fix adapt interface: container, tuple, hash, generator

This commit is contained in:
bolero-MURAKAMI 2013-04-22 13:04:27 +09:00
parent 61720b72c3
commit 74e0c8acd6
36 changed files with 970 additions and 1056 deletions

View file

@ -1,9 +1,9 @@
#ifndef SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP #ifndef SPROUT_ADAPT_STD_UTILITY_HPP
#define SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP #define SPROUT_ADAPT_STD_UTILITY_HPP
#include <utility> #include <utility>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/functional/hash/std/utility.hpp> #include <sprout/functional/hash/std/utility.hpp>
#include <sprout/tuple/std/utility.hpp> #include <sprout/tuple/std/utility.hpp>
#endif // #ifndef SPROUT_ADAPT_SSCRISK_CEL_UTILITY_HPP #endif // #ifndef SPROUT_ADAPT_STD_UTILITY_HPP

View file

@ -4,6 +4,7 @@
#include <cstddef> #include <cstddef>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/container/container_traits.hpp> #include <sprout/container/container_traits.hpp>
#include <sprout/container/container_range_traits.hpp>
#include <sprout/adl/not_found.hpp> #include <sprout/adl/not_found.hpp>
namespace sprout_adl { namespace sprout_adl {
@ -13,56 +14,41 @@ namespace sprout_adl {
namespace sprout { namespace sprout {
namespace container_detail { namespace container_detail {
template<typename Container> template<typename Container>
inline typename sprout::container_traits<Container>::iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
range_begin(Container& cont) { range_begin(Container& cont) {
return cont.begin(); return sprout::container_range_traits<Container>::range_begin(cont);
} }
template<typename Container> template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
range_begin(Container const& cont) { range_begin(Container const& cont) {
return cont.begin(); return sprout::container_range_traits<Container>::range_begin(cont);
}
template<typename T, std::size_t N>
inline typename sprout::container_traits<T[N]>::iterator
range_begin(T (& arr)[N]) {
typedef typename sprout::container_traits<T[N]>::iterator iterator;
return iterator(arr);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::const_iterator
range_begin(T const (& arr)[N]) {
typedef typename sprout::container_traits<T const[N]>::const_iterator iterator;
return iterator(arr);
} }
} // namespace container_detail } // namespace container_detail
} // namespace sprout
namespace sprout {
// //
// begin // begin
// //
template<typename Container> template<typename Container>
inline typename sprout::container_traits<Container>::iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
begin(Container& cont) { begin(Container& cont) {
using sprout::container_detail::range_begin; using sprout::container_detail::range_begin;
using sprout_adl::range_begin; using sprout_adl::range_begin;
return range_begin(cont); return range_begin(cont);
} }
template<typename Container> template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
begin(Container const& cont) { begin(Container const& cont) {
using sprout::container_detail::range_begin; using sprout::container_detail::range_begin;
using sprout_adl::range_begin; using sprout_adl::range_begin;
return range_begin(cont); return range_begin(cont);
} }
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline typename sprout::container_traits<T[N]>::iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::iterator
begin(T (& arr)[N]) { begin(T (& arr)[N]) {
return sprout::container_detail::range_begin(arr); return sprout::container_detail::range_begin(arr);
} }
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::iterator
begin(T const (& arr)[N]) { begin(T const (& arr)[N]) {
return sprout::container_detail::range_begin(arr); return sprout::container_detail::range_begin(arr);
} }
@ -71,14 +57,14 @@ namespace sprout {
// cbegin // cbegin
// //
template<typename Container> template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
cbegin(Container const& cont) { cbegin(Container const& cont) {
using sprout::container_detail::range_begin; using sprout::container_detail::range_begin;
using sprout_adl::range_begin; using sprout_adl::range_begin;
return range_begin(cont); return range_begin(cont);
} }
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::iterator
cbegin(T const (& arr)[N]) { cbegin(T const (& arr)[N]) {
return sprout::container_detail::range_begin(arr); return sprout::container_detail::range_begin(arr);
} }

View file

@ -0,0 +1,87 @@
#ifndef SPROUT_CONTAINER_CONTAINER_RANGE_TRAITS_HPP
#define SPROUT_CONTAINER_CONTAINER_RANGE_TRAITS_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/container/container_traits.hpp>
namespace sprout {
//
// container_range_traits
//
template<typename Container>
struct container_range_traits {
public:
static SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
range_begin(Container& cont) {
return cont.begin();
}
static SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
range_begin(Container const& cont) {
return cont.begin();
}
static SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
range_end(Container& cont) {
return cont.end();
}
static SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
range_end(Container const& cont) {
return cont.end();
}
};
template<typename Container>
struct container_range_traits<Container const> {
public:
static SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
range_begin(Container const& cont) {
return sprout::container_range_traits<Container>::range_begin(cont);
}
static SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
range_end(Container const& cont) {
return sprout::container_range_traits<Container>::range_end(cont);
}
};
template<typename T, std::size_t N>
struct container_range_traits<T[N]> {
public:
static SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::iterator
range_begin(T (& arr)[N]) {
typedef typename sprout::container_traits<T[N]>::iterator type;
return type(arr);
}
static SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::iterator
range_begin(T const (& arr)[N]) {
typedef typename sprout::container_traits<T const[N]>::iterator type;
return type(arr);
}
static SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::iterator
range_end(T (& arr)[N]) {
typedef typename sprout::container_traits<T[N]>::iterator type;
return type(arr) + N;
}
static SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::iterator
range_end(T const (& arr)[N]) {
typedef typename sprout::container_traits<T const[N]>::iterator type;
return type(arr) + N;
}
};
template<typename T, std::size_t N>
struct container_range_traits<T const[N]> {
public:
static SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::iterator
range_begin(T const (& arr)[N]) {
return sprout::container_range_traits<T[N]>::range_begin(arr);
}
static SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::const_iterator
range_end(T const (& arr)[N]) {
return sprout::container_range_traits<T[N]>::range_end(arr);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_CONTAINER_CONTAINER_RANGE_TRAITS_HPP

View file

@ -4,6 +4,7 @@
#include <cstddef> #include <cstddef>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/container/container_traits.hpp> #include <sprout/container/container_traits.hpp>
#include <sprout/container/container_range_traits.hpp>
#include <sprout/adl/not_found.hpp> #include <sprout/adl/not_found.hpp>
namespace sprout_adl { namespace sprout_adl {
@ -13,56 +14,41 @@ namespace sprout_adl {
namespace sprout { namespace sprout {
namespace container_detail { namespace container_detail {
template<typename Container> template<typename Container>
inline typename sprout::container_traits<Container>::iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
range_end(Container& cont) { range_end(Container& cont) {
return cont.end(); return sprout::container_range_traits<Container>::range_end(cont);
} }
template<typename Container> template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
range_end(Container const& cont) { range_end(Container const& cont) {
return cont.end(); return sprout::container_range_traits<Container>::range_end(cont);
}
template<typename T, std::size_t N>
inline typename sprout::container_traits<T[N]>::iterator
range_end(T (& arr)[N]) {
typedef typename sprout::container_traits<T[N]>::iterator iterator;
return iterator(arr) + N;
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::const_iterator
range_end(T const (& arr)[N]) {
typedef typename sprout::container_traits<T const[N]>::const_iterator iterator;
return iterator(arr) + N;
} }
} // namespace container_detail } // namespace container_detail
} // namespace sprout
namespace sprout {
// //
// end // end
// //
template<typename Container> template<typename Container>
inline typename sprout::container_traits<Container>::iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
end(Container& cont) { end(Container& cont) {
using sprout::container_detail::range_end; using sprout::container_detail::range_end;
using sprout_adl::range_end; using sprout_adl::range_end;
return range_end(cont); return range_end(cont);
} }
template<typename Container> template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
end(Container const& cont) { end(Container const& cont) {
using sprout::container_detail::range_end; using sprout::container_detail::range_end;
using sprout_adl::range_end; using sprout_adl::range_end;
return range_end(cont); return range_end(cont);
} }
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline typename sprout::container_traits<T[N]>::iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::iterator
end(T (& arr)[N]) { end(T (& arr)[N]) {
return sprout::container_detail::range_end(arr); return sprout::container_detail::range_end(arr);
} }
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::iterator
end(T const (& arr)[N]) { end(T const (& arr)[N]) {
return sprout::container_detail::range_end(arr); return sprout::container_detail::range_end(arr);
} }
@ -71,14 +57,14 @@ namespace sprout {
// cend // cend
// //
template<typename Container> template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
cend(Container const& cont) { cend(Container const& cont) {
using sprout::container_detail::range_end; using sprout::container_detail::range_end;
using sprout_adl::range_end; using sprout_adl::range_end;
return range_end(cont); return range_end(cont);
} }
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::const_iterator inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::iterator
cend(T const (& arr)[N]) { cend(T const (& arr)[N]) {
return sprout::container_detail::range_end(arr); return sprout::container_detail::range_end(arr);
} }

View file

@ -23,36 +23,31 @@ namespace sprout {
typedef sprout::index_iterator<sscrisk::cel::array<T, N>&, true> iterator; typedef sprout::index_iterator<sscrisk::cel::array<T, N>&, true> iterator;
typedef sprout::index_iterator<sscrisk::cel::array<T, N> const&, true> const_iterator; typedef sprout::index_iterator<sscrisk::cel::array<T, N> const&, true> const_iterator;
}; };
} // namespace sprout
namespace sprout {
// //
// range_begin // container_range_traits
// //
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline typename sprout::container_traits<sscrisk::cel::array<T, N> >::iterator struct container_range_traits<sscrisk::cel::array<T, N> > {
range_begin(sscrisk::cel::array<T, N>& cont) { public:
return typename sprout::container_traits<sscrisk::cel::array<T, N> >::iterator(cont, 0); static SPROUT_CONSTEXPR typename sprout::container_traits<sscrisk::cel::array<T, N> >::iterator
} range_begin(sscrisk::cel::array<T, N>& cont) {
template<typename T, std::size_t N> return typename sprout::container_traits<sscrisk::cel::array<T, N> >::iterator(cont, 0);
inline SPROUT_CONSTEXPR typename sprout::container_traits<sscrisk::cel::array<T, N> >::const_iterator }
range_begin(sscrisk::cel::array<T, N> const& cont) { static SPROUT_CONSTEXPR typename sprout::container_traits<sscrisk::cel::array<T, N> const>::iterator
return typename sprout::container_traits<sscrisk::cel::array<T, N> >::const_iterator(cont, 0); range_begin(sscrisk::cel::array<T, N> const& cont) {
} return typename sprout::container_traits<sscrisk::cel::array<T, N> const>::iterator(cont, 0);
}
// static SPROUT_CONSTEXPR typename sprout::container_traits<sscrisk::cel::array<T, N> >::iterator
// range_end range_end(sscrisk::cel::array<T, N>& cont) {
// return typename sprout::container_traits<sscrisk::cel::array<T, N> >::iterator(cont, cont.size());
template<typename T, std::size_t N> }
inline typename sprout::container_traits<sscrisk::cel::array<T, N> >::iterator static SPROUT_CONSTEXPR typename sprout::container_traits<sscrisk::cel::array<T, N> const>::iterator
range_end(sscrisk::cel::array<T, N>& cont) { range_end(sscrisk::cel::array<T, N> const& cont) {
return typename sprout::container_traits<sscrisk::cel::array<T, N> >::iterator(cont, cont.size()); return typename sprout::container_traits<sscrisk::cel::array<T, N> const>::iterator(cont, cont.size());
} }
template<typename T, std::size_t N> };
inline SPROUT_CONSTEXPR typename sprout::container_traits<sscrisk::cel::array<T, N> >::const_iterator
range_end(sscrisk::cel::array<T, N> const& cont) {
return typename sprout::container_traits<sscrisk::cel::array<T, N> >::const_iterator(cont, cont.size());
}
} // namespace sprout } // namespace sprout
#endif #endif

View file

@ -23,36 +23,31 @@ namespace sprout {
typedef sprout::index_iterator<std::array<T, N>&, true> iterator; typedef sprout::index_iterator<std::array<T, N>&, true> iterator;
typedef sprout::index_iterator<std::array<T, N> const&, true> const_iterator; typedef sprout::index_iterator<std::array<T, N> const&, true> const_iterator;
}; };
} // namespace sprout
namespace sprout {
// //
// range_begin // container_range_traits
// //
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline typename sprout::container_traits<std::array<T, N> >::iterator struct container_range_traits<std::array<T, N> > {
range_begin(std::array<T, N>& cont) { public:
return typename sprout::container_traits<std::array<T, N> >::iterator(cont, 0); static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::iterator
} range_begin(std::array<T, N>& cont) {
template<typename T, std::size_t N> return typename sprout::container_traits<std::array<T, N> >::iterator(cont, 0);
inline SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::const_iterator }
range_begin(std::array<T, N> const& cont) { static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> const>::iterator
return typename sprout::container_traits<std::array<T, N> >::const_iterator(cont, 0); range_begin(std::array<T, N> const& cont) {
} return typename sprout::container_traits<std::array<T, N> const>::iterator(cont, 0);
}
// static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::iterator
// range_end range_end(std::array<T, N>& cont) {
// return typename sprout::container_traits<std::array<T, N> >::iterator(cont, cont.size());
template<typename T, std::size_t N> }
inline typename sprout::container_traits<std::array<T, N> >::iterator static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> const>::iterator
range_end(std::array<T, N>& cont) { range_end(std::array<T, N> const& cont) {
return typename sprout::container_traits<std::array<T, N> >::iterator(cont, cont.size()); return typename sprout::container_traits<std::array<T, N> const>::iterator(cont, cont.size());
} }
template<typename T, std::size_t N> };
inline SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::const_iterator
range_end(std::array<T, N> const& cont) {
return typename sprout::container_traits<std::array<T, N> >::const_iterator(cont, cont.size());
}
} // namespace sprout } // namespace sprout
#endif #endif

View file

@ -3,6 +3,7 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/container/container_traits.hpp> #include <sprout/container/container_traits.hpp>
#include <sprout/container/container_range_traits.hpp>
#include <sprout/container/container_construct_traits.hpp> #include <sprout/container/container_construct_traits.hpp>
#include <sprout/container/container_transform_traits.hpp> #include <sprout/container/container_transform_traits.hpp>
#include <sprout/container/container_fitness_traits.hpp> #include <sprout/container/container_fitness_traits.hpp>

View file

@ -5,7 +5,7 @@
#include <cstdint> #include <cstdint>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/math/floor.hpp> #include <sprout/math/floor.hpp>
#include <sprout/utility/value_holder/value_holder.hpp> #include <sprout/utility/value_holder.hpp>
#include <sprout/darkroom/materials/interpolation.hpp> #include <sprout/darkroom/materials/interpolation.hpp>
namespace sprout { namespace sprout {

View file

@ -3,7 +3,7 @@
#include <type_traits> #include <type_traits>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/array/array.hpp> #include <sprout/array.hpp>
#include <sprout/tuple/tuple.hpp> #include <sprout/tuple/tuple.hpp>
#include <sprout/tuple/functions.hpp> #include <sprout/tuple/functions.hpp>
#include <sprout/darkroom/access/access.hpp> #include <sprout/darkroom/access/access.hpp>

View file

@ -172,7 +172,7 @@ namespace sprout {
ray, ray,
det_sq > 0, det_sq > 0,
b, b,
sprout::sqrt(det_sq) det_sq > 0 ? sprout::sqrt(det_sq) : unit_type(0)
) )
); );
} }

View file

@ -4,7 +4,7 @@
#include <cstddef> #include <cstddef>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/index_tuple/metafunction.hpp> #include <sprout/index_tuple/metafunction.hpp>
#include <sprout/array/array.hpp> #include <sprout/array.hpp>
#include <sprout/container/traits.hpp> #include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp> #include <sprout/container/functions.hpp>
#include <sprout/container/indexes.hpp> #include <sprout/container/indexes.hpp>

View file

@ -3,7 +3,7 @@
#include <cstddef> #include <cstddef>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/array/array.hpp> #include <sprout/array.hpp>
#include <sprout/darkroom/access/access.hpp> #include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/colors/rgb.hpp> #include <sprout/darkroom/colors/rgb.hpp>

View file

@ -415,7 +415,7 @@ namespace sprout {
typename enable_if_void<Res>::type = 0 typename enable_if_void<Res>::type = 0
) )
{ {
f_(sprout::detail::mu<BoundArgs>()(get<Indexes>(bound_args_), args)...); f_(sprout::detail::mu<BoundArgs>()(sprout::tuples::get<Indexes>(bound_args_), args)...);
} }
template<typename Res, typename... Args, sprout::index_t... Indexes> template<typename Res, typename... Args, sprout::index_t... Indexes>
SPROUT_CONSTEXPR Result call( SPROUT_CONSTEXPR Result call(

View file

@ -9,5 +9,6 @@
#include <sprout/functional/hash/hash_combine.hpp> #include <sprout/functional/hash/hash_combine.hpp>
#include <sprout/functional/hash/hash_values.hpp> #include <sprout/functional/hash/hash_values.hpp>
#include <sprout/functional/hash/hash_range.hpp> #include <sprout/functional/hash/hash_range.hpp>
#include <sprout/functional/hash/hash_value_traits.hpp>
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HPP #endif // #ifndef SPROUT_FUNCTIONAL_HASH_HPP

View file

@ -15,7 +15,14 @@ namespace sprout {
// to_hash // to_hash
// //
template<typename T> template<typename T>
SPROUT_CONSTEXPR std::size_t to_hash(T const& v); SPROUT_CONSTEXPR std::size_t to_hash(T&& v);
//
// hash_value
//
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
hash_value(T const& v);
// //
// hash_combine // hash_combine
@ -42,6 +49,12 @@ namespace sprout {
SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, InputRange const& rng); SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, InputRange const& rng);
template<typename InputRange> template<typename InputRange>
SPROUT_CONSTEXPR std::size_t hash_range(InputRange const& rng); SPROUT_CONSTEXPR std::size_t hash_range(InputRange const& rng);
//
// hash_value_traits
//
template<typename T>
struct hash_value_traits;
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_FWD_HPP #endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_FWD_HPP

View file

@ -2,150 +2,20 @@
#define SPROUT_FUNCTIONAL_HASH_HASH_VALUE_HPP #define SPROUT_FUNCTIONAL_HASH_HASH_VALUE_HPP
#include <cstddef> #include <cstddef>
#include <limits>
#include <type_traits>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/functional/hash/hash_fwd.hpp> #include <sprout/functional/hash/hash_fwd.hpp>
#include <sprout/functional/hash/detail/hash_float.hpp>
namespace sprout { namespace sprout {
namespace hash_detail {
template <typename T>
struct is_basic_number
: public std::integral_constant<
bool,
std::is_integral<T>::value
&& (sizeof(T) <= sizeof(std::size_t))
>
{};
template <typename T>
struct is_long_number
: public std::integral_constant<
bool,
std::is_integral<T>::value
&& (sizeof(T) > sizeof(std::size_t))
&& std::is_signed<T>::value
>
{};
template <typename T>
struct is_ulong_number
: public std::integral_constant<
bool,
std::is_integral<T>::value
&& (sizeof(T) > sizeof(std::size_t))
&& std::is_unsigned<T>::value
>
{};
template<typename T>
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<std::size_t>((positive >> i) + (seed << 6) + (seed >> 2)),
positive,
i - std::numeric_limits<std::size_t>::digits
)
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
;
}
template<typename T>
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<std::size_t>::digits);
}
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
hash_value_signed(T val) {
return sprout::hash_detail::hash_value_signed_1(
val,
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
0,
val < 0 ? -1 - val : val
);
}
template<typename T>
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<std::size_t>((val >> i) + (seed << 6) + (seed >> 2)),
i - std::numeric_limits<std::size_t>::digits
)
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
;
}
template<typename T>
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<std::size_t>::digits);
}
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
hash_value_unsigned(T val) {
return sprout::hash_detail::hash_value_unsigned_1(
val,
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
0
);
}
inline std::size_t
hash_value_pointer_1(std::size_t x) {
return x + (x >> 3);
}
template<typename T>
std::size_t
hash_value_pointer(T const* v) {
return sprout::hash_detail::hash_value_pointer_1(static_cast<std::size_t>(reinterpret_cast<std::ptrdiff_t>(v)));
}
} // namespace hash_detail
// //
// hash_value // hash_value
// //
template<typename T> template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_basic_number<T>::value, std::size_t>::type
hash_value(T v) {
return static_cast<std::size_t>(v);
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_long_number<T>::value, std::size_t>::type
hash_value(T v) {
return sprout::hash_detail::hash_value_signed(v);
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_ulong_number<T>::value, std::size_t>::type
hash_value(T v) {
return sprout::hash_detail::hash_value_unsigned(v);
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_enum<T>::value, std::size_t>::type
hash_value(T v) {
return sprout::hash_value(static_cast<typename std::underlying_type<T>::type>(v));
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, std::size_t>::type
hash_value(T v) {
return sprout::detail::float_hash_value(v);
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_pointer<typename std::remove_reference<T>::type>::value, std::size_t>::type
hash_value(T&& v) {
return sprout::hash_detail::hash_value_pointer(v);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR std::size_t inline SPROUT_CONSTEXPR std::size_t
hash_value(T const (&v)[N]) { hash_value(T const& v) {
return sprout::hash_range(v); return sprout::hash_value_traits<T>::hash_value(v);
} }
} // namespace sprout } // namespace sprout
#include <sprout/functional/hash/hash_range.hpp> #include <sprout/functional/hash/hash_value_traits.hpp>
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUE_HPP #endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUE_HPP

View file

@ -0,0 +1,181 @@
#ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUE_TRAITS_HPP
#define SPROUT_FUNCTIONAL_HASH_HASH_VALUE_TRAITS_HPP
#include <cstddef>
#include <limits>
#include <functional>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/functional/hash/hash_fwd.hpp>
#include <sprout/functional/hash/detail/hash_float.hpp>
namespace sprout {
namespace hash_detail {
template <typename T>
struct is_basic_number
: public std::integral_constant<
bool,
std::is_integral<T>::value
&& (sizeof(T) <= sizeof(std::size_t))
>
{};
template <typename T>
struct is_long_number
: public std::integral_constant<
bool,
std::is_integral<T>::value
&& (sizeof(T) > sizeof(std::size_t))
&& std::is_signed<T>::value
>
{};
template <typename T>
struct is_ulong_number
: public std::integral_constant<
bool,
std::is_integral<T>::value
&& (sizeof(T) > sizeof(std::size_t))
&& std::is_unsigned<T>::value
>
{};
template<typename T>
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<std::size_t>((positive >> i) + (seed << 6) + (seed >> 2)),
positive,
i - std::numeric_limits<std::size_t>::digits
)
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
;
}
template<typename T>
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<std::size_t>::digits);
}
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
hash_value_signed(T val) {
return sprout::hash_detail::hash_value_signed_1(
val,
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
0,
val < 0 ? -1 - val : val
);
}
template<typename T>
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<std::size_t>((val >> i) + (seed << 6) + (seed >> 2)),
i - std::numeric_limits<std::size_t>::digits
)
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
;
}
template<typename T>
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<std::size_t>::digits);
}
template<typename T>
inline SPROUT_CONSTEXPR std::size_t
hash_value_unsigned(T val) {
return sprout::hash_detail::hash_value_unsigned_1(
val,
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
0
);
}
inline std::size_t
hash_value_pointer_1(std::size_t x) {
return x + (x >> 3);
}
template<typename T>
std::size_t
hash_value_pointer(T const* v) {
return sprout::hash_detail::hash_value_pointer_1(static_cast<std::size_t>(reinterpret_cast<std::ptrdiff_t>(v)));
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_basic_number<T>::value, std::size_t>::type
hash_value_impl(T v) {
return static_cast<std::size_t>(v);
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_long_number<T>::value, std::size_t>::type
hash_value_impl(T v) {
return sprout::hash_detail::hash_value_signed(v);
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_ulong_number<T>::value, std::size_t>::type
hash_value_impl(T v) {
return sprout::hash_detail::hash_value_unsigned(v);
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_enum<T>::value, std::size_t>::type
hash_value_impl(T v) {
return sprout::hash_detail::hash_value_impl(static_cast<typename std::underlying_type<T>::type>(v));
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_floating_point<T>::value, std::size_t>::type
hash_value_impl(T v) {
return sprout::detail::float_hash_value(v);
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_pointer<typename std::remove_reference<T>::type>::value, std::size_t>::type
hash_value_impl(T&& v) {
return sprout::hash_detail::hash_value_pointer(v);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR std::size_t
hash_value_impl(T const (&v)[N]) {
return sprout::hash_range(v);
}
template<typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<
!std::is_arithmetic<T>::value && !std::is_enum<T>::value && !std::is_pointer<T>::value,
std::size_t
>::type
hash_value_impl(T const &v) {
return std::hash<typename std::decay<T>::type>()(v);
}
} // namespace hash_detail
//
// hash_value_traits
//
template<typename T>
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<typename T>
struct hash_value_traits<T const>
: public sprout::hash_value_traits<T>
{};
template<typename T>
struct hash_value_traits<T volatile>
: public sprout::hash_value_traits<T>
{};
template<typename T>
struct hash_value_traits<T const volatile>
: public sprout::hash_value_traits<T>
{};
} // namespace sprout
#include <sprout/functional/hash/hash_range.hpp>
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUE_TRAITS_HPP

View file

@ -4,17 +4,21 @@
#include <cstddef> #include <cstddef>
#include <sscrisk/cel/array.hpp> #include <sscrisk/cel/array.hpp>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/functional/hash.hpp> #include <sprout/functional/hash/hash_value_traits.hpp>
#include <sprout/functional/hash/hash_range.hpp>
namespace sprout { namespace sprout {
// //
// hash_value // hash_value_traits
// //
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR std::size_t struct hash_value_traits<sscrisk::cel::array<T, N> > {
hash_value(sscrisk::cel::array<T, N> const& v) { public:
return sprout::hash_range(v); static SPROUT_CONSTEXPR std::size_t
} hash_value(sscrisk::cel::array<T, N> const& v) {
return sprout::hash_range(v);
}
};
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_ARRAY_HPP #endif // #ifndef SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_ARRAY_HPP

View file

@ -4,17 +4,21 @@
#include <cstddef> #include <cstddef>
#include <sscrisk/cel/utility.hpp> #include <sscrisk/cel/utility.hpp>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/functional/hash.hpp> #include <sprout/functional/hash/hash_value_traits.hpp>
#include <sprout/functional/hash/hash_values.hpp>
namespace sprout { namespace sprout {
// //
// hash_value // hash_value_traits
// //
template<typename T1, typename T2> template<typename T1, typename T2>
inline SPROUT_CONSTEXPR std::size_t struct hash_value_traits<sscrisk::cel::pair<T1, T2> > {
hash_value(sscrisk::cel::pair<T1, T2> const& v) { public:
return sprout::hash_values(v.first, v.second); static SPROUT_CONSTEXPR std::size_t
} hash_value(sscrisk::cel::pair<T1, T2> const& v) {
return sprout::hash_values(v.first, v.second);
}
};
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_UTILITY_HPP #endif // #ifndef SPROUT_FUNCTIONAL_HASH_SSCRISK_CEL_UTILITY_HPP

View file

@ -4,17 +4,21 @@
#include <cstddef> #include <cstddef>
#include <array> #include <array>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/functional/hash.hpp> #include <sprout/functional/hash/hash_value_traits.hpp>
#include <sprout/functional/hash/hash_range.hpp>
namespace sprout { namespace sprout {
// //
// hash_value // hash_value_traits
// //
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR std::size_t struct hash_value_traits<std::array<T, N> > {
hash_value(std::array<T, N> const& v) { public:
return sprout::hash_range(v); static SPROUT_CONSTEXPR std::size_t
} hash_value(std::array<T, N> const& v) {
return sprout::hash_range(v);
}
};
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_STD_ARRAY_HPP #endif // #ifndef SPROUT_FUNCTIONAL_HASH_STD_ARRAY_HPP

View file

@ -4,17 +4,21 @@
#include <cstddef> #include <cstddef>
#include <utility> #include <utility>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/functional/hash.hpp> #include <sprout/functional/hash/hash_value_traits.hpp>
#include <sprout/functional/hash/hash_values.hpp>
namespace sprout { namespace sprout {
// //
// hash_value // hash_value_traits
// //
template<typename T1, typename T2> template<typename T1, typename T2>
inline SPROUT_CONSTEXPR std::size_t struct hash_value_traits<std::pair<T1, T2> > {
hash_value(std::pair<T1, T2> const& v) { public:
return sprout::hash_values(v.first, v.second); static SPROUT_CONSTEXPR std::size_t
} hash_value(std::pair<T1, T2> const& v) {
return sprout::hash_values(v.first, v.second);
}
};
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_STD_UTILITY_HPP #endif // #ifndef SPROUT_FUNCTIONAL_HASH_STD_UTILITY_HPP

View file

@ -2,144 +2,28 @@
#define SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP #define SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP
#include <cstddef> #include <cstddef>
#include <utility>
#include <type_traits>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/functional/hash/hash_fwd.hpp> #include <sprout/functional/hash/hash_fwd.hpp>
#include <sprout/functional/hash/hash_value.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/adl/not_found.hpp> #include <sprout/adl/not_found.hpp>
namespace sprout_adl { namespace sprout_adl {
sprout::not_found_via_adl hash_value(...); sprout::not_found_via_adl hash_value(...);
} // namespace sprout_adl } // namespace sprout_adl
namespace sprout_hash_detail {
using sprout::hash_value;
using sprout_adl::hash_value;
template<typename T>
struct has_adl_hash_value_test {
public:
template<
typename U = T,
typename sprout::enabler_if<
sprout::is_found_via_adl<decltype(hash_value(std::declval<U>()))>::value
>::type = sprout::enabler
>
static std::true_type test(int);
static std::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = decltype(sprout_hash_detail::has_adl_hash_value_test<T>::test(0))>
struct has_adl_hash_value
: public Base_
{};
#else
template<typename T>
struct has_adl_hash_value
: public decltype(sprout_hash_detail::has_adl_hash_value_test<T>::test(0))
{};
#endif
template<typename T, typename Enable = void>
struct select_adl_hash_value;
template<typename T>
struct select_adl_hash_value<
T,
typename std::enable_if<
sprout_hash_detail::has_adl_hash_value<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct select_adl_hash_value<
T,
typename std::enable_if<!(
sprout_hash_detail::has_adl_hash_value<T>::value
)>::type
>
: public std::false_type
{};
template<typename T, typename Enable = void>
struct select_std_hash;
template<typename T>
struct select_std_hash<
T,
typename std::enable_if<
!sprout_hash_detail::has_adl_hash_value<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct select_std_hash<
T,
typename std::enable_if<!(
!sprout_hash_detail::has_adl_hash_value<T>::value
)>::type
>
: public std::false_type
{};
template<typename T, typename = void>
struct noexcept_to_hash;
template<typename T>
struct noexcept_to_hash<T, typename std::enable_if<sprout_hash_detail::select_adl_hash_value<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(hash_value(std::declval<T>()), false)>
{};
template<typename T>
struct noexcept_to_hash<T, typename std::enable_if<sprout_hash_detail::select_std_hash<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::hash<typename std::decay<T>::type>()(std::declval<T>()), false)>
{};
template<typename T, typename = void>
struct to_hash_result;
template<typename T>
struct to_hash_result<T, typename std::enable_if<sprout_hash_detail::select_adl_hash_value<T>::value>::type> {
public:
typedef decltype(hash_value(std::declval<T>())) type;
};
template<typename T>
struct to_hash_result<T, typename std::enable_if<sprout_hash_detail::select_std_hash<T>::value>::type> {
public:
typedef decltype(std::hash<typename std::decay<T>::type>()(std::declval<T>())) type;
};
template<
typename T,
typename sprout::enabler_if<sprout_hash_detail::select_adl_hash_value<T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout_hash_detail::to_hash_result<T>::type
to_hash_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_hash_detail::noexcept_to_hash<T>::value))
{
return hash_value(sprout::forward<T>(t));
}
template<
typename T,
typename sprout::enabler_if<sprout_hash_detail::select_std_hash<T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout_hash_detail::to_hash_result<T>::type
to_hash_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_hash_detail::noexcept_to_hash<T>::value))
{
return std::hash<typename std::decay<T>::type>()(sprout::forward<T>(t));
}
} // namespace sprout_hash_detail
namespace sprout { namespace sprout {
// //
// to_hash // to_hash
// //
template<typename T> template<typename T>
inline SPROUT_CONSTEXPR std::size_t inline SPROUT_CONSTEXPR std::size_t
to_hash(T const& v) { to_hash(T&& v) {
return sprout_hash_detail::to_hash_impl(v); using sprout::hash_value;
using sprout_adl::hash_value;
return hash_value(sprout::forward<T>(v));
} }
} // namespace sprout } // namespace sprout
#include <sprout/functional/hash/hash_value.hpp>
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP #endif // #ifndef SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP

View file

@ -2,5 +2,6 @@
#define SPROUT_GENERATOR_HPP #define SPROUT_GENERATOR_HPP
#include <sprout/generator/functions.hpp> #include <sprout/generator/functions.hpp>
#include <sprout/generator/generator_access_traits.hpp>
#endif // #ifndef SPROUT_GENERATOR_HPP #endif // #ifndef SPROUT_GENERATOR_HPP

View file

@ -1,6 +1,7 @@
#ifndef SPROUT_GENERATOR_FUNCTIONS_HPP #ifndef SPROUT_GENERATOR_FUNCTIONS_HPP
#define SPROUT_GENERATOR_FUNCTIONS_HPP #define SPROUT_GENERATOR_FUNCTIONS_HPP
#include <sprout/config.hpp>
#include <sprout/generator/generated_value.hpp> #include <sprout/generator/generated_value.hpp>
#include <sprout/generator/next_generator.hpp> #include <sprout/generator/next_generator.hpp>

View file

@ -3,9 +3,9 @@
#include <utility> #include <utility>
#include <type_traits> #include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/generator/generator_access_traits.hpp>
#include <sprout/tuple/tuple/get.hpp>
#include <sprout/adl/not_found.hpp> #include <sprout/adl/not_found.hpp>
namespace sprout_adl { namespace sprout_adl {
@ -13,208 +13,56 @@ namespace sprout_adl {
} // namespace sprout_adl } // namespace sprout_adl
namespace sprout_generator_detail { namespace sprout_generator_detail {
using sprout::tuples::get;
using sprout_adl::generated_value; using sprout_adl::generated_value;
template<typename T> template<typename Gen>
struct has_adl_generated_value_test { inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::generated_value(std::declval<Gen&>()))
public: generated_value(Gen& gen)
template< SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits<Gen>::generated_value(std::declval<Gen&>())))
typename U = T, {
typename sprout::enabler_if< return sprout::generators::generator_access_traits<Gen>::generated_value(gen);
sprout::is_found_via_adl<decltype(generated_value(std::declval<U>()))>::value }
>::type = sprout::enabler template<typename Gen>
> inline SPROUT_CONSTEXPR typename std::enable_if<
static std::true_type test(int); !std::is_const<Gen>::value && !std::is_volatile<Gen>::value && !std::is_reference<Gen>::value,
static std::false_type test(...); decltype(sprout::generators::generator_access_traits<typename std::remove_reference<Gen>::type>::generated_value(std::declval<Gen&&>()))
}; >::type
#if defined(_MSC_VER) generated_value(Gen&& gen)
template<typename T, typename Base_ = decltype(sprout_generator_detail::has_adl_generated_value_test<T>::test(0))> SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits<typename std::remove_reference<Gen>::type>::generated_value(std::declval<Gen&&>())))
struct has_adl_generated_value {
: public Base_ return sprout::generators::generator_access_traits<Gen>::generated_value(gen);
{}; }
#else template<typename Gen>
template<typename T> inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen const>::generated_value(std::declval<Gen const&>()))
struct has_adl_generated_value generated_value(Gen const& gen)
: public decltype(sprout_generator_detail::has_adl_generated_value_test<T>::test(0)) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits<Gen const>::generated_value(std::declval<Gen const&>())))
{}; {
#endif return sprout::generators::generator_access_traits<Gen const>::generated_value(gen);
}
template<typename T>
struct has_mem_generated_value_test {
public:
template<
typename U = T,
typename = decltype(std::declval<U>().generated_value())
>
static std::true_type test(int);
static std::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = decltype(sprout_generator_detail::has_mem_generated_value_test<T>::test(0))>
struct has_mem_generated_value
: public Base_
{};
#else
template<typename T>
struct has_mem_generated_value
: public decltype(sprout_generator_detail::has_mem_generated_value_test<T>::test(0))
{};
#endif
template<typename T>
struct has_get_generated_value_test {
public:
template<
typename U = T,
typename = decltype(get<0>(std::declval<U>()))
>
static std::true_type test(int);
static std::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = decltype(sprout_generator_detail::has_get_generated_value_test<T>::test(0))>
struct has_get_generated_value
: public Base_
{};
#else
template<typename T>
struct has_get_generated_value
: public decltype(sprout_generator_detail::has_get_generated_value_test<T>::test(0))
{};
#endif
template<typename T, typename Enable = void>
struct select_adl_generated_value;
template<typename T>
struct select_adl_generated_value<
T,
typename std::enable_if<
sprout_generator_detail::has_adl_generated_value<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct select_adl_generated_value<
T,
typename std::enable_if<!(
sprout_generator_detail::has_adl_generated_value<T>::value
)>::type
>
: public std::false_type
{};
template<typename T, typename Enable = void>
struct select_mem_generated_value;
template<typename T>
struct select_mem_generated_value<
T,
typename std::enable_if<
sprout_generator_detail::has_mem_generated_value<T>::value
&& !sprout_generator_detail::has_adl_generated_value<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct select_mem_generated_value<
T,
typename std::enable_if<!(
sprout_generator_detail::has_mem_generated_value<T>::value
&& !sprout_generator_detail::has_adl_generated_value<T>::value
)>::type
>
: public std::false_type
{};
template<typename T, typename Enable = void>
struct select_get_generated_value;
template<typename T>
struct select_get_generated_value<
T,
typename std::enable_if<
sprout_generator_detail::has_get_generated_value<T>::value
&& !sprout_generator_detail::has_adl_generated_value<T>::value
&& !sprout_generator_detail::has_mem_generated_value<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct select_get_generated_value<
T,
typename std::enable_if<!(
sprout_generator_detail::has_get_generated_value<T>::value
&& !sprout_generator_detail::has_adl_generated_value<T>::value
&& !sprout_generator_detail::has_mem_generated_value<T>::value
)>::type
>
: public std::false_type
{};
template<typename T, typename = void>
struct noexcept_generated_value;
template<typename T>
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(generated_value(std::declval<T>()), false)>
{};
template<typename T>
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_mem_generated_value<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::declval<T>().generated_value(), false)>
{};
template<typename T>
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_get_generated_value<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(get<0>(std::declval<T>()), false)>
{};
template<typename T, typename = void>
struct generated_value_result;
template<typename T>
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type> {
public:
typedef decltype(generated_value(std::declval<T>())) type;
};
template<typename T>
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_mem_generated_value<T>::value>::type> {
public:
typedef decltype(std::declval<T>().generated_value()) type;
};
template<typename T>
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_get_generated_value<T>::value>::type> {
public:
typedef decltype(get<0>(std::declval<T>())) type;
};
template< template<typename Gen>
typename T, inline SPROUT_CONSTEXPR decltype(generated_value(std::declval<Gen&>()))
typename sprout::enabler_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type = sprout::enabler call_generated_value(Gen& gen)
> SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(generated_value(std::declval<Gen&>())))
inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type
generated_value_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value))
{ {
return generated_value(sprout::forward<T>(t)); return generated_value(gen);
} }
template< template<typename Gen>
typename T, inline SPROUT_CONSTEXPR typename std::enable_if<
typename sprout::enabler_if<sprout_generator_detail::select_mem_generated_value<T>::value>::type = sprout::enabler !std::is_const<Gen>::value && !std::is_volatile<Gen>::value && !std::is_reference<Gen>::value,
> decltype(generated_value(std::declval<Gen&&>()))
inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type >::type
generated_value_impl(T&& t) call_generated_value(Gen&& gen)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value)) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(generated_value(std::declval<Gen&&>())))
{ {
return sprout::forward<T>(t).generated_value(); return generated_value(gen);
} }
template< template<typename Gen>
typename T, inline SPROUT_CONSTEXPR decltype(generated_value(std::declval<Gen const&>()))
typename sprout::enabler_if<sprout_generator_detail::select_get_generated_value<T>::value>::type = sprout::enabler call_generated_value(Gen const& gen)
> SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(generated_value(std::declval<Gen const&>())))
inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type
generated_value_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value))
{ {
return get<0>(sprout::forward<T>(t)); return generated_value(gen);
} }
} // namespace sprout_generator_detail } // namespace sprout_generator_detail
@ -224,11 +72,11 @@ namespace sprout {
// generated_value // generated_value
// //
template<typename T> template<typename T>
inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type inline SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_generated_value(std::declval<T>()))
generated_value(T&& t) generated_value(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value)) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_generator_detail::call_generated_value(std::declval<T>())))
{ {
return sprout_generator_detail::generated_value_impl(sprout::forward<T>(t)); return sprout_generator_detail::call_generated_value(sprout::forward<T>(t));
} }
} // namespace generators } // namespace generators

