diff --git a/sprout/complex/operators.hpp b/sprout/complex/operators.hpp index c909ff04..5dc3c99f 100644 --- a/sprout/complex/operators.hpp +++ b/sprout/complex/operators.hpp @@ -8,8 +8,8 @@ #ifndef SPROUT_COMPLEX_OPERATORS_HPP #define SPROUT_COMPLEX_OPERATORS_HPP -#include -#include +#include +#include #include #include diff --git a/sprout/functional/ref.hpp b/sprout/functional/ref.hpp index 72d4ae4f..0d39d429 100644 --- a/sprout/functional/ref.hpp +++ b/sprout/functional/ref.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -235,20 +236,17 @@ namespace sprout { // unwrap_reference // template - struct unwrap_reference { - public: - typedef T type; - }; + struct unwrap_reference + : public sprout::identity + {}; template - struct unwrap_reference > { - public: - typedef T type; - }; + struct unwrap_reference > + : public sprout::identity + {}; template - struct unwrap_reference > { - public: - typedef T type; - }; + struct unwrap_reference > + : public sprout::identity + {}; template struct unwrap_reference : public sprout::unwrap_reference @@ -266,20 +264,17 @@ namespace sprout { // strip_reference // template - struct strip_reference { - public: - typedef T type; - }; + struct strip_reference + : public sprout::identity + {}; template - struct strip_reference > { - public: - typedef T& type; - }; + struct strip_reference > + : public sprout::identity + {}; template - struct strip_reference > { - public: - typedef T& type; - }; + struct strip_reference > + : public sprout::identity + {}; template struct strip_reference : public sprout::strip_reference diff --git a/sprout/logic/tribool/io.hpp b/sprout/logic/tribool/io.hpp index c7d7cf9b..d14fa5c5 100644 --- a/sprout/logic/tribool/io.hpp +++ b/sprout/logic/tribool/io.hpp @@ -10,8 +10,8 @@ #include #include -#include -#include +#include +#include #include #include #include diff --git a/sprout/memory.hpp b/sprout/memory.hpp index 0cfa73e5..06d309f6 100644 --- a/sprout/memory.hpp +++ b/sprout/memory.hpp @@ -11,5 +11,8 @@ #include #include #include +#include +#include +#include #endif // #ifndef SPROUT_MEMORY_HPP diff --git a/sprout/memory/exempt_ptr.hpp b/sprout/memory/exempt_ptr.hpp index a0e472a4..b587f01e 100644 --- a/sprout/memory/exempt_ptr.hpp +++ b/sprout/memory/exempt_ptr.hpp @@ -12,9 +12,14 @@ #include #include #include +#include #include #include #include +#include +#include +#include +#include namespace sprout { // @@ -100,10 +105,7 @@ namespace sprout { SPROUT_EXPLICIT_CONVERSION SPROUT_CONSTEXPR operator bool() const SPROUT_NOEXCEPT { return get(); } - SPROUT_CONSTEXPR operator pointer() SPROUT_NOEXCEPT { - return get(); - } - SPROUT_CONSTEXPR operator const_pointer() const SPROUT_NOEXCEPT { + SPROUT_EXPLICIT_CONVERSION SPROUT_CONSTEXPR operator pointer() const SPROUT_NOEXCEPT { return get(); } SPROUT_CXX14_CONSTEXPR pointer @@ -186,25 +188,27 @@ namespace sprout { operator!=(sprout::exempt_ptr const& x, sprout::exempt_ptr const& y) SPROUT_NOEXCEPT { return !(x == y); } + template inline SPROUT_CONSTEXPR bool - operator==(sprout::exempt_ptr const& x, std::nullptr_t y) SPROUT_NOEXCEPT { - return x.get() == y; + operator==(sprout::exempt_ptr const& x, std::nullptr_t) SPROUT_NOEXCEPT { + return !x; } template inline SPROUT_CONSTEXPR bool - operator!=(sprout::exempt_ptr const& x, std::nullptr_t y) SPROUT_NOEXCEPT { - return !(x == y); + operator!=(sprout::exempt_ptr const& x, std::nullptr_t) SPROUT_NOEXCEPT { + return static_cast(x); + } + + template + inline SPROUT_CONSTEXPR bool + operator==(std::nullptr_t, sprout::exempt_ptr const& y) SPROUT_NOEXCEPT { + return !y; } template inline SPROUT_CONSTEXPR bool - operator==(std::nullptr_t x, sprout::exempt_ptr const& y) SPROUT_NOEXCEPT { - return x == y.get(); - } - template - inline SPROUT_CONSTEXPR bool - operator!=(std::nullptr_t x, sprout::exempt_ptr const& y) SPROUT_NOEXCEPT { - return !(x == y); + operator!=(std::nullptr_t, sprout::exempt_ptr const& y) SPROUT_NOEXCEPT { + return static_cast(y); } // // operator< @@ -215,7 +219,8 @@ namespace sprout { template inline SPROUT_CONSTEXPR bool operator<(sprout::exempt_ptr const& x, sprout::exempt_ptr const& y) { - return x.get() < y.get(); + typedef typename sprout::common_decay::type type; + return sprout::less()(x.get(), y.get()); } template inline SPROUT_CONSTEXPR bool @@ -232,6 +237,48 @@ namespace sprout { operator>=(sprout::exempt_ptr const& x, sprout::exempt_ptr const& y) { return !(x < y); } + + template + inline SPROUT_CONSTEXPR bool + operator<(sprout::exempt_ptr const& x, std::nullptr_t y) { + return sprout::less()(x.get(), y); + } + template + inline SPROUT_CONSTEXPR bool + operator>(sprout::exempt_ptr const& x, std::nullptr_t y) { + return y < x; + } + template + inline SPROUT_CONSTEXPR bool + operator<=(sprout::exempt_ptr const& x, std::nullptr_t y) { + return !(y < x); + } + template + inline SPROUT_CONSTEXPR bool + operator>=(sprout::exempt_ptr const& x, std::nullptr_t y) { + return !(x < y); + } + + template + inline SPROUT_CONSTEXPR bool + operator<(std::nullptr_t x, sprout::exempt_ptr const& y) { + return sprout::less()(x, y.get()); + } + template + inline SPROUT_CONSTEXPR bool + operator>(std::nullptr_t x, sprout::exempt_ptr const& y) { + return y < x; + } + template + inline SPROUT_CONSTEXPR bool + operator<=(std::nullptr_t x, sprout::exempt_ptr const& y) { + return !(y < x); + } + template + inline SPROUT_CONSTEXPR bool + operator>=(std::nullptr_t x, sprout::exempt_ptr const& y) { + return !(x < y); + } // // operator+ // operator- @@ -246,6 +293,14 @@ namespace sprout { operator-(sprout::exempt_ptr const& x, sprout::exempt_ptr const& y) { return x.get() - y.get(); } + // + // operator<< + // + template + inline SPROUT_CONSTEXPR std::basic_ostream& + operator<<(std::basic_ostream& lhs, sprout::exempt_ptr const& rhs) { + return lhs << rhs.get(); + } } // namespace sprout namespace sprout { @@ -276,4 +331,46 @@ namespace std { #endif } // namespace std +namespace sprout { + // + // static_pointer_cast + // const_pointer_cast + // dynamic_pointer_cast + // reinterpret_pointer_cast + // + template + inline SPROUT_CONSTEXPR sprout::exempt_ptr + static_pointer_cast(sprout::exempt_ptr const& p) { + typedef typename sprout::exempt_ptr::element_type element_type; + return sprout::exempt_ptr(sprout::static_pointer_cast(p.get())); + } + template + inline SPROUT_CONSTEXPR sprout::exempt_ptr + const_pointer_cast(sprout::exempt_ptr const& p) { + typedef typename sprout::exempt_ptr::element_type element_type; + return sprout::exempt_ptr(sprout::const_pointer_cast(p.get())); + } + template + inline SPROUT_CONSTEXPR sprout::exempt_ptr + dynamic_pointer_cast(sprout::exempt_ptr const& p) { + typedef typename sprout::exempt_ptr::element_type element_type; + return sprout::exempt_ptr(sprout::dynamic_pointer_cast(p.get())); + } + template + inline SPROUT_CONSTEXPR sprout::exempt_ptr + reinterpret_pointer_cast(sprout::exempt_ptr const& p) { + typedef typename sprout::exempt_ptr::element_type element_type; + return sprout::exempt_ptr(sprout::reinterpret_pointer_cast(p.get())); + } + + // + // get_pointer + // + template + inline SPROUT_NON_CONSTEXPR T* + get_pointer(sprout::exempt_ptr const& p) SPROUT_NOEXCEPT { + return p.get(); + } +} // namespace sprout + #endif // #ifndef SPROUT_MEMORY_EXEMPT_PTR_HPP diff --git a/sprout/memory/get_pointer.hpp b/sprout/memory/get_pointer.hpp new file mode 100644 index 00000000..e470cd4e --- /dev/null +++ b/sprout/memory/get_pointer.hpp @@ -0,0 +1,46 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_MEMORY_GET_POINTER_HPP +#define SPROUT_MEMORY_GET_POINTER_HPP + +#include +#include + +namespace sprout { + // + // get_pointer + // + template + inline SPROUT_CONSTEXPR T* + get_pointer(T* p) SPROUT_NOEXCEPT { + return p; + } + + template + inline SPROUT_NON_CONSTEXPR T* + get_pointer(std::auto_ptr const& p) SPROUT_NOEXCEPT { + return p.get(); + } + +#if !defined(SPROUT_NO_CXX11_SMART_PTR) + template + inline SPROUT_NON_CONSTEXPR T* + get_pointer(std::unique_ptr const& p) SPROUT_NOEXCEPT { + return p.get(); + } + + template + inline SPROUT_NON_CONSTEXPR T* + get_pointer(std::shared_ptr const& p) SPROUT_NOEXCEPT { + return p.get(); + } +#endif +} // namespace sprout + + +#endif // #ifndef SPROUT_MEMORY_GET_POINTER_HPP diff --git a/sprout/memory/observer_ptr.hpp b/sprout/memory/observer_ptr.hpp new file mode 100644 index 00000000..df65087d --- /dev/null +++ b/sprout/memory/observer_ptr.hpp @@ -0,0 +1,33 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_MEMORY_OBSERVER_PTR_HPP +#define SPROUT_MEMORY_OBSERVER_PTR_HPP + +#include +#include + +namespace sprout { + // + // make_observer + // + template + inline SPROUT_CONSTEXPR sprout::exempt_ptr + make_observer(T* p) SPROUT_NOEXCEPT { + return sprout::exempt_ptr(p); + } + +#if SPROUT_USE_TEMPLATE_ALIASES + // + // observer_ptr + // + template + using observer_ptr = sprout::exempt_ptr; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES +} // namespace sprout + +#endif // #ifndef SPROUT_MEMORY_OBSERVER_PTR_HPP diff --git a/sprout/memory/pointer_cast.hpp b/sprout/memory/pointer_cast.hpp new file mode 100644 index 00000000..3695007a --- /dev/null +++ b/sprout/memory/pointer_cast.hpp @@ -0,0 +1,69 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_MEMORY_POINTER_CAST_HPP +#define SPROUT_MEMORY_POINTER_CAST_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // static_pointer_cast + // const_pointer_cast + // dynamic_pointer_cast + // reinterpret_pointer_cast + // + template + inline SPROUT_CONSTEXPR T* + static_pointer_cast(U* p) { + return static_cast(p); + } + template + inline SPROUT_CONSTEXPR T* + const_pointer_cast(U* p) { + return const_cast(p); + } + template + inline SPROUT_CONSTEXPR T* + dynamic_pointer_cast(U* p) { + return sprout::dyn_cast(p); + } + template + inline SPROUT_CONSTEXPR T* + reinterpret_pointer_cast(U* p) { + return sprout::reinter_cast(p); + } + +#if !defined(SPROUT_NO_CXX11_SMART_PTR) + template + inline SPROUT_NON_CONSTEXPR std::shared_ptr + static_pointer_cast(std::shared_ptr const& p) { + return std::static_pointer_cast(p); + } + template + inline SPROUT_NON_CONSTEXPR std::shared_ptr + const_pointer_cast(std::shared_ptr const& p) { + return std::const_pointer_cast(p); + } + template + inline SPROUT_NON_CONSTEXPR std::shared_ptr + dynamic_pointer_cast(std::shared_ptr const& p) { + return std::dynamic_pointer_cast(p); + } + template + inline SPROUT_NON_CONSTEXPR std::shared_ptr + reinterpret_pointer_cast(std::shared_ptr const& p) { + typedef typename std::shared_ptr::element_type element_type; + return std::shared_ptr(p, reinterpret_cast(p.get())); + } +#endif +} // namespace sprout + +#endif // #ifndef SPROUT_MEMORY_POINTER_CAST_HPP diff --git a/sprout/optional/io.hpp b/sprout/optional/io.hpp index 5323cf22..6ef2c611 100644 --- a/sprout/optional/io.hpp +++ b/sprout/optional/io.hpp @@ -8,8 +8,8 @@ #ifndef SPROUT_OPTIONAL_IO_HPP #define SPROUT_OPTIONAL_IO_HPP -#include -#include +#include +#include #include #include #include diff --git a/sprout/random/additive_combine.hpp b/sprout/random/additive_combine.hpp index f9f87570..8c4af499 100644 --- a/sprout/random/additive_combine.hpp +++ b/sprout/random/additive_combine.hpp @@ -9,8 +9,8 @@ #define SPROUT_RANDOM_ADDITIVE_COMBINE_HPP #include -#include #include +#include #include #include #include diff --git a/sprout/random/geometric_distribution.hpp b/sprout/random/geometric_distribution.hpp index e6597c20..cce2d385 100644 --- a/sprout/random/geometric_distribution.hpp +++ b/sprout/random/geometric_distribution.hpp @@ -8,7 +8,8 @@ #ifndef SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP #define SPROUT_RANDOM_GEOMETRIC_DISTRIBUTION_HPP -#include +#include +#include #include #include #include diff --git a/sprout/random/inversive_congruential.hpp b/sprout/random/inversive_congruential.hpp index a56621a0..255a4379 100644 --- a/sprout/random/inversive_congruential.hpp +++ b/sprout/random/inversive_congruential.hpp @@ -9,7 +9,8 @@ #define SPROUT_RANDOM_INVERSIVE_CONGRUENTIAL_HPP #include -#include +#include +#include #include #include #include diff --git a/sprout/random/linear_congruential.hpp b/sprout/random/linear_congruential.hpp index 2e0ff8a1..cd805a41 100644 --- a/sprout/random/linear_congruential.hpp +++ b/sprout/random/linear_congruential.hpp @@ -9,7 +9,8 @@ #define SPROUT_RANDOM_LINEAR_CONGRUENTIAL_HPP #include -#include +#include +#include #include #include #include diff --git a/sprout/random/linear_feedback_shift.hpp b/sprout/random/linear_feedback_shift.hpp index 02e48498..12a6b680 100644 --- a/sprout/random/linear_feedback_shift.hpp +++ b/sprout/random/linear_feedback_shift.hpp @@ -8,7 +8,8 @@ #ifndef SPROUT_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP #define SPROUT_RANDOM_LINEAR_FEEDBACK_SHIFT_HPP -#include +#include +#include #include #include #include diff --git a/sprout/random/mersenne_twister.hpp b/sprout/random/mersenne_twister.hpp index cfc3b621..5d631f12 100644 --- a/sprout/random/mersenne_twister.hpp +++ b/sprout/random/mersenne_twister.hpp @@ -8,7 +8,8 @@ #ifndef SPROUT_RANDOM_MERSENNE_TWISTER_HPP #define SPROUT_RANDOM_MERSENNE_TWISTER_HPP -#include +#include +#include #include #include #include diff --git a/sprout/random/normal_distribution.hpp b/sprout/random/normal_distribution.hpp index 59d6c575..42d8e949 100644 --- a/sprout/random/normal_distribution.hpp +++ b/sprout/random/normal_distribution.hpp @@ -8,8 +8,8 @@ #ifndef SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP #define SPROUT_RANDOM_NORMAL_DISTRIBUTION_HPP -#include #include +#include #include #include #include diff --git a/sprout/random/shuffle_order.hpp b/sprout/random/shuffle_order.hpp index b006d2bf..0fae1c76 100644 --- a/sprout/random/shuffle_order.hpp +++ b/sprout/random/shuffle_order.hpp @@ -9,8 +9,8 @@ #define SPROUT_RANDOM_SHUFFLE_ORDER_HPP #include -#include #include +#include #include #include #include diff --git a/sprout/random/uniform_int_distribution.hpp b/sprout/random/uniform_int_distribution.hpp index 4234fe23..a97a7742 100644 --- a/sprout/random/uniform_int_distribution.hpp +++ b/sprout/random/uniform_int_distribution.hpp @@ -8,8 +8,8 @@ #ifndef SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP #define SPROUT_RANDOM_UNIFORM_INT_DISTRIBUTION_HPP -#include #include +#include #include #include #include diff --git a/sprout/random/uniform_real_distribution.hpp b/sprout/random/uniform_real_distribution.hpp index 43867955..55a81a9a 100644 --- a/sprout/random/uniform_real_distribution.hpp +++ b/sprout/random/uniform_real_distribution.hpp @@ -8,8 +8,8 @@ #ifndef SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP #define SPROUT_RANDOM_UNIFORM_REAL_DISTRIBUTION_HPP -#include #include +#include #include #include #include diff --git a/sprout/random/xor_combine.hpp b/sprout/random/xor_combine.hpp index 0f2a9467..c8e34c47 100644 --- a/sprout/random/xor_combine.hpp +++ b/sprout/random/xor_combine.hpp @@ -8,8 +8,8 @@ #ifndef SPROUT_RANDOM_XOR_COMBINE_HPP #define SPROUT_RANDOM_XOR_COMBINE_HPP -#include #include +#include #include #include #include diff --git a/sprout/rational/io.hpp b/sprout/rational/io.hpp index 9bb79080..015c6c81 100644 --- a/sprout/rational/io.hpp +++ b/sprout/rational/io.hpp @@ -8,8 +8,8 @@ #ifndef SPROUT_RATIONAL_IO_HPP #define SPROUT_RATIONAL_IO_HPP -#include -#include +#include +#include #include #include #include diff --git a/sprout/string/io.hpp b/sprout/string/io.hpp index dbc240f8..f142ba92 100644 --- a/sprout/string/io.hpp +++ b/sprout/string/io.hpp @@ -8,7 +8,8 @@ #ifndef SPROUT_STRING_IO_HPP #define SPROUT_STRING_IO_HPP -#include +#include +#include #include #include #include diff --git a/sprout/type_traits.hpp b/sprout/type_traits.hpp index a7baf937..df443003 100644 --- a/sprout/type_traits.hpp +++ b/sprout/type_traits.hpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/sprout/type_traits/is_nullptr_cast.hpp b/sprout/type_traits/is_nullptr_cast.hpp new file mode 100644 index 00000000..fcc4d383 --- /dev/null +++ b/sprout/type_traits/is_nullptr_cast.hpp @@ -0,0 +1,29 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_TRAITS_IS_NULLPTR_CAST_HPP +#define SPROUT_TYPE_TRAITS_IS_NULLPTR_CAST_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // is_nullptr_cast + // + template + struct is_nullptr_cast + : public sprout::integral_constant< + bool, + sprout::is_pointer::value && sprout::is_same::type, std::nullptr_t>::value + > + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_IS_NULLPTR_CAST_HPP diff --git a/sprout/type_traits/is_upcast.hpp b/sprout/type_traits/is_upcast.hpp new file mode 100644 index 00000000..5ad82663 --- /dev/null +++ b/sprout/type_traits/is_upcast.hpp @@ -0,0 +1,35 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_TRAITS_IS_UPCAST_HPP +#define SPROUT_TYPE_TRAITS_IS_UPCAST_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // is_upcast + // + template + struct is_upcast + : public sprout::integral_constant< + bool, + sprout::is_nullptr_cast::value + || (sprout::is_pointer::value + && sprout::is_base_of::type, typename sprout::remove_pointer::type>::type>::value + ) + || (sprout::is_reference::value + && sprout::is_base_of::type, typename sprout::remove_reference::type>::value + ) + > + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_IS_UPCAST_HPP diff --git a/sprout/utility.hpp b/sprout/utility.hpp index 9df4dfd1..5231ad20 100644 --- a/sprout/utility.hpp +++ b/sprout/utility.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/sprout/utility/cast.hpp b/sprout/utility/cast.hpp new file mode 100644 index 00000000..4ce2e9c0 --- /dev/null +++ b/sprout/utility/cast.hpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_CAST_HPP +#define SPROUT_UTILITY_CAST_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // #ifndef SPROUT_UTILITY_CAST_HPP diff --git a/sprout/utility/dyn_cast.hpp b/sprout/utility/dyn_cast.hpp new file mode 100644 index 00000000..b024b9d2 --- /dev/null +++ b/sprout/utility/dyn_cast.hpp @@ -0,0 +1,38 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_DYN_CAST_HPP +#define SPROUT_UTILITY_DYN_CAST_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // dyn_cast + // + template< + typename T, typename U, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR T + dyn_cast(U&& x) { + return static_cast(SPROUT_FORWARD(U, x)); + } + template< + typename T, typename U, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_NON_CONSTEXPR T + dyn_cast(U&& x) { + return dynamic_cast(SPROUT_FORWARD(U, x)); + } +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_DYN_CAST_HPP diff --git a/sprout/utility/implicit_cast.hpp b/sprout/utility/implicit_cast.hpp new file mode 100644 index 00000000..dfccb0b1 --- /dev/null +++ b/sprout/utility/implicit_cast.hpp @@ -0,0 +1,25 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_IMPLICIT_CAST_HPP +#define SPROUT_UTILITY_IMPLICIT_CAST_HPP + +#include +#include + +namespace sprout { + // + // implicit_cast + // + template + inline SPROUT_CONSTEXPR T + implicit_cast (typename sprout::identity::type t) { + return t; + } +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_IMPLICIT_CAST_HPP diff --git a/sprout/utility/noncopyable.hpp b/sprout/utility/noncopyable.hpp index 6c404ad1..8772313b 100644 --- a/sprout/utility/noncopyable.hpp +++ b/sprout/utility/noncopyable.hpp @@ -11,7 +11,7 @@ #include namespace sprout { - namespace noncopyable_ { + namespace noncopyable_detail { class noncopyable { protected: SPROUT_CONSTEXPR noncopyable() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL @@ -20,11 +20,11 @@ namespace sprout { noncopyable(noncopyable const&) SPROUT_DELETED_FUNCTION_DECL noncopyable& operator=(noncopyable const&) SPROUT_DELETED_FUNCTION_DECL }; - } // namespace noncopyable_ + } // namespace noncopyable_detail // // noncopyable // - typedef sprout::noncopyable_::noncopyable noncopyable; + typedef sprout::noncopyable_detail::noncopyable noncopyable; } // namespace sprout #endif // #ifndef SPROUT_UTILITY_NONCOPYABLE_HPP diff --git a/sprout/utility/operation.hpp b/sprout/utility/operation.hpp index 950537ba..e8bb7190 100644 --- a/sprout/utility/operation.hpp +++ b/sprout/utility/operation.hpp @@ -14,7 +14,5 @@ #include #include #include -#include -#include #endif // #ifndef SPROUT_UTILITY_OPERATION_HPP diff --git a/sprout/utility/operation_ext.hpp b/sprout/utility/operation_ext.hpp index 4e1cd07d..4f917475 100644 --- a/sprout/utility/operation_ext.hpp +++ b/sprout/utility/operation_ext.hpp @@ -10,10 +10,7 @@ #include #include -#include -#include -#include -#include +#include #include #endif // #ifndef SPROUT_UTILITY_OPERATION_EXT_HPP diff --git a/sprout/utility/reinter_cast.hpp b/sprout/utility/reinter_cast.hpp new file mode 100644 index 00000000..9da6c677 --- /dev/null +++ b/sprout/utility/reinter_cast.hpp @@ -0,0 +1,55 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_REINTER_CAST_HPP +#define SPROUT_UTILITY_REINTER_CAST_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace detail { + template + struct is_same_reinterpret_cast + : public sprout::integral_constant< + bool, + (sprout::is_reference::value + && sprout::is_same::type, typename sprout::decay::type>::value + && sprout::is_convertible::value + ) + || ((sprout::is_integral::type || sprout::is_enum::type || sprout::is_pointer::type) + && sprout::is_same::type, To>::value + ) + + > + {}; + } // namespace detail + // + // reinter_cast + // + template< + typename T, typename U, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR T + reinter_cast(U&& x) { + return SPROUT_FORWARD(U, x); + } + template< + typename T, typename U, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_NON_CONSTEXPR T + reinter_cast(U&& x) { + return reinterpret_cast(SPROUT_FORWARD(U, x)); + } +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_REINTER_CAST_HPP diff --git a/sprout/utility/string_ref/io.hpp b/sprout/utility/string_ref/io.hpp index bedb34cb..b4b8cffb 100644 --- a/sprout/utility/string_ref/io.hpp +++ b/sprout/utility/string_ref/io.hpp @@ -9,7 +9,8 @@ #define SPROUT_UTILITY_STRING_IO_HPP #include -#include +#include +#include #include #include #include diff --git a/sprout/utility/upcast.hpp b/sprout/utility/upcast.hpp new file mode 100644 index 00000000..a007f056 --- /dev/null +++ b/sprout/utility/upcast.hpp @@ -0,0 +1,30 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_UTILITY_UPCAST_HPP +#define SPROUT_UTILITY_UPCAST_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // upcast + // + template< + typename T, typename U, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR T + upcast(U&& x) { + return static_cast(SPROUT_FORWARD(U, x)); + } +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_UPCAST_HPP diff --git a/sprout/uuid/io.hpp b/sprout/uuid/io.hpp index d9aa385e..02b5cc7e 100644 --- a/sprout/uuid/io.hpp +++ b/sprout/uuid/io.hpp @@ -9,9 +9,8 @@ #define SPROUT_UUID_IO_HPP #include -#include -#include #include +#include #include #include #include