diff --git a/sprout/adapt/std/utility.hpp b/sprout/adapt/std/utility.hpp index 4a549775..c8fdaf74 100644 --- a/sprout/adapt/std/utility.hpp +++ b/sprout/adapt/std/utility.hpp @@ -1,9 +1,9 @@ -#ifndef SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP -#define SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP +#ifndef SPROUT_ADAPT_STD_UTILITY_HPP +#define SPROUT_ADAPT_STD_UTILITY_HPP #include #include #include #include -#endif // #ifndef SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP +#endif // #ifndef SPROUT_ADAPT_STD_UTILITY_HPP diff --git a/sprout/container/begin.hpp b/sprout/container/begin.hpp index ded390bc..2aa919ec 100644 --- a/sprout/container/begin.hpp +++ b/sprout/container/begin.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace sprout_adl { @@ -13,56 +14,41 @@ namespace sprout_adl { namespace sprout { namespace container_detail { template - inline typename sprout::container_traits::iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_begin(Container& cont) { - return cont.begin(); + return sprout::container_range_traits::range_begin(cont); } template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_begin(Container const& cont) { - return cont.begin(); - } - - template - inline typename sprout::container_traits::iterator - range_begin(T (& arr)[N]) { - typedef typename sprout::container_traits::iterator iterator; - return iterator(arr); - } - template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator - range_begin(T const (& arr)[N]) { - typedef typename sprout::container_traits::const_iterator iterator; - return iterator(arr); + return sprout::container_range_traits::range_begin(cont); } } // namespace container_detail -} // namespace sprout -namespace sprout { // // begin // template - inline typename sprout::container_traits::iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator begin(Container& cont) { using sprout::container_detail::range_begin; using sprout_adl::range_begin; return range_begin(cont); } template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator begin(Container const& cont) { using sprout::container_detail::range_begin; using sprout_adl::range_begin; return range_begin(cont); } template - inline typename sprout::container_traits::iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator begin(T (& arr)[N]) { return sprout::container_detail::range_begin(arr); } template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator begin(T const (& arr)[N]) { return sprout::container_detail::range_begin(arr); } @@ -71,14 +57,14 @@ namespace sprout { // cbegin // template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator cbegin(Container const& cont) { using sprout::container_detail::range_begin; using sprout_adl::range_begin; return range_begin(cont); } template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator cbegin(T const (& arr)[N]) { return sprout::container_detail::range_begin(arr); } diff --git a/sprout/container/container_range_traits.hpp b/sprout/container/container_range_traits.hpp new file mode 100644 index 00000000..558388a6 --- /dev/null +++ b/sprout/container/container_range_traits.hpp @@ -0,0 +1,87 @@ +#ifndef SPROUT_CONTAINER_CONTAINER_RANGE_TRAITS_HPP +#define SPROUT_CONTAINER_CONTAINER_RANGE_TRAITS_HPP + +#include +#include +#include + +namespace sprout { + // + // container_range_traits + // + template + struct container_range_traits { + public: + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_begin(Container& cont) { + return cont.begin(); + } + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_begin(Container const& cont) { + return cont.begin(); + } + + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_end(Container& cont) { + return cont.end(); + } + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_end(Container const& cont) { + return cont.end(); + } + }; + template + struct container_range_traits { + public: + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_begin(Container const& cont) { + return sprout::container_range_traits::range_begin(cont); + } + + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_end(Container const& cont) { + return sprout::container_range_traits::range_end(cont); + } + }; + + template + struct container_range_traits { + public: + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_begin(T (& arr)[N]) { + typedef typename sprout::container_traits::iterator type; + return type(arr); + } + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_begin(T const (& arr)[N]) { + typedef typename sprout::container_traits::iterator type; + return type(arr); + } + + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_end(T (& arr)[N]) { + typedef typename sprout::container_traits::iterator type; + return type(arr) + N; + } + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_end(T const (& arr)[N]) { + typedef typename sprout::container_traits::iterator type; + return type(arr) + N; + } + }; + template + struct container_range_traits { + public: + static SPROUT_CONSTEXPR typename sprout::container_traits::iterator + range_begin(T const (& arr)[N]) { + return sprout::container_range_traits::range_begin(arr); + } + + static SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + range_end(T const (& arr)[N]) { + return sprout::container_range_traits::range_end(arr); + } + }; +} // namespace sprout + +#endif // #ifndef SPROUT_CONTAINER_CONTAINER_RANGE_TRAITS_HPP diff --git a/sprout/container/end.hpp b/sprout/container/end.hpp index 4ab01e4e..b87fe422 100644 --- a/sprout/container/end.hpp +++ b/sprout/container/end.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace sprout_adl { @@ -13,56 +14,41 @@ namespace sprout_adl { namespace sprout { namespace container_detail { template - inline typename sprout::container_traits::iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_end(Container& cont) { - return cont.end(); + return sprout::container_range_traits::range_end(cont); } template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_end(Container const& cont) { - return cont.end(); - } - - template - inline typename sprout::container_traits::iterator - range_end(T (& arr)[N]) { - typedef typename sprout::container_traits::iterator iterator; - return iterator(arr) + N; - } - template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator - range_end(T const (& arr)[N]) { - typedef typename sprout::container_traits::const_iterator iterator; - return iterator(arr) + N; + return sprout::container_range_traits::range_end(cont); } } // namespace container_detail -} // namespace sprout -namespace sprout { // // end // template - inline typename sprout::container_traits::iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator end(Container& cont) { using sprout::container_detail::range_end; using sprout_adl::range_end; return range_end(cont); } template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator end(Container const& cont) { using sprout::container_detail::range_end; using sprout_adl::range_end; return range_end(cont); } template - inline typename sprout::container_traits::iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator end(T (& arr)[N]) { return sprout::container_detail::range_end(arr); } template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator end(T const (& arr)[N]) { return sprout::container_detail::range_end(arr); } @@ -71,14 +57,14 @@ namespace sprout { // cend // template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator cend(Container const& cont) { using sprout::container_detail::range_end; using sprout_adl::range_end; return range_end(cont); } template - inline SPROUT_CONSTEXPR typename sprout::container_traits::const_iterator + inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator cend(T const (& arr)[N]) { return sprout::container_detail::range_end(arr); } diff --git a/sprout/container/sscrisk/cel/array.hpp b/sprout/container/sscrisk/cel/array.hpp index d5471b15..9c6e8106 100644 --- a/sprout/container/sscrisk/cel/array.hpp +++ b/sprout/container/sscrisk/cel/array.hpp @@ -23,36 +23,31 @@ namespace sprout { typedef sprout::index_iterator&, true> iterator; typedef sprout::index_iterator const&, true> const_iterator; }; -} // namespace sprout -namespace sprout { // - // range_begin + // container_range_traits // template - inline typename sprout::container_traits >::iterator - range_begin(sscrisk::cel::array& cont) { - return typename sprout::container_traits >::iterator(cont, 0); - } - template - inline SPROUT_CONSTEXPR typename sprout::container_traits >::const_iterator - range_begin(sscrisk::cel::array const& cont) { - return typename sprout::container_traits >::const_iterator(cont, 0); - } + struct container_range_traits > { + public: + static SPROUT_CONSTEXPR typename sprout::container_traits >::iterator + range_begin(sscrisk::cel::array& cont) { + return typename sprout::container_traits >::iterator(cont, 0); + } + static SPROUT_CONSTEXPR typename sprout::container_traits const>::iterator + range_begin(sscrisk::cel::array const& cont) { + return typename sprout::container_traits const>::iterator(cont, 0); + } - // - // range_end - // - template - inline typename sprout::container_traits >::iterator - range_end(sscrisk::cel::array& cont) { - return typename sprout::container_traits >::iterator(cont, cont.size()); - } - template - inline SPROUT_CONSTEXPR typename sprout::container_traits >::const_iterator - range_end(sscrisk::cel::array const& cont) { - return typename sprout::container_traits >::const_iterator(cont, cont.size()); - } + static SPROUT_CONSTEXPR typename sprout::container_traits >::iterator + range_end(sscrisk::cel::array& cont) { + return typename sprout::container_traits >::iterator(cont, cont.size()); + } + static SPROUT_CONSTEXPR typename sprout::container_traits const>::iterator + range_end(sscrisk::cel::array const& cont) { + return typename sprout::container_traits const>::iterator(cont, cont.size()); + } + }; } // namespace sprout #endif diff --git a/sprout/container/std/array.hpp b/sprout/container/std/array.hpp index 53535866..1e4f96d2 100644 --- a/sprout/container/std/array.hpp +++ b/sprout/container/std/array.hpp @@ -23,36 +23,31 @@ namespace sprout { typedef sprout::index_iterator&, true> iterator; typedef sprout::index_iterator const&, true> const_iterator; }; -} // namespace sprout -namespace sprout { // - // range_begin + // container_range_traits // template - inline typename sprout::container_traits >::iterator - range_begin(std::array& cont) { - return typename sprout::container_traits >::iterator(cont, 0); - } - template - inline SPROUT_CONSTEXPR typename sprout::container_traits >::const_iterator - range_begin(std::array const& cont) { - return typename sprout::container_traits >::const_iterator(cont, 0); - } + struct container_range_traits > { + public: + static SPROUT_CONSTEXPR typename sprout::container_traits >::iterator + range_begin(std::array& cont) { + return typename sprout::container_traits >::iterator(cont, 0); + } + static SPROUT_CONSTEXPR typename sprout::container_traits const>::iterator + range_begin(std::array const& cont) { + return typename sprout::container_traits const>::iterator(cont, 0); + } - // - // range_end - // - template - inline typename sprout::container_traits >::iterator - range_end(std::array& cont) { - return typename sprout::container_traits >::iterator(cont, cont.size()); - } - template - inline SPROUT_CONSTEXPR typename sprout::container_traits >::const_iterator - range_end(std::array const& cont) { - return typename sprout::container_traits >::const_iterator(cont, cont.size()); - } + static SPROUT_CONSTEXPR typename sprout::container_traits >::iterator + range_end(std::array& cont) { + return typename sprout::container_traits >::iterator(cont, cont.size()); + } + static SPROUT_CONSTEXPR typename sprout::container_traits const>::iterator + range_end(std::array const& cont) { + return typename sprout::container_traits const>::iterator(cont, cont.size()); + } + }; } // namespace sprout #endif diff --git a/sprout/container/traits.hpp b/sprout/container/traits.hpp index 6591c361..0676e30a 100644 --- a/sprout/container/traits.hpp +++ b/sprout/container/traits.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/sprout/darkroom/materials/texture_map.hpp b/sprout/darkroom/materials/texture_map.hpp index 036aaa76..aa7059c1 100644 --- a/sprout/darkroom/materials/texture_map.hpp +++ b/sprout/darkroom/materials/texture_map.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace sprout { diff --git a/sprout/darkroom/objects/polygon/triangle.hpp b/sprout/darkroom/objects/polygon/triangle.hpp index 20ba296b..66971fab 100644 --- a/sprout/darkroom/objects/polygon/triangle.hpp +++ b/sprout/darkroom/objects/polygon/triangle.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include #include diff --git a/sprout/darkroom/objects/sphere.hpp b/sprout/darkroom/objects/sphere.hpp index 049702f2..867b997b 100644 --- a/sprout/darkroom/objects/sphere.hpp +++ b/sprout/darkroom/objects/sphere.hpp @@ -172,7 +172,7 @@ namespace sprout { ray, det_sq > 0, b, - sprout::sqrt(det_sq) + det_sq > 0 ? sprout::sqrt(det_sq) : unit_type(0) ) ); } diff --git a/sprout/darkroom/pixels/generate.hpp b/sprout/darkroom/pixels/generate.hpp index 41cf6dd0..d94e29ae 100644 --- a/sprout/darkroom/pixels/generate.hpp +++ b/sprout/darkroom/pixels/generate.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/sprout/darkroom/textures/texture.hpp b/sprout/darkroom/textures/texture.hpp index 390c8539..df66f662 100644 --- a/sprout/darkroom/textures/texture.hpp +++ b/sprout/darkroom/textures/texture.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include diff --git a/sprout/functional/bind/bind.hpp b/sprout/functional/bind/bind.hpp index 038c1f4f..f42fba66 100644 --- a/sprout/functional/bind/bind.hpp +++ b/sprout/functional/bind/bind.hpp @@ -415,7 +415,7 @@ namespace sprout { typename enable_if_void::type = 0 ) { - f_(sprout::detail::mu()(get(bound_args_), args)...); + f_(sprout::detail::mu()(sprout::tuples::get(bound_args_), args)...); } template SPROUT_CONSTEXPR Result call( diff --git a/sprout/functional/hash.hpp b/sprout/functional/hash.hpp index d98932d7..3b3870fe 100644 --- a/sprout/functional/hash.hpp +++ b/sprout/functional/hash.hpp @@ -9,5 +9,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_FUNCTIONAL_HASH_HPP diff --git a/sprout/functional/hash/hash_fwd.hpp b/sprout/functional/hash/hash_fwd.hpp index 05dd4f13..7c86f62e 100644 --- a/sprout/functional/hash/hash_fwd.hpp +++ b/sprout/functional/hash/hash_fwd.hpp @@ -15,7 +15,14 @@ namespace sprout { // to_hash // template - SPROUT_CONSTEXPR std::size_t to_hash(T const& v); + SPROUT_CONSTEXPR std::size_t to_hash(T&& v); + + // + // hash_value + // + template + inline SPROUT_CONSTEXPR std::size_t + hash_value(T const& v); // // hash_combine @@ -42,6 +49,12 @@ namespace sprout { SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, InputRange const& rng); template SPROUT_CONSTEXPR std::size_t hash_range(InputRange const& rng); + + // + // hash_value_traits + // + template + struct hash_value_traits; } // namespace sprout #endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_FWD_HPP diff --git a/sprout/functional/hash/hash_value.hpp b/sprout/functional/hash/hash_value.hpp index dbd0bb3a..1677a8da 100644 --- a/sprout/functional/hash/hash_value.hpp +++ b/sprout/functional/hash/hash_value.hpp @@ -2,150 +2,20 @@ #define SPROUT_FUNCTIONAL_HASH_HASH_VALUE_HPP #include -#include -#include #include #include -#include namespace sprout { - namespace hash_detail { - template - struct is_basic_number - : public std::integral_constant< - bool, - std::is_integral::value - && (sizeof(T) <= sizeof(std::size_t)) - > - {}; - template - struct is_long_number - : public std::integral_constant< - bool, - std::is_integral::value - && (sizeof(T) > sizeof(std::size_t)) - && std::is_signed::value - > - {}; - template - struct is_ulong_number - : public std::integral_constant< - bool, - std::is_integral::value - && (sizeof(T) > sizeof(std::size_t)) - && std::is_unsigned::value - > - {}; - - template - inline SPROUT_CONSTEXPR std::size_t - hash_value_signed_2(T val, int length, std::size_t seed, T positive, std::size_t i) { - return i > 0 - ? hash_value_signed_2( - val, - length, - seed ^ static_cast((positive >> i) + (seed << 6) + (seed >> 2)), - positive, - i - std::numeric_limits::digits - ) - : seed ^ static_cast(val + (seed << 6) + (seed >> 2)) - ; - } - template - inline SPROUT_CONSTEXPR std::size_t - hash_value_signed_1(T val, int length, std::size_t seed, T positive) { - return hash_value_signed_2(val, length, seed, positive, length * std::numeric_limits::digits); - } - template - inline SPROUT_CONSTEXPR std::size_t - hash_value_signed(T val) { - return sprout::hash_detail::hash_value_signed_1( - val, - (std::numeric_limits::digits - 1) / std::numeric_limits::digits, - 0, - val < 0 ? -1 - val : val - ); - } - - template - inline SPROUT_CONSTEXPR std::size_t - hash_value_unsigned_2(T val, int length, std::size_t seed, std::size_t i) { - return i > 0 - ? hash_value_unsigned_2( - val, - length, - seed ^ static_cast((val >> i) + (seed << 6) + (seed >> 2)), - i - std::numeric_limits::digits - ) - : seed ^ static_cast(val + (seed << 6) + (seed >> 2)) - ; - } - template - inline SPROUT_CONSTEXPR std::size_t - hash_value_unsigned_1(T val, int length, std::size_t seed) { - return hash_value_unsigned_2(val, length, seed, length * std::numeric_limits::digits); - } - template - inline SPROUT_CONSTEXPR std::size_t - hash_value_unsigned(T val) { - return sprout::hash_detail::hash_value_unsigned_1( - val, - (std::numeric_limits::digits - 1) / std::numeric_limits::digits, - 0 - ); - } - - inline std::size_t - hash_value_pointer_1(std::size_t x) { - return x + (x >> 3); - } - template - std::size_t - hash_value_pointer(T const* v) { - return sprout::hash_detail::hash_value_pointer_1(static_cast(reinterpret_cast(v))); - } - } // namespace hash_detail - // // hash_value // template - inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type - hash_value(T v) { - return static_cast(v); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type - hash_value(T v) { - return sprout::hash_detail::hash_value_signed(v); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type - hash_value(T v) { - return sprout::hash_detail::hash_value_unsigned(v); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type - hash_value(T v) { - return sprout::hash_value(static_cast::type>(v)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type - hash_value(T v) { - return sprout::detail::float_hash_value(v); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::type>::value, std::size_t>::type - hash_value(T&& v) { - return sprout::hash_detail::hash_value_pointer(v); - } - template inline SPROUT_CONSTEXPR std::size_t - hash_value(T const (&v)[N]) { - return sprout::hash_range(v); + hash_value(T const& v) { + return sprout::hash_value_traits::hash_value(v); } } // namespace sprout -#include +#include #endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUE_HPP diff --git a/sprout/functional/hash/hash_value_traits.hpp b/sprout/functional/hash/hash_value_traits.hpp new file mode 100644 index 00000000..30dfa9dd --- /dev/null +++ b/sprout/functional/hash/hash_value_traits.hpp @@ -0,0 +1,181 @@ +#ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUE_TRAITS_HPP +#define SPROUT_FUNCTIONAL_HASH_HASH_VALUE_TRAITS_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace hash_detail { + template + struct is_basic_number + : public std::integral_constant< + bool, + std::is_integral::value + && (sizeof(T) <= sizeof(std::size_t)) + > + {}; + template + struct is_long_number + : public std::integral_constant< + bool, + std::is_integral::value + && (sizeof(T) > sizeof(std::size_t)) + && std::is_signed::value + > + {}; + template + struct is_ulong_number + : public std::integral_constant< + bool, + std::is_integral::value + && (sizeof(T) > sizeof(std::size_t)) + && std::is_unsigned::value + > + {}; + + template + inline SPROUT_CONSTEXPR std::size_t + hash_value_signed_2(T val, int length, std::size_t seed, T positive, std::size_t i) { + return i > 0 + ? hash_value_signed_2( + val, + length, + seed ^ static_cast((positive >> i) + (seed << 6) + (seed >> 2)), + positive, + i - std::numeric_limits::digits + ) + : seed ^ static_cast(val + (seed << 6) + (seed >> 2)) + ; + } + template + inline SPROUT_CONSTEXPR std::size_t + hash_value_signed_1(T val, int length, std::size_t seed, T positive) { + return hash_value_signed_2(val, length, seed, positive, length * std::numeric_limits::digits); + } + template + inline SPROUT_CONSTEXPR std::size_t + hash_value_signed(T val) { + return sprout::hash_detail::hash_value_signed_1( + val, + (std::numeric_limits::digits - 1) / std::numeric_limits::digits, + 0, + val < 0 ? -1 - val : val + ); + } + + template + inline SPROUT_CONSTEXPR std::size_t + hash_value_unsigned_2(T val, int length, std::size_t seed, std::size_t i) { + return i > 0 + ? hash_value_unsigned_2( + val, + length, + seed ^ static_cast((val >> i) + (seed << 6) + (seed >> 2)), + i - std::numeric_limits::digits + ) + : seed ^ static_cast(val + (seed << 6) + (seed >> 2)) + ; + } + template + inline SPROUT_CONSTEXPR std::size_t + hash_value_unsigned_1(T val, int length, std::size_t seed) { + return hash_value_unsigned_2(val, length, seed, length * std::numeric_limits::digits); + } + template + inline SPROUT_CONSTEXPR std::size_t + hash_value_unsigned(T val) { + return sprout::hash_detail::hash_value_unsigned_1( + val, + (std::numeric_limits::digits - 1) / std::numeric_limits::digits, + 0 + ); + } + + inline std::size_t + hash_value_pointer_1(std::size_t x) { + return x + (x >> 3); + } + template + std::size_t + hash_value_pointer(T const* v) { + return sprout::hash_detail::hash_value_pointer_1(static_cast(reinterpret_cast(v))); + } + + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type + hash_value_impl(T v) { + return static_cast(v); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type + hash_value_impl(T v) { + return sprout::hash_detail::hash_value_signed(v); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type + hash_value_impl(T v) { + return sprout::hash_detail::hash_value_unsigned(v); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type + hash_value_impl(T v) { + return sprout::hash_detail::hash_value_impl(static_cast::type>(v)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, std::size_t>::type + hash_value_impl(T v) { + return sprout::detail::float_hash_value(v); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::type>::value, std::size_t>::type + hash_value_impl(T&& v) { + return sprout::hash_detail::hash_value_pointer(v); + } + template + inline SPROUT_CONSTEXPR std::size_t + hash_value_impl(T const (&v)[N]) { + return sprout::hash_range(v); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !std::is_arithmetic::value && !std::is_enum::value && !std::is_pointer::value, + std::size_t + >::type + hash_value_impl(T const &v) { + return std::hash::type>()(v); + } + } // namespace hash_detail + + // + // hash_value_traits + // + template + struct hash_value_traits { + public: + static SPROUT_CONSTEXPR std::size_t + hash_value(T const& v) { + return sprout::hash_detail::hash_value_impl(v); + } + }; + template + struct hash_value_traits + : public sprout::hash_value_traits + {}; + template + struct hash_value_traits + : public sprout::hash_value_traits + {}; + template + struct hash_value_traits + : public sprout::hash_value_traits + {}; +} // namespace sprout + +#include + +#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUE_TRAITS_HPP diff --git a/sprout/functional/hash/sscrisk/cel/array.hpp b/sprout/functional/hash/sscrisk/cel/array.hpp index 1ee76cf3..ad16545b 100644 --- a/sprout/functional/hash/sscrisk/cel/array.hpp +++ b/sprout/functional/hash/sscrisk/cel/array.hpp @@ -4,17 +4,21 @@ #include #include #include -#include +#include +#include namespace sprout { // - // hash_value + // hash_value_traits // template - inline SPROUT_CONSTEXPR std::size_t - hash_value(sscrisk::cel::array const& v) { - return sprout::hash_range(v); - } + struct hash_value_traits > { + public: + static SPROUT_CONSTEXPR std::size_t + hash_value(sscrisk::cel::array const& v) { + return sprout::hash_range(v); + } + }; } // namespace sprout #endif // #ifndef SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_ARRAY_HPP diff --git a/sprout/functional/hash/sscrisk/cel/utility.hpp b/sprout/functional/hash/sscrisk/cel/utility.hpp index 3d1b1130..4d58013d 100644 --- a/sprout/functional/hash/sscrisk/cel/utility.hpp +++ b/sprout/functional/hash/sscrisk/cel/utility.hpp @@ -4,17 +4,21 @@ #include #include #include -#include +#include +#include namespace sprout { // - // hash_value + // hash_value_traits // template - inline SPROUT_CONSTEXPR std::size_t - hash_value(sscrisk::cel::pair const& v) { - return sprout::hash_values(v.first, v.second); - } + struct hash_value_traits > { + public: + static SPROUT_CONSTEXPR std::size_t + hash_value(sscrisk::cel::pair const& v) { + return sprout::hash_values(v.first, v.second); + } + }; } // namespace sprout #endif // #ifndef SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_UTILITY_HPP diff --git a/sprout/functional/hash/std/array.hpp b/sprout/functional/hash/std/array.hpp index 39a2cddb..3e7cada2 100644 --- a/sprout/functional/hash/std/array.hpp +++ b/sprout/functional/hash/std/array.hpp @@ -4,17 +4,21 @@ #include #include #include -#include +#include +#include namespace sprout { // - // hash_value + // hash_value_traits // template - inline SPROUT_CONSTEXPR std::size_t - hash_value(std::array const& v) { - return sprout::hash_range(v); - } + struct hash_value_traits > { + public: + static SPROUT_CONSTEXPR std::size_t + hash_value(std::array const& v) { + return sprout::hash_range(v); + } + }; } // namespace sprout #endif // #ifndef SPROUT_FUNCTIONAL_HASH_STD_ARRAY_HPP diff --git a/sprout/functional/hash/std/utility.hpp b/sprout/functional/hash/std/utility.hpp index f886a7fa..8feb316c 100644 --- a/sprout/functional/hash/std/utility.hpp +++ b/sprout/functional/hash/std/utility.hpp @@ -4,17 +4,21 @@ #include #include #include -#include +#include +#include namespace sprout { // - // hash_value + // hash_value_traits // template - inline SPROUT_CONSTEXPR std::size_t - hash_value(std::pair const& v) { - return sprout::hash_values(v.first, v.second); - } + struct hash_value_traits > { + public: + static SPROUT_CONSTEXPR std::size_t + hash_value(std::pair const& v) { + return sprout::hash_values(v.first, v.second); + } + }; } // namespace sprout #endif // #ifndef SPROUT_FUNCTIONAL_HASH_STD_UTILITY_HPP diff --git a/sprout/functional/hash/to_hash.hpp b/sprout/functional/hash/to_hash.hpp index c9a6fc84..16c2bff7 100644 --- a/sprout/functional/hash/to_hash.hpp +++ b/sprout/functional/hash/to_hash.hpp @@ -2,144 +2,28 @@ #define SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP #include -#include -#include #include #include -#include #include -#include #include namespace sprout_adl { sprout::not_found_via_adl hash_value(...); } // namespace sprout_adl -namespace sprout_hash_detail { - using sprout::hash_value; - using sprout_adl::hash_value; - - template - struct has_adl_hash_value_test { - public: - template< - typename U = T, - typename sprout::enabler_if< - sprout::is_found_via_adl()))>::value - >::type = sprout::enabler - > - static std::true_type test(int); - static std::false_type test(...); - }; -#if defined(_MSC_VER) - template::test(0))> - struct has_adl_hash_value - : public Base_ - {}; -#else - template - struct has_adl_hash_value - : public decltype(sprout_hash_detail::has_adl_hash_value_test::test(0)) - {}; -#endif - - template - struct select_adl_hash_value; - template - struct select_adl_hash_value< - T, - typename std::enable_if< - sprout_hash_detail::has_adl_hash_value::value - >::type - > - : public std::true_type - {}; - template - struct select_adl_hash_value< - T, - typename std::enable_if::value - )>::type - > - : public std::false_type - {}; - - template - struct select_std_hash; - template - struct select_std_hash< - T, - typename std::enable_if< - !sprout_hash_detail::has_adl_hash_value::value - >::type - > - : public std::true_type - {}; - template - struct select_std_hash< - T, - typename std::enable_if::value - )>::type - > - : public std::false_type - {}; - - template - struct noexcept_to_hash; - template - struct noexcept_to_hash::value>::type> - : public std::integral_constant()), false)> - {}; - template - struct noexcept_to_hash::value>::type> - : public std::integral_constant::type>()(std::declval()), false)> - {}; - - template - struct to_hash_result; - template - struct to_hash_result::value>::type> { - public: - typedef decltype(hash_value(std::declval())) type; - }; - template - struct to_hash_result::value>::type> { - public: - typedef decltype(std::hash::type>()(std::declval())) type; - }; - - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_hash_detail::to_hash_result::type - to_hash_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_hash_detail::noexcept_to_hash::value)) - { - return hash_value(sprout::forward(t)); - } - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_hash_detail::to_hash_result::type - to_hash_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_hash_detail::noexcept_to_hash::value)) - { - return std::hash::type>()(sprout::forward(t)); - } -} // namespace sprout_hash_detail - namespace sprout { // // to_hash // template inline SPROUT_CONSTEXPR std::size_t - to_hash(T const& v) { - return sprout_hash_detail::to_hash_impl(v); + to_hash(T&& v) { + using sprout::hash_value; + using sprout_adl::hash_value; + return hash_value(sprout::forward(v)); } } // namespace sprout +#include + #endif // #ifndef SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP diff --git a/sprout/generator.hpp b/sprout/generator.hpp index d13c995d..6d59606e 100644 --- a/sprout/generator.hpp +++ b/sprout/generator.hpp @@ -2,5 +2,6 @@ #define SPROUT_GENERATOR_HPP #include +#include #endif // #ifndef SPROUT_GENERATOR_HPP diff --git a/sprout/generator/functions.hpp b/sprout/generator/functions.hpp index e06143d3..44f91315 100644 --- a/sprout/generator/functions.hpp +++ b/sprout/generator/functions.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_GENERATOR_FUNCTIONS_HPP #define SPROUT_GENERATOR_FUNCTIONS_HPP +#include #include #include diff --git a/sprout/generator/generated_value.hpp b/sprout/generator/generated_value.hpp index 6745ec56..187875f6 100644 --- a/sprout/generator/generated_value.hpp +++ b/sprout/generator/generated_value.hpp @@ -3,9 +3,9 @@ #include #include +#include #include -#include -#include +#include #include namespace sprout_adl { @@ -13,208 +13,56 @@ namespace sprout_adl { } // namespace sprout_adl namespace sprout_generator_detail { - using sprout::tuples::get; using sprout_adl::generated_value; - template - struct has_adl_generated_value_test { - public: - template< - typename U = T, - typename sprout::enabler_if< - sprout::is_found_via_adl()))>::value - >::type = sprout::enabler - > - static std::true_type test(int); - static std::false_type test(...); - }; -#if defined(_MSC_VER) - template::test(0))> - struct has_adl_generated_value - : public Base_ - {}; -#else - template - struct has_adl_generated_value - : public decltype(sprout_generator_detail::has_adl_generated_value_test::test(0)) - {}; -#endif - - template - struct has_mem_generated_value_test { - public: - template< - typename U = T, - typename = decltype(std::declval().generated_value()) - > - static std::true_type test(int); - static std::false_type test(...); - }; -#if defined(_MSC_VER) - template::test(0))> - struct has_mem_generated_value - : public Base_ - {}; -#else - template - struct has_mem_generated_value - : public decltype(sprout_generator_detail::has_mem_generated_value_test::test(0)) - {}; -#endif - - template - struct has_get_generated_value_test { - public: - template< - typename U = T, - typename = decltype(get<0>(std::declval())) - > - static std::true_type test(int); - static std::false_type test(...); - }; -#if defined(_MSC_VER) - template::test(0))> - struct has_get_generated_value - : public Base_ - {}; -#else - template - struct has_get_generated_value - : public decltype(sprout_generator_detail::has_get_generated_value_test::test(0)) - {}; -#endif - - template - struct select_adl_generated_value; - template - struct select_adl_generated_value< - T, - typename std::enable_if< - sprout_generator_detail::has_adl_generated_value::value - >::type - > - : public std::true_type - {}; - template - struct select_adl_generated_value< - T, - typename std::enable_if::value - )>::type - > - : public std::false_type - {}; - - template - struct select_mem_generated_value; - template - struct select_mem_generated_value< - T, - typename std::enable_if< - sprout_generator_detail::has_mem_generated_value::value - && !sprout_generator_detail::has_adl_generated_value::value - >::type - > - : public std::true_type - {}; - template - struct select_mem_generated_value< - T, - typename std::enable_if::value - && !sprout_generator_detail::has_adl_generated_value::value - )>::type - > - : public std::false_type - {}; - - template - struct select_get_generated_value; - template - struct select_get_generated_value< - T, - typename std::enable_if< - sprout_generator_detail::has_get_generated_value::value - && !sprout_generator_detail::has_adl_generated_value::value - && !sprout_generator_detail::has_mem_generated_value::value - >::type - > - : public std::true_type - {}; - template - struct select_get_generated_value< - T, - typename std::enable_if::value - && !sprout_generator_detail::has_adl_generated_value::value - && !sprout_generator_detail::has_mem_generated_value::value - )>::type - > - : public std::false_type - {}; - - template - struct noexcept_generated_value; - template - struct noexcept_generated_value::value>::type> - : public std::integral_constant()), false)> - {}; - template - struct noexcept_generated_value::value>::type> - : public std::integral_constant().generated_value(), false)> - {}; - template - struct noexcept_generated_value::value>::type> - : public std::integral_constant(std::declval()), false)> - {}; - - template - struct generated_value_result; - template - struct generated_value_result::value>::type> { - public: - typedef decltype(generated_value(std::declval())) type; - }; - template - struct generated_value_result::value>::type> { - public: - typedef decltype(std::declval().generated_value()) type; - }; - template - struct generated_value_result::value>::type> { - public: - typedef decltype(get<0>(std::declval())) type; - }; + template + inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::generated_value(std::declval())) + generated_value(Gen& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits::generated_value(std::declval()))) + { + return sprout::generators::generator_access_traits::generated_value(gen); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, + decltype(sprout::generators::generator_access_traits::type>::generated_value(std::declval())) + >::type + generated_value(Gen&& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits::type>::generated_value(std::declval()))) + { + return sprout::generators::generator_access_traits::generated_value(gen); + } + template + inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::generated_value(std::declval())) + generated_value(Gen const& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits::generated_value(std::declval()))) + { + return sprout::generators::generator_access_traits::generated_value(gen); + } - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type - generated_value_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) + template + inline SPROUT_CONSTEXPR decltype(generated_value(std::declval())) + call_generated_value(Gen& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(generated_value(std::declval()))) { - return generated_value(sprout::forward(t)); + return generated_value(gen); } - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type - generated_value_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, + decltype(generated_value(std::declval())) + >::type + call_generated_value(Gen&& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(generated_value(std::declval()))) { - return sprout::forward(t).generated_value(); + return generated_value(gen); } - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type - generated_value_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) + template + inline SPROUT_CONSTEXPR decltype(generated_value(std::declval())) + call_generated_value(Gen const& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(generated_value(std::declval()))) { - return get<0>(sprout::forward(t)); + return generated_value(gen); } } // namespace sprout_generator_detail @@ -224,11 +72,11 @@ namespace sprout { // generated_value // template - inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type + inline SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_generated_value(std::declval())) generated_value(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_generator_detail::call_generated_value(std::declval()))) { - return sprout_generator_detail::generated_value_impl(sprout::forward(t)); + return sprout_generator_detail::call_generated_value(sprout::forward(t)); } } // namespace generators diff --git a/sprout/generator/generator_access_traits.hpp b/sprout/generator/generator_access_traits.hpp new file mode 100644 index 00000000..94177be5 --- /dev/null +++ b/sprout/generator/generator_access_traits.hpp @@ -0,0 +1,192 @@ +#ifndef SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP +#define SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace generators { + namespace detail { + template + struct has_mem_generated_value_test { + public: + template< + typename U = T, + typename = decltype(std::declval().generated_value()) + > + static std::true_type test(int); + static std::false_type test(...); + }; +#if defined(_MSC_VER) + template::test(0))> + struct has_mem_generated_value + : public Base_ + {}; +#else + template + struct has_mem_generated_value + : public decltype(sprout::generators::detail::has_mem_generated_value_test::test(0)) + {}; +#endif + + template + struct generator_access_traits_generated_value_impl; + template + struct generator_access_traits_generated_value_impl< + Gen, + typename std::enable_if::value>::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().generated_value()) + generated_value(Gen& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval().generated_value())) + { + return t.generated_value(); + } + static SPROUT_CONSTEXPR decltype(std::declval().generated_value()) + generated_value(Gen&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval().generated_value())) + { + return t.generated_value(); + } + static SPROUT_CONSTEXPR decltype(std::declval().generated_value()) + generated_value(Gen const& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval().generated_value())) + { + return t.generated_value(); + } + }; + template + struct generator_access_traits_generated_value_impl< + Gen, + typename std::enable_if::value>::type + > { + public: + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval())) + generated_value(Gen& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<0>(std::declval()))) + { + return sprout::tuples::get<0>(t); + } + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval())) + generated_value(Gen&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<0>(std::declval()))) + { + return sprout::tuples::get<0>(t); + } + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval())) + generated_value(Gen const& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<0>(std::declval()))) + { + return sprout::tuples::get<0>(t); + } + }; + + template + struct has_mem_next_generator_test { + public: + template< + typename U = T, + typename = decltype(std::declval().next_generator()) + > + static std::true_type test(int); + static std::false_type test(...); + }; +#if defined(_MSC_VER) + template::test(0))> + struct has_mem_next_generator + : public Base_ + {}; +#else + template + struct has_mem_next_generator + : public decltype(sprout::generators::detail::has_mem_next_generator_test::test(0)) + {}; +#endif + + template + struct generator_access_traits_next_generator_impl; + template + struct generator_access_traits_next_generator_impl< + Gen, + typename std::enable_if::value>::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().next_generator()) + next_generator(Gen& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval().next_generator())) + { + return t.next_generator(); + } + static SPROUT_CONSTEXPR decltype(std::declval().next_generator()) + next_generator(Gen&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval().next_generator())) + { + return t.next_generator(); + } + static SPROUT_CONSTEXPR decltype(std::declval().next_generator()) + next_generator(Gen const& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval().next_generator())) + { + return t.next_generator(); + } + }; + template + struct generator_access_traits_next_generator_impl< + Gen, + typename std::enable_if::value>::type + > { + public: + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval())) + next_generator(Gen& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<1>(std::declval()))) + { + return sprout::tuples::get<1>(t); + } + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval())) + next_generator(Gen&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<1>(std::declval()))) + { + return sprout::tuples::get<1>(t); + } + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval())) + next_generator(Gen const& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<1>(std::declval()))) + { + return sprout::tuples::get<1>(t); + } + }; + } // namespace detail + + // + // generator_access_traits + // + template + struct generator_access_traits + : public sprout::generators::detail::generator_access_traits_generated_value_impl + , public sprout::generators::detail::generator_access_traits_next_generator_impl + {}; + template + struct generator_access_traits { + public: + static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::generated_value(std::declval())) + generated_value(Gen const& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits::generated_value(std::declval()))) + { + return sprout::generators::generator_access_traits::generated_value(t); + } + static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::next_generator(std::declval())) + next_generator(Gen const& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits::next_generator(std::declval()))) + { + return sprout::generators::generator_access_traits::next_generator(t); + } + }; + } // namespace generators + + using sprout::generators::generator_access_traits; +} // namespace sprout + +#endif // #ifndef SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP diff --git a/sprout/generator/next_generator.hpp b/sprout/generator/next_generator.hpp index 643808fc..f2f4ee98 100644 --- a/sprout/generator/next_generator.hpp +++ b/sprout/generator/next_generator.hpp @@ -3,9 +3,9 @@ #include #include +#include #include -#include -#include +#include #include namespace sprout_adl { @@ -13,208 +13,56 @@ namespace sprout_adl { } // namespace sprout_adl namespace sprout_generator_detail { - using sprout::tuples::get; using sprout_adl::next_generator; - template - struct has_adl_next_generator_test { - public: - template< - typename U = T, - typename sprout::enabler_if< - sprout::is_found_via_adl()))>::value - >::type = sprout::enabler - > - static std::true_type test(int); - static std::false_type test(...); - }; -#if defined(_MSC_VER) - template::test(0))> - struct has_adl_next_generator - : public Base_ - {}; -#else - template - struct has_adl_next_generator - : public decltype(sprout_generator_detail::has_adl_next_generator_test::test(0)) - {}; -#endif - - template - struct has_mem_next_generator_test { - public: - template< - typename U = T, - typename = decltype(std::declval().next_generator()) - > - static std::true_type test(int); - static std::false_type test(...); - }; -#if defined(_MSC_VER) - template::test(0))> - struct has_mem_next_generator - : public Base_ - {}; -#else - template - struct has_mem_next_generator - : public decltype(sprout_generator_detail::has_mem_next_generator_test::test(0)) - {}; -#endif - - template - struct has_get_next_generator_test { - public: - template< - typename U = T, - typename = decltype(get<1>(std::declval())) - > - static std::true_type test(int); - static std::false_type test(...); - }; -#if defined(_MSC_VER) - template::test(0))> - struct has_get_next_generator - : public Base_ - {}; -#else - template - struct has_get_next_generator - : public decltype(sprout_generator_detail::has_get_next_generator_test::test(0)) - {}; -#endif - - template - struct select_adl_next_generator; - template - struct select_adl_next_generator< - T, - typename std::enable_if< - sprout_generator_detail::has_adl_next_generator::value - >::type - > - : public std::true_type - {}; - template - struct select_adl_next_generator< - T, - typename std::enable_if::value - )>::type - > - : public std::false_type - {}; - - template - struct select_mem_next_generator; - template - struct select_mem_next_generator< - T, - typename std::enable_if< - sprout_generator_detail::has_mem_next_generator::value - && !sprout_generator_detail::has_adl_next_generator::value - >::type - > - : public std::true_type - {}; - template - struct select_mem_next_generator< - T, - typename std::enable_if::value - && !sprout_generator_detail::has_adl_next_generator::value - )>::type - > - : public std::false_type - {}; - - template - struct select_get_next_generator; - template - struct select_get_next_generator< - T, - typename std::enable_if< - sprout_generator_detail::has_get_next_generator::value - && !sprout_generator_detail::has_adl_next_generator::value - && !sprout_generator_detail::has_mem_next_generator::value - >::type - > - : public std::true_type - {}; - template - struct select_get_next_generator< - T, - typename std::enable_if::value - && !sprout_generator_detail::has_adl_next_generator::value - && !sprout_generator_detail::has_mem_next_generator::value - )>::type - > - : public std::false_type - {}; - - template - struct noexcept_next_generator; - template - struct noexcept_next_generator::value>::type> - : public std::integral_constant()), false)> - {}; - template - struct noexcept_next_generator::value>::type> - : public std::integral_constant().next_generator(), false)> - {}; - template - struct noexcept_next_generator::value>::type> - : public std::integral_constant(std::declval()), false)> - {}; - - template - struct next_generator_result; - template - struct next_generator_result::value>::type> { - public: - typedef decltype(next_generator(std::declval())) type; - }; - template - struct next_generator_result::value>::type> { - public: - typedef decltype(std::declval().next_generator()) type; - }; - template - struct next_generator_result::value>::type> { - public: - typedef decltype(get<1>(std::declval())) type; - }; + template + inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::next_generator(std::declval())) + next_generator(Gen& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits::next_generator(std::declval()))) + { + return sprout::generators::generator_access_traits::next_generator(gen); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, + decltype(sprout::generators::generator_access_traits::type>::next_generator(std::declval())) + >::type + next_generator(Gen&& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits::type>::next_generator(std::declval()))) + { + return sprout::generators::generator_access_traits::next_generator(gen); + } + template + inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::next_generator(std::declval())) + next_generator(Gen const& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits::next_generator(std::declval()))) + { + return sprout::generators::generator_access_traits::next_generator(gen); + } - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type - next_generator_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) + template + inline SPROUT_CONSTEXPR decltype(next_generator(std::declval())) + call_next_generator(Gen& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(next_generator(std::declval()))) { - return next_generator(sprout::forward(t)); + return next_generator(gen); } - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type - next_generator_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, + decltype(next_generator(std::declval())) + >::type + call_next_generator(Gen&& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(next_generator(std::declval()))) { - return sprout::forward(t).next_generator(); + return next_generator(gen); } - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type - next_generator_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) + template + inline SPROUT_CONSTEXPR decltype(next_generator(std::declval())) + call_next_generator(Gen const& gen) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(next_generator(std::declval()))) { - return get<1>(sprout::forward(t)); + return next_generator(gen); } } // namespace sprout_generator_detail @@ -224,11 +72,11 @@ namespace sprout { // next_generator // template - inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type + inline SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_next_generator(std::declval())) next_generator(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_generator_detail::call_next_generator(std::declval()))) { - return sprout_generator_detail::next_generator_impl(sprout::forward(t)); + return sprout_generator_detail::call_next_generator(sprout::forward(t)); } } // namespace generators diff --git a/sprout/tuple/sscrisk/cel/array.hpp b/sprout/tuple/sscrisk/cel/array.hpp index 406512b3..e9cb43f8 100644 --- a/sprout/tuple/sscrisk/cel/array.hpp +++ b/sprout/tuple/sscrisk/cel/array.hpp @@ -6,29 +6,36 @@ #include #include #include +#include #include -namespace sprout_adl { - // - // tuple_get - // - template - inline SPROUT_CONSTEXPR T& - tuple_get(sscrisk::cel::array& t) SPROUT_NOEXCEPT { - static_assert(I < N, "tuple_get: index out of range"); - return t[I]; - } - template - inline SPROUT_CONSTEXPR T const& - tuple_get(sscrisk::cel::array const& t) SPROUT_NOEXCEPT { - static_assert(I < N, "tuple_get: index out of range"); - return t[I]; - } - template - inline SPROUT_CONSTEXPR T&& - tuple_get(sscrisk::cel::array&& t) SPROUT_NOEXCEPT { - return sprout::move(sprout::tuples::get(t)); - } -} // namespace sprout_adl +namespace sprout { + namespace tuples { + // + // tuple_access_traits + // + template + struct tuple_access_traits > { + public: + template + static SPROUT_CONSTEXPR T& + tuple_get(sscrisk::cel::array& t) SPROUT_NOEXCEPT { + static_assert(I < N, "tuple_get: index out of range"); + return t[I]; + } + template + static SPROUT_CONSTEXPR T const& + tuple_get(sscrisk::cel::array const& t) SPROUT_NOEXCEPT { + static_assert(I < N, "tuple_get: index out of range"); + return t[I]; + } + template + static SPROUT_CONSTEXPR T&& + tuple_get(sscrisk::cel::array&& t) SPROUT_NOEXCEPT { + return sprout::move(tuple_get(t)); + } + }; + } // namespace tuples +} // namespace sprout #endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_ARRAY_HPP diff --git a/sprout/tuple/sscrisk/cel/utility.hpp b/sprout/tuple/sscrisk/cel/utility.hpp index ee23fa9e..c8fe1897 100644 --- a/sprout/tuple/sscrisk/cel/utility.hpp +++ b/sprout/tuple/sscrisk/cel/utility.hpp @@ -68,27 +68,33 @@ namespace sprout { } // namespace tuples } // namespace sprout -namespace sprout_adl { - // - // tuple_get - // - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& - tuple_get(sscrisk::cel::pair& t) SPROUT_NOEXCEPT { - static_assert(I < 2, "tuple_get: index out of range"); - return sprout::tuples::detail::get_impl >()(t); - } - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& - tuple_get(sscrisk::cel::pair const& t) SPROUT_NOEXCEPT { - static_assert(I < 2, "tuple_get: index out of range"); - return sprout::tuples::detail::get_impl >()(t); - } - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& - tuple_get(sscrisk::cel::pair&& t) SPROUT_NOEXCEPT { - return sprout::move(sprout::tuples::get(t)); - } -} // namespace sprout_adl +namespace sprout { + namespace tuples { + // + // tuple_access_traits + // + template + struct tuple_access_traits > { + public: + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& + tuple_get(sscrisk::cel::pair& t) SPROUT_NOEXCEPT { + static_assert(I < 2, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& + tuple_get(sscrisk::cel::pair const& t) SPROUT_NOEXCEPT { + static_assert(I < 2, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& + tuple_get(sscrisk::cel::pair&& t) SPROUT_NOEXCEPT { + return sprout::move(tuple_get(t)); + } + }; + } // namespace tuples +} // namespace sprout #endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP diff --git a/sprout/tuple/std/array.hpp b/sprout/tuple/std/array.hpp index 3ac6b824..bbb59185 100644 --- a/sprout/tuple/std/array.hpp +++ b/sprout/tuple/std/array.hpp @@ -6,29 +6,36 @@ #include #include #include +#include #include -namespace sprout_adl { - // - // tuple_get - // - template - inline SPROUT_CONSTEXPR T& - tuple_get(std::array& t) SPROUT_NOEXCEPT { - static_assert(I < N, "tuple_get: index out of range"); - return t[I]; - } - template - inline SPROUT_CONSTEXPR T const& - tuple_get(std::array const& t) SPROUT_NOEXCEPT { - static_assert(I < N, "tuple_get: index out of range"); - return t[I]; - } - template - inline SPROUT_CONSTEXPR T&& - tuple_get(std::array&& t) SPROUT_NOEXCEPT { - return sprout::move(sprout::tuples::get(t)); - } -} // namespace sprout_adl +namespace sprout { + namespace tuples { + // + // tuple_access_traits + // + template + struct tuple_access_traits > { + public: + template + static SPROUT_CONSTEXPR T& + tuple_get(std::array& t) SPROUT_NOEXCEPT { + static_assert(I < N, "tuple_get: index out of range"); + return t[I]; + } + template + static SPROUT_CONSTEXPR T const& + tuple_get(std::array const& t) SPROUT_NOEXCEPT { + static_assert(I < N, "tuple_get: index out of range"); + return t[I]; + } + template + static SPROUT_CONSTEXPR T&& + tuple_get(std::array&& t) SPROUT_NOEXCEPT { + return sprout::move(tuple_get(t)); + } + }; + } // namespace tuples +} // namespace sprout #endif // #ifndef SPROUT_TUPLE_STD_ARRAY_HPP diff --git a/sprout/tuple/std/utility.hpp b/sprout/tuple/std/utility.hpp index 335d5fe2..d2a94678 100644 --- a/sprout/tuple/std/utility.hpp +++ b/sprout/tuple/std/utility.hpp @@ -38,27 +38,33 @@ namespace sprout { } // namespace tuples } // namespace sprout -namespace sprout_adl { - // - // tuple_get - // - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& - tuple_get(std::pair& t) SPROUT_NOEXCEPT { - static_assert(I < 2, "tuple_get: index out of range"); - return sprout::tuples::detail::get_impl >()(t); - } - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& - tuple_get(std::pair const& t) SPROUT_NOEXCEPT { - static_assert(I < 2, "tuple_get: index out of range"); - return sprout::tuples::detail::get_impl >()(t); - } - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& - tuple_get(std::pair&& t) SPROUT_NOEXCEPT { - return sprout::move(sprout::tuples::get(t)); - } -} // namespace sprout_adl +namespace sprout { + namespace tuples { + // + // tuple_access_traits + // + template + struct tuple_access_traits > { + public: + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& + tuple_get(std::pair& t) SPROUT_NOEXCEPT { + static_assert(I < 2, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& + tuple_get(std::pair const& t) SPROUT_NOEXCEPT { + static_assert(I < 2, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& + tuple_get(std::pair&& t) SPROUT_NOEXCEPT { + return sprout::move(tuple_get(t)); + } + }; + } // namespace tuples +} // namespace sprout #endif // #ifndef SPROUT_TUPLE_STD_UTILITY_HPP diff --git a/sprout/tuple/tuple.hpp b/sprout/tuple/tuple.hpp index 32363633..1eb300d5 100644 --- a/sprout/tuple/tuple.hpp +++ b/sprout/tuple/tuple.hpp @@ -6,11 +6,14 @@ #include #include #include +#include +#include #include #include #include #include #include +#include #include #endif // #ifndef SPROUT_TUPLE_TUPLE_HPP diff --git a/sprout/tuple/tuple/get.hpp b/sprout/tuple/tuple/get.hpp index 144d9b2b..d0f6022a 100644 --- a/sprout/tuple/tuple/get.hpp +++ b/sprout/tuple/tuple/get.hpp @@ -2,62 +2,21 @@ #define SPROUT_TUPLE_TUPLE_GET_HPP #include +#include #include -#include #include -#include #include #include +#include +#include +#include #include +//#include +//#include + namespace sprout { namespace tuples { - // - // tuple_size - // - template - struct tuple_size - : public std::tuple_size - {}; - template - struct tuple_size - : public sprout::tuples::tuple_size - {}; - template - struct tuple_size - : public sprout::tuples::tuple_size - {}; - template - struct tuple_size - : public sprout::tuples::tuple_size - {}; - - // - // tuple_element - // - template - struct tuple_element - : public std::tuple_element - {}; - template - struct tuple_element - : public std::add_const< - typename sprout::tuples::tuple_element::type - > - {}; - template - struct tuple_element - : public std::add_volatile< - typename sprout::tuples::tuple_element::type - > - {}; - template - struct tuple_element - : public std::add_cv< - typename sprout::tuples::tuple_element::type - > - {}; - namespace detail { template inline SPROUT_CONSTEXPR typename std::add_lvalue_reference::type @@ -71,30 +30,28 @@ namespace sprout { } } // namespace detail // - // get + // tuple_get // template inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& - get(sprout::tuples::tuple& t) SPROUT_NOEXCEPT { + tuple_get(sprout::tuples::tuple& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::get_helper(t); } template inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& - get(sprout::tuples::tuple&& t) SPROUT_NOEXCEPT { + tuple_get(sprout::tuples::tuple&& t) SPROUT_NOEXCEPT { return sprout::forward >::type&&>( - sprout::tuples::get(t) + sprout::tuples::tuple_get(t) ); } template inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& - get(sprout::tuples::tuple const& t) SPROUT_NOEXCEPT { + tuple_get(sprout::tuples::tuple const& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::get_helper(t); } } // namespace tuples - using sprout::tuples::tuple_size; - using sprout::tuples::tuple_element; - using sprout::tuples::get; + using sprout::tuples::tuple_get; } // namespace sprout namespace sprout_adl { @@ -106,135 +63,37 @@ namespace sprout_tuple_detail { using sprout_adl::tuple_get; template - struct has_adl_tuple_get_test { - public: - template< - typename U = T, - typename sprout::enabler_if< - sprout::is_found_via_adl(std::declval()))>::value - >::type = sprout::enabler - > - static std::true_type test(int); - static std::false_type test(...); - }; -#if defined(_MSC_VER) - template::test(0))> - struct has_adl_tuple_get - : public Base_ - {}; -#else - template - struct has_adl_tuple_get - : public decltype(sprout_tuple_detail::has_adl_tuple_get_test::test(0)) - {}; -#endif - - template - struct has_std_get_test { - public: - template< - typename U = T, - typename = decltype(std::get(std::declval())) - > - static std::true_type test(int); - static std::false_type test(...); - }; -#if defined(_MSC_VER) - template::test(0))> - struct has_std_get - : public Base_ - {}; -#else - template - struct has_std_get - : public decltype(sprout_tuple_detail::has_std_get_test::test(0)) - {}; -#endif - - template - struct select_adl_tuple_get; - template - struct select_adl_tuple_get< - I, T, - typename std::enable_if::value>::type - > - : public std::true_type - {}; - template - struct select_adl_tuple_get< - I, T, - typename std::enable_if::value>::type - > - : public std::false_type - {}; - - template - struct select_std_get; - template - struct select_std_get< - I, T, - typename std::enable_if< - sprout_tuple_detail::has_std_get::value - && !sprout_tuple_detail::has_adl_tuple_get::value - >::type - > - : public std::true_type - {}; - template - struct select_std_get< - I, T, - typename std::enable_if::value - && !sprout_tuple_detail::has_adl_tuple_get::value - )>::type - > - : public std::false_type - {}; - - template - struct noexcept_get; + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type& + tuple_get(T& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits::template tuple_get(std::declval()))) + { + return sprout::tuples::tuple_access_traits::template tuple_get(t); + } template - struct noexcept_get::value>::type> - : public std::integral_constant(std::declval()), false)> - {}; + inline SPROUT_CONSTEXPR typename std::enable_if< + !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, + typename sprout::tuples::tuple_element::type>::type&& + >::type + tuple_get(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits::type>::template tuple_get(std::declval()))) + { + return sprout::tuples::tuple_access_traits::template tuple_get(t); + } template - struct noexcept_get::value>::type> - : public std::integral_constant(std::declval()), false)> - {}; + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type const& + tuple_get(T const& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits::template tuple_get(std::declval()))) + { + return sprout::tuples::tuple_access_traits::template tuple_get(t); + } - template - struct get_result; template - struct get_result::value>::type> { - public: - typedef decltype(tuple_get(std::declval())) type; - }; - template - struct get_result::value>::type> { - public: - typedef decltype(std::get(std::declval())) type; - }; - - template< - std::size_t I, typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_tuple_detail::get_result::type - get_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get::value)) + inline SPROUT_CONSTEXPR decltype(tuple_get(std::declval())) + call_tuple_get(T&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(tuple_get(std::declval()))) { return tuple_get(sprout::forward(t)); } - template< - std::size_t I, typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_tuple_detail::get_result::type - get_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get::value)) - { - return std::get(sprout::forward(t)); - } } // namespace sprout_tuple_detail namespace sprout { @@ -243,11 +102,11 @@ namespace sprout { // get // template - inline SPROUT_CONSTEXPR typename sprout_tuple_detail::get_result::type + inline SPROUT_CONSTEXPR decltype(sprout_tuple_detail::call_tuple_get(std::declval())) get(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get::value)) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_tuple_detail::call_tuple_get(std::declval()))) { - return sprout_tuple_detail::get_impl(sprout::forward(t)); + return sprout_tuple_detail::call_tuple_get(sprout::forward(t)); } } // namespace tuples diff --git a/sprout/tuple/tuple/tuple_access_traits.hpp b/sprout/tuple/tuple/tuple_access_traits.hpp new file mode 100644 index 00000000..a09a24b6 --- /dev/null +++ b/sprout/tuple/tuple/tuple_access_traits.hpp @@ -0,0 +1,47 @@ +#ifndef SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP +#define SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // tuple_access_traits + // + template + struct tuple_access_traits { + public: + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type& + tuple_get(Tuple& t) SPROUT_NOEXCEPT { + return std::get(t); + } + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type&& + tuple_get(Tuple&& t) SPROUT_NOEXCEPT { + return std::get(t); + } + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type const& + tuple_get(Tuple const& t) SPROUT_NOEXCEPT { + return std::get(t); + } + }; + template + struct tuple_access_traits { + public: + template + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type const& + tuple_get(Tuple const& t) SPROUT_NOEXCEPT { + return sprout::tuples::tuple_access_traits::template tuple_get(t); + } + }; + } // namespace tuples + + using sprout::tuples::tuple_access_traits; +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP diff --git a/sprout/tuple/tuple/tuple_element.hpp b/sprout/tuple/tuple/tuple_element.hpp new file mode 100644 index 00000000..e2a3313a --- /dev/null +++ b/sprout/tuple/tuple/tuple_element.hpp @@ -0,0 +1,41 @@ +#ifndef SPROUT_TUPLE_TUPLE_TUPLE_ELEMENT_HPP +#define SPROUT_TUPLE_TUPLE_TUPLE_ELEMENT_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // tuple_element + // + template + struct tuple_element + : public std::tuple_element + {}; + template + struct tuple_element + : public std::add_const< + typename sprout::tuples::tuple_element::type + > + {}; + template + struct tuple_element + : public std::add_volatile< + typename sprout::tuples::tuple_element::type + > + {}; + template + struct tuple_element + : public std::add_cv< + typename sprout::tuples::tuple_element::type + > + {}; + } // namespace tuples + + using sprout::tuples::tuple_element; +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_ELEMENT_HPP diff --git a/sprout/tuple/tuple/tuple_size.hpp b/sprout/tuple/tuple/tuple_size.hpp new file mode 100644 index 00000000..23522012 --- /dev/null +++ b/sprout/tuple/tuple/tuple_size.hpp @@ -0,0 +1,33 @@ +#ifndef SPROUT_TUPLE_TUPLE_TUPLE_SIZE_HPP +#define SPROUT_TUPLE_TUPLE_TUPLE_SIZE_HPP + +#include +#include + +namespace sprout { + namespace tuples { + // + // tuple_size + // + template + struct tuple_size + : public std::tuple_size + {}; + template + struct tuple_size + : public sprout::tuples::tuple_size + {}; + template + struct tuple_size + : public sprout::tuples::tuple_size + {}; + template + struct tuple_size + : public sprout::tuples::tuple_size + {}; + } // namespace tuples + + using sprout::tuples::tuple_size; +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_SIZE_HPP