View file

@ -0,0 +1,192 @@
#ifndef SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP
#define SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP
#include <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
namespace sprout {
namespace generators {
namespace detail {
template<typename T>
struct has_mem_generated_value_test {
public:
template<
typename U = T,
typename = decltype(std::declval<U>().generated_value())
>
static std::true_type test(int);
static std::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = decltype(sprout::generators::detail::has_mem_generated_value_test<T>::test(0))>
struct has_mem_generated_value
: public Base_
{};
#else
template<typename T>
struct has_mem_generated_value
: public decltype(sprout::generators::detail::has_mem_generated_value_test<T>::test(0))
{};
#endif
template<typename Gen, typename = void>
struct generator_access_traits_generated_value_impl;
template<typename Gen>
struct generator_access_traits_generated_value_impl<
Gen,
typename std::enable_if<sprout::generators::detail::has_mem_generated_value<Gen>::value>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&>().generated_value())
generated_value(Gen& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<Gen&>().generated_value()))
{
return t.generated_value();
}
static SPROUT_CONSTEXPR decltype(std::declval<Gen&&>().generated_value())
generated_value(Gen&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<Gen&&>().generated_value()))
{
return t.generated_value();
}
static SPROUT_CONSTEXPR decltype(std::declval<Gen const&>().generated_value())
generated_value(Gen const& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<Gen const&>().generated_value()))
{
return t.generated_value();
}
};
template<typename Gen>
struct generator_access_traits_generated_value_impl<
Gen,
typename std::enable_if<!sprout::generators::detail::has_mem_generated_value<Gen>::value>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen&>()))
generated_value(Gen& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<0>(std::declval<Gen&>())))
{
return sprout::tuples::get<0>(t);
}
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen&&>()))
generated_value(Gen&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<0>(std::declval<Gen&>())))
{
return sprout::tuples::get<0>(t);
}
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen const&>()))
generated_value(Gen const& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<0>(std::declval<Gen const&>())))
{
return sprout::tuples::get<0>(t);
}
};
template<typename T>
struct has_mem_next_generator_test {
public:
template<
typename U = T,
typename = decltype(std::declval<U>().next_generator())
>
static std::true_type test(int);
static std::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = decltype(sprout::generators::detail::has_mem_next_generator_test<T>::test(0))>
struct has_mem_next_generator
: public Base_
{};
#else
template<typename T>
struct has_mem_next_generator
: public decltype(sprout::generators::detail::has_mem_next_generator_test<T>::test(0))
{};
#endif
template<typename Gen, typename = void>
struct generator_access_traits_next_generator_impl;
template<typename Gen>
struct generator_access_traits_next_generator_impl<
Gen,
typename std::enable_if<sprout::generators::detail::has_mem_next_generator<Gen>::value>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&>().next_generator())
next_generator(Gen& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<Gen&>().next_generator()))
{
return t.next_generator();
}
static SPROUT_CONSTEXPR decltype(std::declval<Gen&&>().next_generator())
next_generator(Gen&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<Gen&&>().next_generator()))
{
return t.next_generator();
}
static SPROUT_CONSTEXPR decltype(std::declval<Gen const&>().next_generator())
next_generator(Gen const& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<Gen const&>().next_generator()))
{
return t.next_generator();
}
};
template<typename Gen>
struct generator_access_traits_next_generator_impl<
Gen,
typename std::enable_if<!sprout::generators::detail::has_mem_next_generator<Gen>::value>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen&>()))
next_generator(Gen& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<1>(std::declval<Gen&>())))
{
return sprout::tuples::get<1>(t);
}
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen&&>()))
next_generator(Gen&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<1>(std::declval<Gen&>())))
{
return sprout::tuples::get<1>(t);
}
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen const&>()))
next_generator(Gen const& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::get<1>(std::declval<Gen const&>())))
{
return sprout::tuples::get<1>(t);
}
};
} // namespace detail
//
// generator_access_traits
//
template<typename Gen>
struct generator_access_traits
: public sprout::generators::detail::generator_access_traits_generated_value_impl<Gen>
, public sprout::generators::detail::generator_access_traits_next_generator_impl<Gen>
{};
template<typename Gen>
struct generator_access_traits<Gen const> {
public:
static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::generated_value(std::declval<Gen const&>()))
generated_value(Gen const& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits<Gen>::generated_value(std::declval<Gen const&>())))
{
return sprout::generators::generator_access_traits<Gen>::generated_value(t);
}
static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::next_generator(std::declval<Gen const&>()))
next_generator(Gen const& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits<Gen>::next_generator(std::declval<Gen const&>())))
{
return sprout::generators::generator_access_traits<Gen>::next_generator(t);
}
};
} // namespace generators
using sprout::generators::generator_access_traits;
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP

View file

@ -3,9 +3,9 @@
#include <utility> #include <utility>
#include <type_traits> #include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/generator/generator_access_traits.hpp>
#include <sprout/tuple/tuple/get.hpp>
#include <sprout/adl/not_found.hpp> #include <sprout/adl/not_found.hpp>
namespace sprout_adl { namespace sprout_adl {
@ -13,208 +13,56 @@ namespace sprout_adl {
} // namespace sprout_adl } // namespace sprout_adl
namespace sprout_generator_detail { namespace sprout_generator_detail {
using sprout::tuples::get;
using sprout_adl::next_generator; using sprout_adl::next_generator;
template<typename T> template<typename Gen>
struct has_adl_next_generator_test { inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::next_generator(std::declval<Gen&>()))
public: next_generator(Gen& gen)
template< SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits<Gen>::next_generator(std::declval<Gen&>())))
typename U = T, {
typename sprout::enabler_if< return sprout::generators::generator_access_traits<Gen>::next_generator(gen);
sprout::is_found_via_adl<decltype(next_generator(std::declval<U>()))>::value }
>::type = sprout::enabler template<typename Gen>
> inline SPROUT_CONSTEXPR typename std::enable_if<
static std::true_type test(int); !std::is_const<Gen>::value && !std::is_volatile<Gen>::value && !std::is_reference<Gen>::value,
static std::false_type test(...); decltype(sprout::generators::generator_access_traits<typename std::remove_reference<Gen>::type>::next_generator(std::declval<Gen&&>()))
}; >::type
#if defined(_MSC_VER) next_generator(Gen&& gen)
template<typename T, typename Base_ = decltype(sprout_generator_detail::has_adl_next_generator_test<T>::test(0))> SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits<typename std::remove_reference<Gen>::type>::next_generator(std::declval<Gen&&>())))
struct has_adl_next_generator {
: public Base_ return sprout::generators::generator_access_traits<Gen>::next_generator(gen);
{}; }
#else template<typename Gen>
template<typename T> inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen const>::next_generator(std::declval<Gen const&>()))
struct has_adl_next_generator next_generator(Gen const& gen)
: public decltype(sprout_generator_detail::has_adl_next_generator_test<T>::test(0)) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::generators::generator_access_traits<Gen const>::next_generator(std::declval<Gen const&>())))
{}; {
#endif return sprout::generators::generator_access_traits<Gen const>::next_generator(gen);
}
template<typename T>
struct has_mem_next_generator_test {
public:
template<
typename U = T,
typename = decltype(std::declval<U>().next_generator())
>
static std::true_type test(int);
static std::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = decltype(sprout_generator_detail::has_mem_next_generator_test<T>::test(0))>
struct has_mem_next_generator
: public Base_
{};
#else
template<typename T>
struct has_mem_next_generator
: public decltype(sprout_generator_detail::has_mem_next_generator_test<T>::test(0))
{};
#endif
template<typename T>
struct has_get_next_generator_test {
public:
template<
typename U = T,
typename = decltype(get<1>(std::declval<U>()))
>
static std::true_type test(int);
static std::false_type test(...);
};
#if defined(_MSC_VER)
template<typename T, typename Base_ = decltype(sprout_generator_detail::has_get_next_generator_test<T>::test(0))>
struct has_get_next_generator
: public Base_
{};
#else
template<typename T>
struct has_get_next_generator
: public decltype(sprout_generator_detail::has_get_next_generator_test<T>::test(0))
{};
#endif
template<typename T, typename Enable = void>
struct select_adl_next_generator;
template<typename T>
struct select_adl_next_generator<
T,
typename std::enable_if<
sprout_generator_detail::has_adl_next_generator<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct select_adl_next_generator<
T,
typename std::enable_if<!(
sprout_generator_detail::has_adl_next_generator<T>::value
)>::type
>
: public std::false_type
{};
template<typename T, typename Enable = void>
struct select_mem_next_generator;
template<typename T>
struct select_mem_next_generator<
T,
typename std::enable_if<
sprout_generator_detail::has_mem_next_generator<T>::value
&& !sprout_generator_detail::has_adl_next_generator<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct select_mem_next_generator<
T,
typename std::enable_if<!(
sprout_generator_detail::has_mem_next_generator<T>::value
&& !sprout_generator_detail::has_adl_next_generator<T>::value
)>::type
>
: public std::false_type
{};
template<typename T, typename Enable = void>
struct select_get_next_generator;
template<typename T>
struct select_get_next_generator<
T,
typename std::enable_if<
sprout_generator_detail::has_get_next_generator<T>::value
&& !sprout_generator_detail::has_adl_next_generator<T>::value
&& !sprout_generator_detail::has_mem_next_generator<T>::value
>::type
>
: public std::true_type
{};
template<typename T>
struct select_get_next_generator<
T,
typename std::enable_if<!(
sprout_generator_detail::has_get_next_generator<T>::value
&& !sprout_generator_detail::has_adl_next_generator<T>::value
&& !sprout_generator_detail::has_mem_next_generator<T>::value
)>::type
>
: public std::false_type
{};
template<typename T, typename = void>
struct noexcept_next_generator;
template<typename T>
struct noexcept_next_generator<T, typename std::enable_if<sprout_generator_detail::select_adl_next_generator<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(next_generator(std::declval<T>()), false)>
{};
template<typename T>
struct noexcept_next_generator<T, typename std::enable_if<sprout_generator_detail::select_mem_next_generator<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::declval<T>().next_generator(), false)>
{};
template<typename T>
struct noexcept_next_generator<T, typename std::enable_if<sprout_generator_detail::select_get_next_generator<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(get<1>(std::declval<T>()), false)>
{};
template<typename T, typename = void>
struct next_generator_result;
template<typename T>
struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_adl_next_generator<T>::value>::type> {
public:
typedef decltype(next_generator(std::declval<T>())) type;
};
template<typename T>
struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_mem_next_generator<T>::value>::type> {
public:
typedef decltype(std::declval<T>().next_generator()) type;
};
template<typename T>
struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_get_next_generator<T>::value>::type> {
public:
typedef decltype(get<1>(std::declval<T>())) type;
};
template< template<typename Gen>
typename T, inline SPROUT_CONSTEXPR decltype(next_generator(std::declval<Gen&>()))
typename sprout::enabler_if<sprout_generator_detail::select_adl_next_generator<T>::value>::type = sprout::enabler call_next_generator(Gen& gen)
> SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(next_generator(std::declval<Gen&>())))
inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result<T>::type
next_generator_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator<T>::value))
{ {
return next_generator(sprout::forward<T>(t)); return next_generator(gen);
} }
template< template<typename Gen>
typename T, inline SPROUT_CONSTEXPR typename std::enable_if<
typename sprout::enabler_if<sprout_generator_detail::select_mem_next_generator<T>::value>::type = sprout::enabler !std::is_const<Gen>::value && !std::is_volatile<Gen>::value && !std::is_reference<Gen>::value,
> decltype(next_generator(std::declval<Gen&&>()))
inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result<T>::type >::type
next_generator_impl(T&& t) call_next_generator(Gen&& gen)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator<T>::value)) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(next_generator(std::declval<Gen&&>())))
{ {
return sprout::forward<T>(t).next_generator(); return next_generator(gen);
} }
template< template<typename Gen>
typename T, inline SPROUT_CONSTEXPR decltype(next_generator(std::declval<Gen const&>()))
typename sprout::enabler_if<sprout_generator_detail::select_get_next_generator<T>::value>::type = sprout::enabler call_next_generator(Gen const& gen)
> SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(next_generator(std::declval<Gen const&>())))
inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result<T>::type
next_generator_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator<T>::value))
{ {
return get<1>(sprout::forward<T>(t)); return next_generator(gen);
} }
} // namespace sprout_generator_detail } // namespace sprout_generator_detail
@ -224,11 +72,11 @@ namespace sprout {
// next_generator // next_generator
// //
template<typename T> template<typename T>
inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result<T>::type inline SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_next_generator(std::declval<T>()))
next_generator(T&& t) next_generator(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator<T>::value)) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_generator_detail::call_next_generator(std::declval<T>())))
{ {
return sprout_generator_detail::next_generator_impl(sprout::forward<T>(t)); return sprout_generator_detail::call_next_generator(sprout::forward<T>(t));
} }
} // namespace generators } // namespace generators

View file

@ -6,29 +6,36 @@
#include <sscrisk/cel/array.hpp> #include <sscrisk/cel/array.hpp>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/utility/move.hpp> #include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
#include <sprout/tuple/tuple/get.hpp> #include <sprout/tuple/tuple/get.hpp>
namespace sprout_adl { namespace sprout {
// namespace tuples {
// tuple_get //
// // tuple_access_traits
template<std::size_t I, typename T, std::size_t N> //
inline SPROUT_CONSTEXPR T& template<typename T, std::size_t N>
tuple_get(sscrisk::cel::array<T, N>& t) SPROUT_NOEXCEPT { struct tuple_access_traits<sscrisk::cel::array<T, N> > {
static_assert(I < N, "tuple_get: index out of range"); public:
return t[I]; template<std::size_t I>
} static SPROUT_CONSTEXPR T&
template<std::size_t I, typename T, std::size_t N> tuple_get(sscrisk::cel::array<T, N>& t) SPROUT_NOEXCEPT {
inline SPROUT_CONSTEXPR T const& static_assert(I < N, "tuple_get: index out of range");
tuple_get(sscrisk::cel::array<T, N> const& t) SPROUT_NOEXCEPT { return t[I];
static_assert(I < N, "tuple_get: index out of range"); }
return t[I]; template<std::size_t I>
} static SPROUT_CONSTEXPR T const&
template<std::size_t I, typename T, std::size_t N> tuple_get(sscrisk::cel::array<T, N> const& t) SPROUT_NOEXCEPT {
inline SPROUT_CONSTEXPR T&& static_assert(I < N, "tuple_get: index out of range");
tuple_get(sscrisk::cel::array<T, N>&& t) SPROUT_NOEXCEPT { return t[I];
return sprout::move(sprout::tuples::get<I>(t)); }
} template<std::size_t I>
} // namespace sprout_adl static SPROUT_CONSTEXPR T&&
tuple_get(sscrisk::cel::array<T, N>&& t) SPROUT_NOEXCEPT {
return sprout::move(tuple_get<I>(t));
}
};
} // namespace tuples
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_ARRAY_HPP #endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_ARRAY_HPP

View file

@ -68,27 +68,33 @@ namespace sprout {
} // namespace tuples } // namespace tuples
} // namespace sprout } // namespace sprout
namespace sprout_adl { namespace sprout {
// namespace tuples {
// tuple_get //
// // tuple_access_traits
template<std::size_t I, typename T1, typename T2> //
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type& template<typename T1, typename T2>
tuple_get(sscrisk::cel::pair<T1, T2>& t) SPROUT_NOEXCEPT { struct tuple_access_traits<sscrisk::cel::pair<T1, T2> > {
static_assert(I < 2, "tuple_get: index out of range"); public:
return sprout::tuples::detail::get_impl<I, sscrisk::cel::pair<T1, T2> >()(t); template<std::size_t I>
} static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type&
template<std::size_t I, typename T1, typename T2> tuple_get(sscrisk::cel::pair<T1, T2>& t) SPROUT_NOEXCEPT {
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type const& static_assert(I < 2, "tuple_get: index out of range");
tuple_get(sscrisk::cel::pair<T1, T2> const& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::get_impl<I, sscrisk::cel::pair<T1, T2> >()(t);
static_assert(I < 2, "tuple_get: index out of range"); }
return sprout::tuples::detail::get_impl<I, sscrisk::cel::pair<T1, T2> >()(t); template<std::size_t I>
} static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type const&
template<std::size_t I, typename T1, typename T2> tuple_get(sscrisk::cel::pair<T1, T2> const& t) SPROUT_NOEXCEPT {
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type&& static_assert(I < 2, "tuple_get: index out of range");
tuple_get(sscrisk::cel::pair<T1, T2>&& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::get_impl<I, sscrisk::cel::pair<T1, T2> >()(t);
return sprout::move(sprout::tuples::get<I>(t)); }
} template<std::size_t I>
} // namespace sprout_adl static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type&&
tuple_get(sscrisk::cel::pair<T1, T2>&& t) SPROUT_NOEXCEPT {
return sprout::move(tuple_get<I>(t));
}
};
} // namespace tuples
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP #endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP

View file

@ -6,29 +6,36 @@
#include <array> #include <array>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/utility/move.hpp> #include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
#include <sprout/tuple/tuple/get.hpp> #include <sprout/tuple/tuple/get.hpp>
namespace sprout_adl { namespace sprout {
// namespace tuples {
// tuple_get //
// // tuple_access_traits
template<std::size_t I, typename T, std::size_t N> //
inline SPROUT_CONSTEXPR T& template<typename T, std::size_t N>
tuple_get(std::array<T, N>& t) SPROUT_NOEXCEPT { struct tuple_access_traits<std::array<T, N> > {
static_assert(I < N, "tuple_get: index out of range"); public:
return t[I]; template<std::size_t I>
} static SPROUT_CONSTEXPR T&
template<std::size_t I, typename T, std::size_t N> tuple_get(std::array<T, N>& t) SPROUT_NOEXCEPT {
inline SPROUT_CONSTEXPR T const& static_assert(I < N, "tuple_get: index out of range");
tuple_get(std::array<T, N> const& t) SPROUT_NOEXCEPT { return t[I];
static_assert(I < N, "tuple_get: index out of range"); }
return t[I]; template<std::size_t I>
} static SPROUT_CONSTEXPR T const&
template<std::size_t I, typename T, std::size_t N> tuple_get(std::array<T, N> const& t) SPROUT_NOEXCEPT {
inline SPROUT_CONSTEXPR T&& static_assert(I < N, "tuple_get: index out of range");
tuple_get(std::array<T, N>&& t) SPROUT_NOEXCEPT { return t[I];
return sprout::move(sprout::tuples::get<I>(t)); }
} template<std::size_t I>
} // namespace sprout_adl static SPROUT_CONSTEXPR T&&
tuple_get(std::array<T, N>&& t) SPROUT_NOEXCEPT {
return sprout::move(tuple_get<I>(t));
}
};
} // namespace tuples
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_STD_ARRAY_HPP #endif // #ifndef SPROUT_TUPLE_STD_ARRAY_HPP

View file

@ -38,27 +38,33 @@ namespace sprout {
} // namespace tuples } // namespace tuples
} // namespace sprout } // namespace sprout
namespace sprout_adl { namespace sprout {
// namespace tuples {
// tuple_get //
// // tuple_access_traits
template<std::size_t I, typename T1, typename T2> //
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, std::pair<T1, T2> >::type& template<typename T1, typename T2>
tuple_get(std::pair<T1, T2>& t) SPROUT_NOEXCEPT { struct tuple_access_traits<std::pair<T1, T2> > {
static_assert(I < 2, "tuple_get: index out of range"); public:
return sprout::tuples::detail::get_impl<I, std::pair<T1, T2> >()(t); template<std::size_t I>
} static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, std::pair<T1, T2> >::type&
template<std::size_t I, typename T1, typename T2> tuple_get(std::pair<T1, T2>& t) SPROUT_NOEXCEPT {
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, std::pair<T1, T2> >::type const& static_assert(I < 2, "tuple_get: index out of range");
tuple_get(std::pair<T1, T2> const& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::get_impl<I, std::pair<T1, T2> >()(t);
static_assert(I < 2, "tuple_get: index out of range"); }
return sprout::tuples::detail::get_impl<I, std::pair<T1, T2> >()(t); template<std::size_t I>
} static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, std::pair<T1, T2> >::type const&
template<std::size_t I, typename T1, typename T2> tuple_get(std::pair<T1, T2> const& t) SPROUT_NOEXCEPT {
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, std::pair<T1, T2> >::type&& static_assert(I < 2, "tuple_get: index out of range");
tuple_get(std::pair<T1, T2>&& t) SPROUT_NOEXCEPT { return sprout::tuples::detail::get_impl<I, std::pair<T1, T2> >()(t);
return sprout::move(sprout::tuples::get<I>(t)); }
} template<std::size_t I>
} // namespace sprout_adl static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, std::pair<T1, T2> >::type&&
tuple_get(std::pair<T1, T2>&& t) SPROUT_NOEXCEPT {
return sprout::move(tuple_get<I>(t));
}
};
} // namespace tuples
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_STD_UTILITY_HPP #endif // #ifndef SPROUT_TUPLE_STD_UTILITY_HPP

View file

@ -6,11 +6,14 @@
#include <sprout/tuple/tuple/tuple_decl.hpp> #include <sprout/tuple/tuple/tuple_decl.hpp>
#include <sprout/tuple/tuple/tuple.hpp> #include <sprout/tuple/tuple/tuple.hpp>
#include <sprout/tuple/tuple/comparison.hpp> #include <sprout/tuple/tuple/comparison.hpp>
#include <sprout/tuple/tuple/tuple_size.hpp>
#include <sprout/tuple/tuple/tuple_element.hpp>
#include <sprout/tuple/tuple/get.hpp> #include <sprout/tuple/tuple/get.hpp>
#include <sprout/tuple/tuple/hash.hpp> #include <sprout/tuple/tuple/hash.hpp>
#include <sprout/tuple/tuple/ignore.hpp> #include <sprout/tuple/tuple/ignore.hpp>
#include <sprout/tuple/tuple/make_tuple.hpp> #include <sprout/tuple/tuple/make_tuple.hpp>
#include <sprout/tuple/tuple/type_traits.hpp> #include <sprout/tuple/tuple/type_traits.hpp>
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
#include <sprout/tuple/flexibly_construct.hpp> #include <sprout/tuple/flexibly_construct.hpp>
#endif // #ifndef SPROUT_TUPLE_TUPLE_HPP #endif // #ifndef SPROUT_TUPLE_TUPLE_HPP

View file

@ -2,62 +2,21 @@
#define SPROUT_TUPLE_TUPLE_GET_HPP #define SPROUT_TUPLE_TUPLE_GET_HPP
#include <cstddef> #include <cstddef>
#include <utility>
#include <type_traits> #include <type_traits>
#include <tuple>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/tuple/tuple/tuple.hpp> #include <sprout/tuple/tuple/tuple.hpp>
#include <sprout/tuple/tuple/tuple_size.hpp>
#include <sprout/tuple/tuple/tuple_element.hpp>
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
#include <sprout/adl/not_found.hpp> #include <sprout/adl/not_found.hpp>
//#include <tuple>
//#include <sprout/type_traits/enabler_if.hpp>
namespace sprout { namespace sprout {
namespace tuples { namespace tuples {
//
// tuple_size
//
template<typename T>
struct tuple_size
: public std::tuple_size<T>
{};
template<typename T>
struct tuple_size<T const>
: public sprout::tuples::tuple_size<T>
{};
template<typename T>
struct tuple_size<T volatile>
: public sprout::tuples::tuple_size<T>
{};
template<typename T>
struct tuple_size<T const volatile>
: public sprout::tuples::tuple_size<T>
{};
//
// tuple_element
//
template<std::size_t I, typename T>
struct tuple_element
: public std::tuple_element<I, T>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T const>
: public std::add_const<
typename sprout::tuples::tuple_element<I, T>::type
>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T volatile>
: public std::add_volatile<
typename sprout::tuples::tuple_element<I, T>::type
>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T const volatile>
: public std::add_cv<
typename sprout::tuples::tuple_element<I, T>::type
>
{};
namespace detail { namespace detail {
template<std::size_t I, typename Head, typename... Tail> template<std::size_t I, typename Head, typename... Tail>
inline SPROUT_CONSTEXPR typename std::add_lvalue_reference<Head>::type inline SPROUT_CONSTEXPR typename std::add_lvalue_reference<Head>::type
@ -71,30 +30,28 @@ namespace sprout {
} }
} // namespace detail } // namespace detail
// //
// get // tuple_get
// //
template<std::size_t I, typename... Types> template<std::size_t I, typename... Types>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type& inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type&
get(sprout::tuples::tuple<Types...>& t) SPROUT_NOEXCEPT { tuple_get(sprout::tuples::tuple<Types...>& t) SPROUT_NOEXCEPT {
return sprout::tuples::detail::get_helper<I>(t); return sprout::tuples::detail::get_helper<I>(t);
} }
template<std::size_t I, typename... Types> template<std::size_t I, typename... Types>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type&& inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type&&
get(sprout::tuples::tuple<Types...>&& t) SPROUT_NOEXCEPT { tuple_get(sprout::tuples::tuple<Types...>&& t) SPROUT_NOEXCEPT {
return sprout::forward<typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type&&>( return sprout::forward<typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type&&>(
sprout::tuples::get<I>(t) sprout::tuples::tuple_get<I>(t)
); );
} }
template<std::size_t I, typename... Types> template<std::size_t I, typename... Types>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type const& inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::tuples::tuple<Types...> >::type const&
get(sprout::tuples::tuple<Types...> const& t) SPROUT_NOEXCEPT { tuple_get(sprout::tuples::tuple<Types...> const& t) SPROUT_NOEXCEPT {
return sprout::tuples::detail::get_helper<I>(t); return sprout::tuples::detail::get_helper<I>(t);
} }
} // namespace tuples } // namespace tuples
using sprout::tuples::tuple_size; using sprout::tuples::tuple_get;
using sprout::tuples::tuple_element;
using sprout::tuples::get;
} // namespace sprout } // namespace sprout
namespace sprout_adl { namespace sprout_adl {
@ -106,135 +63,37 @@ namespace sprout_tuple_detail {
using sprout_adl::tuple_get; using sprout_adl::tuple_get;
template<std::size_t I, typename T> template<std::size_t I, typename T>
struct has_adl_tuple_get_test { inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, T>::type&
public: tuple_get(T& t)
template< SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(std::declval<T>())))
typename U = T, {
typename sprout::enabler_if< return sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(t);
sprout::is_found_via_adl<decltype(tuple_get<I>(std::declval<U>()))>::value }
>::type = sprout::enabler
>
static std::true_type test(int);
static std::false_type test(...);
};
#if defined(_MSC_VER)
template<std::size_t I, typename T, typename Base_ = decltype(sprout_tuple_detail::has_adl_tuple_get_test<I, T>::test(0))>
struct has_adl_tuple_get
: public Base_
{};
#else
template<std::size_t I, typename T>
struct has_adl_tuple_get
: public decltype(sprout_tuple_detail::has_adl_tuple_get_test<I, T>::test(0))
{};
#endif
template<std::size_t I, typename T>
struct has_std_get_test {
public:
template<
typename U = T,
typename = decltype(std::get<I>(std::declval<U>()))
>
static std::true_type test(int);
static std::false_type test(...);
};
#if defined(_MSC_VER)
template<std::size_t I, typename T, typename Base_ = decltype(sprout_tuple_detail::has_std_get_test<I, T>::test(0))>
struct has_std_get
: public Base_
{};
#else
template<std::size_t I, typename T>
struct has_std_get
: public decltype(sprout_tuple_detail::has_std_get_test<I, T>::test(0))
{};
#endif
template<std::size_t I, typename T, typename Enable = void>
struct select_adl_tuple_get;
template<std::size_t I, typename T>
struct select_adl_tuple_get<
I, T,
typename std::enable_if<sprout_tuple_detail::has_adl_tuple_get<I, T>::value>::type
>
: public std::true_type
{};
template<std::size_t I, typename T>
struct select_adl_tuple_get<
I, T,
typename std::enable_if<!sprout_tuple_detail::has_adl_tuple_get<I, T>::value>::type
>
: public std::false_type
{};
template<std::size_t I, typename T, typename Enable = void>
struct select_std_get;
template<std::size_t I, typename T>
struct select_std_get<
I, T,
typename std::enable_if<
sprout_tuple_detail::has_std_get<I, T>::value
&& !sprout_tuple_detail::has_adl_tuple_get<I, T>::value
>::type
>
: public std::true_type
{};
template<std::size_t I, typename T>
struct select_std_get<
I, T,
typename std::enable_if<!(
sprout_tuple_detail::has_std_get<I, T>::value
&& !sprout_tuple_detail::has_adl_tuple_get<I, T>::value
)>::type
>
: public std::false_type
{};
template<std::size_t I, typename T, typename = void>
struct noexcept_get;
template<std::size_t I, typename T> template<std::size_t I, typename T>
struct noexcept_get<I, T, typename std::enable_if<sprout_tuple_detail::select_adl_tuple_get<I, T>::value>::type> inline SPROUT_CONSTEXPR typename std::enable_if<
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(tuple_get<I>(std::declval<T>()), false)> !std::is_const<T>::value && !std::is_volatile<T>::value && !std::is_reference<T>::value,
{}; typename sprout::tuples::tuple_element<I, typename std::remove_reference<T>::type>::type&&
>::type
tuple_get(T&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits<typename std::remove_reference<T>::type>::template tuple_get<I>(std::declval<T>())))
{
return sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(t);
}
template<std::size_t I, typename T> template<std::size_t I, typename T>
struct noexcept_get<I, T, typename std::enable_if<sprout_tuple_detail::select_std_get<I, T>::value>::type> inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, T>::type const&
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::get<I>(std::declval<T>()), false)> tuple_get(T const& t)
{}; SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits<T const>::template tuple_get<I>(std::declval<T>())))
{
return sprout::tuples::tuple_access_traits<T const>::template tuple_get<I>(t);
}
template<std::size_t I, typename T, typename = void>
struct get_result;
template<std::size_t I, typename T> template<std::size_t I, typename T>
struct get_result<I, T, typename std::enable_if<sprout_tuple_detail::select_adl_tuple_get<I, T>::value>::type> { inline SPROUT_CONSTEXPR decltype(tuple_get<I>(std::declval<T>()))
public: call_tuple_get(T&& t)
typedef decltype(tuple_get<I>(std::declval<T>())) type; SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(tuple_get<I>(std::declval<T>())))
};
template<std::size_t I, typename T>
struct get_result<I, T, typename std::enable_if<sprout_tuple_detail::select_std_get<I, T>::value>::type> {
public:
typedef decltype(std::get<I>(std::declval<T>())) type;
};
template<
std::size_t I, typename T,
typename sprout::enabler_if<sprout_tuple_detail::select_adl_tuple_get<I, T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout_tuple_detail::get_result<I, T>::type
get_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get<I, T>::value))
{ {
return tuple_get<I>(sprout::forward<T>(t)); return tuple_get<I>(sprout::forward<T>(t));
} }
template<
std::size_t I, typename T,
typename sprout::enabler_if<sprout_tuple_detail::select_std_get<I, T>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout_tuple_detail::get_result<I, T>::type
get_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get<I, T>::value))
{
return std::get<I>(sprout::forward<T>(t));
}
} // namespace sprout_tuple_detail } // namespace sprout_tuple_detail
namespace sprout { namespace sprout {
@ -243,11 +102,11 @@ namespace sprout {
// get // get
// //
template<std::size_t I, typename T> template<std::size_t I, typename T>
inline SPROUT_CONSTEXPR typename sprout_tuple_detail::get_result<I, T>::type inline SPROUT_CONSTEXPR decltype(sprout_tuple_detail::call_tuple_get<I>(std::declval<T>()))
get(T&& t) get(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_tuple_detail::noexcept_get<I, T>::value)) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_tuple_detail::call_tuple_get<I>(std::declval<T>())))
{ {
return sprout_tuple_detail::get_impl<I>(sprout::forward<T>(t)); return sprout_tuple_detail::call_tuple_get<I>(sprout::forward<T>(t));
} }
} // namespace tuples } // namespace tuples

View file

@ -0,0 +1,47 @@
#ifndef SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP
#define SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP
#include <cstddef>
#include <tuple>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple/tuple_element.hpp>
namespace sprout {
namespace tuples {
//
// tuple_access_traits
//
template<typename Tuple>
struct tuple_access_traits {
public:
template<std::size_t I>
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type&
tuple_get(Tuple& t) SPROUT_NOEXCEPT {
return std::get<I>(t);
}
template<std::size_t I>
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type&&
tuple_get(Tuple&& t) SPROUT_NOEXCEPT {
return std::get<I>(t);
}
template<std::size_t I>
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type const&
tuple_get(Tuple const& t) SPROUT_NOEXCEPT {
return std::get<I>(t);
}
};
template<typename Tuple>
struct tuple_access_traits<Tuple const> {
public:
template<std::size_t I>
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type const&
tuple_get(Tuple const& t) SPROUT_NOEXCEPT {
return sprout::tuples::tuple_access_traits<Tuple>::template tuple_get<I>(t);
}
};
} // namespace tuples
using sprout::tuples::tuple_access_traits;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP

View file

@ -0,0 +1,41 @@
#ifndef SPROUT_TUPLE_TUPLE_TUPLE_ELEMENT_HPP
#define SPROUT_TUPLE_TUPLE_TUPLE_ELEMENT_HPP
#include <cstddef>
#include <type_traits>
#include <tuple>
#include <sprout/config.hpp>
namespace sprout {
namespace tuples {
//
// tuple_element
//
template<std::size_t I, typename T>
struct tuple_element
: public std::tuple_element<I, T>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T const>
: public std::add_const<
typename sprout::tuples::tuple_element<I, T>::type
>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T volatile>
: public std::add_volatile<
typename sprout::tuples::tuple_element<I, T>::type
>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T const volatile>
: public std::add_cv<
typename sprout::tuples::tuple_element<I, T>::type
>
{};
} // namespace tuples
using sprout::tuples::tuple_element;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_ELEMENT_HPP

View file

@ -0,0 +1,33 @@
#ifndef SPROUT_TUPLE_TUPLE_TUPLE_SIZE_HPP
#define SPROUT_TUPLE_TUPLE_TUPLE_SIZE_HPP
#include <tuple>
#include <sprout/config.hpp>
namespace sprout {
namespace tuples {
//
// tuple_size
//
template<typename T>
struct tuple_size
: public std::tuple_size<T>
{};
template<typename T>
struct tuple_size<T const>
: public sprout::tuples::tuple_size<T>
{};
template<typename T>
struct tuple_size<T volatile>
: public sprout::tuples::tuple_size<T>
{};
template<typename T>
struct tuple_size<T const volatile>
: public sprout::tuples::tuple_size<T>
{};
} // namespace tuples
using sprout::tuples::tuple_size;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_SIZE_HPP