fix tuple get adapt-interfaces

This commit is contained in:
bolero-MURAKAMI 2012-09-29 18:41:13 +09:00
parent 0c00166c5f
commit 2dcafaa98d
10 changed files with 265 additions and 266 deletions

View file

@ -6,32 +6,29 @@
#include <type_traits>
#include <sprout/array/array.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/get.hpp>
namespace sprout {
namespace tuples {
//
// get
// tuple_get
//
template<std::size_t I, typename T, std::size_t N>
inline SPROUT_CONSTEXPR T&
get(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
static_assert(I < N, "get: index out of range");
tuple_get(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
static_assert(I < N, "tuple_get: index out of range");
return t[I];
}
template<std::size_t I, typename T, std::size_t N>
inline SPROUT_CONSTEXPR T const&
get(sprout::array<T, N> const& t) SPROUT_NOEXCEPT {
static_assert(I < N, "get: index out of range");
tuple_get(sprout::array<T, N> const& t) SPROUT_NOEXCEPT {
static_assert(I < N, "tuple_get: index out of range");
return t[I];
}
template<std::size_t I, typename T, std::size_t N>
inline SPROUT_CONSTEXPR T&&
get(sprout::array<T, N>&& t) SPROUT_NOEXCEPT {
tuple_get(sprout::array<T, N>&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
namespace std {

View file

@ -6,35 +6,32 @@
#include <type_traits>
#include <sprout/pit/pit.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/get.hpp>
namespace sprout {
namespace tuples {
namespace sprout_adl {
//
// get
// tuple_get
//
template<std::size_t I, typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<sprout::pit<Container> >::value_type&
get(sprout::pit<Container>& t) SPROUT_NOEXCEPT {
static_assert(I < sprout::container_traits<sprout::pit<Container> >::static_size, "get: index out of range");
tuple_get(sprout::pit<Container>& t) SPROUT_NOEXCEPT {
static_assert(I < sprout::container_traits<sprout::pit<Container> >::static_size, "tuple_get: index out of range");
return t[I];
}
template<std::size_t I, typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<sprout::pit<Container> >::value_type const&
get(sprout::pit<Container> const& t) SPROUT_NOEXCEPT {
static_assert(I < sprout::container_traits<sprout::pit<Container> >::static_size, "get: index out of range");
tuple_get(sprout::pit<Container> const& t) SPROUT_NOEXCEPT {
static_assert(I < sprout::container_traits<sprout::pit<Container> >::static_size, "tuple_get: index out of range");
return t[I];
}
template<std::size_t I, typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<sprout::pit<Container> >::value_type&&
get(sprout::pit<Container>&& t)
tuple_get(sprout::pit<Container>&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get<I>(t))))
{
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
} // namespace sprout_adl
namespace std {
//

View file

@ -6,33 +6,30 @@
#include <type_traits>
#include <sprout/string/string.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/get.hpp>
namespace sprout {
namespace tuples {
namespace sprout_adl {
//
// get
// tuple_get
//
template<std::size_t I, typename T, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR T&
get(sprout::basic_string<T, N, Traits>& t) SPROUT_NOEXCEPT {
static_assert(I < N, "get: index out of range");
tuple_get(sprout::basic_string<T, N, Traits>& t) SPROUT_NOEXCEPT {
static_assert(I < N, "tuple_get: index out of range");
return t[I];
}
template<std::size_t I, typename T, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR T const&
get(sprout::basic_string<T, N, Traits> const& t) SPROUT_NOEXCEPT {
static_assert(I < N, "get: index out of range");
tuple_get(sprout::basic_string<T, N, Traits> const& t) SPROUT_NOEXCEPT {
static_assert(I < N, "tuple_get: index out of range");
return t[I];
}
template<std::size_t I, typename T, std::size_t N, typename Traits>
inline SPROUT_CONSTEXPR T&&
get(sprout::basic_string<T, N, Traits>&& t) SPROUT_NOEXCEPT {
tuple_get(sprout::basic_string<T, N, Traits>&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
} // namespace sprout_adl
namespace std {
//

View file

@ -11,39 +11,36 @@
#include <sprout/utility/move.hpp>
#include <sprout/sub_array/sub_array.hpp>
#include <sprout/sub_array/container.hpp>
#include <sprout/tuple/tuple/get.hpp>
namespace sprout {
namespace tuples {
namespace sprout_adl {
//
// get
// tuple_get
//
template<std::size_t I, typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<sprout::sub_array<Container> >::value_type&
get(sprout::sub_array<Container>& t)
tuple_get(sprout::sub_array<Container>& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I)))
{
static_assert(I < sprout::container_traits<sprout::sub_array<Container> >::static_size, "get: index out of range");
static_assert(I < sprout::container_traits<sprout::sub_array<Container> >::static_size, "tuple_get: index out of range");
return *sprout::next(sprout::internal_begin(t), I);
}
template<std::size_t I, typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<sprout::sub_array<Container> >::value_type const&
get(sprout::sub_array<Container> const& t)
tuple_get(sprout::sub_array<Container> const& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I)))
{
static_assert(I < sprout::container_traits<sprout::sub_array<Container> >::static_size, "get: index out of range");
static_assert(I < sprout::container_traits<sprout::sub_array<Container> >::static_size, "tuple_get: index out of range");
return *sprout::next(sprout::internal_begin(t), I);
}
template<std::size_t I, typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<sprout::sub_array<Container> >::value_type&&
get(sprout::sub_array<Container>&& t)
tuple_get(sprout::sub_array<Container>&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get<I>(t))))
{
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
} // namespace sprout_adl
namespace std {
//

View file

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

View file

@ -5,8 +5,8 @@
#include <type_traits>
#include <sscrisk/cel/utility.hpp>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple.hpp>
namespace sprout {
namespace tuples {
@ -18,9 +18,6 @@ namespace sprout {
: public std::integral_constant<std::size_t, 2>
{};
//
// tuple_element
//
namespace detail {
template<std::size_t I, typename T>
struct tuple_element_impl;
@ -35,14 +32,14 @@ namespace sprout {
typedef T2 type;
};
} // namespace detail
//
// tuple_element
//
template<std::size_t I, typename T1, typename T2>
struct tuple_element<I, sscrisk::cel::pair<T1, T2> >
: public sprout::tuples::detail::tuple_element_impl<I, sscrisk::cel::pair<T1, T2> >
{};
//
// get
//
namespace detail {
template<std::size_t I, typename T>
struct get_impl;
@ -68,26 +65,33 @@ namespace sprout {
}
};
} // namespace detail
} // namespace tuples
} // namespace sprout
namespace sprout_adl {
//
// tuple_get
//
template<std::size_t I, typename T1, typename T2>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type&
get(sscrisk::cel::pair<T1, T2>& t) SPROUT_NOEXCEPT {
static_assert(I < 2, "get: index out of range");
tuple_get(sscrisk::cel::pair<T1, T2>& t) SPROUT_NOEXCEPT {
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, typename T1, typename T2>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type const&
get(sscrisk::cel::pair<T1, T2> const& t) SPROUT_NOEXCEPT {
static_assert(I < 2, "get: index out of range");
tuple_get(sscrisk::cel::pair<T1, T2> const& t) SPROUT_NOEXCEPT {
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, typename T1, typename T2>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type&&
get(sscrisk::cel::pair<T1, T2>&& t) SPROUT_NOEXCEPT {
tuple_get(sscrisk::cel::pair<T1, T2>&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
} // namespace sprout_adl
#endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP

View file

@ -8,6 +8,7 @@
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/tuple/tuple/tuple.hpp>
#include <sprout/adl/not_found.hpp>
namespace sprout {
namespace tuples {
@ -90,20 +91,29 @@ namespace sprout {
using sprout::tuples::get;
} // namespace sprout
namespace sprout_adl {
template<std::size_t I>
sprout::adl_not_found tuple_get(...);
} // namespace sprout_adl
namespace sprout_tuple_detail {
using sprout_adl::tuple_get;
template<std::size_t I, typename T>
struct has_spr_get_test {
struct has_adl_tuple_get_test {
public:
template<
typename U = T,
typename = decltype(sprout::tuples::get<I>(std::declval<U>()))
typename sprout::enabler_if<
!std::is_same<decltype(tuple_get<I>(std::declval<U>())), sprout::adl_not_found>::value
>::type = sprout::enabler
>
static std::true_type test(int);
static std::false_type test(...);
};
template<std::size_t I, typename T>
struct has_spr_get
: public decltype(sprout_tuple_detail::has_spr_get_test<I, T>::test(0))
struct has_adl_tuple_get
: public decltype(sprout_tuple_detail::has_adl_tuple_get_test<I, T>::test(0))
{};
template<std::size_t I, typename T>
@ -122,18 +132,18 @@ namespace sprout_tuple_detail {
{};
template<std::size_t I, typename T, typename Enable = void>
struct select_spr_get;
struct select_adl_tuple_get;
template<std::size_t I, typename T>
struct select_spr_get<
struct select_adl_tuple_get<
I, T,
typename std::enable_if<sprout_tuple_detail::has_spr_get<I, T>::value>::type
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_spr_get<
struct select_adl_tuple_get<
I, T,
typename std::enable_if<!sprout_tuple_detail::has_spr_get<I, T>::value>::type
typename std::enable_if<!sprout_tuple_detail::has_adl_tuple_get<I, T>::value>::type
>
: public std::false_type
{};
@ -145,7 +155,7 @@ namespace sprout_tuple_detail {
I, T,
typename std::enable_if<
sprout_tuple_detail::has_std_get<I, T>::value
&& !sprout_tuple_detail::has_spr_get<I, T>::value
&& !sprout_tuple_detail::has_adl_tuple_get<I, T>::value
>::type
>
: public std::true_type
@ -155,7 +165,7 @@ namespace sprout_tuple_detail {
I, T,
typename std::enable_if<!(
sprout_tuple_detail::has_std_get<I, T>::value
&& !sprout_tuple_detail::has_spr_get<I, T>::value
&& !sprout_tuple_detail::has_adl_tuple_get<I, T>::value
)>::type
>
: public std::false_type
@ -163,10 +173,10 @@ namespace sprout_tuple_detail {
template<std::size_t I, typename T, typename = void>
struct noexcept_get;
// template<std::size_t I, typename T>
// struct noexcept_get<I, T, typename std::enable_if<sprout_tuple_detail::select_spr_get<I, T>::value>::type>
// : public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(sprout::tuples::get<I>(std::declval<T>()), false)>
// {};
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>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(tuple_get<I>(std::declval<T>()), false)>
{};
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>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::get<I>(std::declval<T>()), false)>
@ -174,27 +184,27 @@ namespace sprout_tuple_detail {
template<std::size_t I, typename T, typename = void>
struct get_result;
// template<std::size_t I, typename T>
// struct get_result<I, T, typename std::enable_if<sprout_tuple_detail::select_spr_get<I, T>::value>::type> {
// public:
// typedef decltype(sprout::tuples::get<I>(std::declval<T>())) type;
// };
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> {
public:
typedef decltype(tuple_get<I>(std::declval<T>())) type;
};
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_spr_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 sprout::tuples::get<I>(sprout::forward<T>(t));
// }
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));
}
template<
std::size_t I, typename T,
typename sprout::enabler_if<sprout_tuple_detail::select_std_get<I, T>::value>::type = sprout::enabler

View file

@ -181,34 +181,7 @@ namespace sprout {
public:
typedef T2 type;
};
} // namespace detail
} // namespace tuples
} // namespace sprout
namespace std {
//
// tuple_size
//
template<typename T1, typename T2>
struct tuple_size<sprout::pair<T1, T2> >
: public std::integral_constant<std::size_t, 2>
{};
//
// tuple_element
//
template<std::size_t I, typename T1, typename T2>
struct tuple_element<I, sprout::pair<T1, T2> >
: public sprout::tuples::detail::tuple_element_impl<I, sprout::pair<T1, T2> >
{};
} // namespace std
namespace sprout {
namespace tuples {
//
// get
//
namespace detail {
template<std::size_t I, typename T>
struct get_impl;
template<typename T1, typename T2>
@ -232,26 +205,48 @@ namespace sprout {
}
};
} // namespace detail
} // namespace tuples
} // namespace sprout
namespace std {
//
// tuple_size
//
template<typename T1, typename T2>
struct tuple_size<sprout::pair<T1, T2> >
: public std::integral_constant<std::size_t, 2>
{};
//
// tuple_element
//
template<std::size_t I, typename T1, typename T2>
struct tuple_element<I, sprout::pair<T1, T2> >
: public sprout::tuples::detail::tuple_element_impl<I, sprout::pair<T1, T2> >
{};
} // namespace std
namespace sprout_adl {
//
// tuple_get
//
template<std::size_t I, typename T1, typename T2>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::pair<T1, T2> >::type&
get(sprout::pair<T1, T2>& t) SPROUT_NOEXCEPT {
static_assert(I < 2, "get: index out of range");
tuple_get(sprout::pair<T1, T2>& t) SPROUT_NOEXCEPT {
static_assert(I < 2, "tuple_get: index out of range");
return sprout::tuples::detail::get_impl<I, sprout::pair<T1, T2> >()(t);
}
template<std::size_t I, typename T1, typename T2>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::pair<T1, T2> >::type const&
get(sprout::pair<T1, T2> const& t) SPROUT_NOEXCEPT {
static_assert(I < 2, "get: index out of range");
tuple_get(sprout::pair<T1, T2> const& t) SPROUT_NOEXCEPT {
static_assert(I < 2, "tuple_get: index out of range");
return sprout::tuples::detail::get_impl<I, sprout::pair<T1, T2> >()(t);
}
template<std::size_t I, typename T1, typename T2>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::pair<T1, T2> >::type&&
get(sprout::pair<T1, T2>&& t) SPROUT_NOEXCEPT {
tuple_get(sprout::pair<T1, T2>&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
} // namespace sprout_adl
#endif // #ifndef SPROUT_UTILITY_PAIR_HPP

View file

@ -6,33 +6,30 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/get.hpp>
#include <sprout/uuid/uuid.hpp>
namespace sprout {
namespace tuples {
namespace sprout_adl {
//
// get
// tuple_get
//
template<std::size_t I>
inline SPROUT_CONSTEXPR sprout::uuids::uuid::value_type&
get(sprout::uuids::uuid& t) SPROUT_NOEXCEPT {
static_assert(I < 16, "get: index out of range");
tuple_get(sprout::uuids::uuid& t) SPROUT_NOEXCEPT {
static_assert(I < 16, "tuple_get: index out of range");
return t[I];
}
template<std::size_t I>
inline SPROUT_CONSTEXPR sprout::uuids::uuid::value_type const&
get(sprout::uuids::uuid const& t) SPROUT_NOEXCEPT {
static_assert(I < 16, "get: index out of range");
tuple_get(sprout::uuids::uuid const& t) SPROUT_NOEXCEPT {
static_assert(I < 16, "tuple_get: index out of range");
return t[I];
}
template<std::size_t I>
inline SPROUT_CONSTEXPR sprout::uuids::uuid::value_type&&
get(sprout::uuids::uuid&& t) SPROUT_NOEXCEPT {
tuple_get(sprout::uuids::uuid&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
namespace std {

View file

@ -3,7 +3,7 @@
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/tuple/tuple/get.hpp>
#include <sprout/variant/variant.hpp>
namespace sprout {
@ -18,20 +18,28 @@ namespace sprout {
inline SPROUT_CONSTEXPR U& get(sprout::variant<Types...>& operand) {
return operand.template get<U>();
}
template<std::size_t I, typename... Types>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<
I,
sprout::variant<Types...>
>::type const& get(sprout::variant<Types...> const& operand) {
return operand.template get_at<I>();
}
template<std::size_t I, typename... Types>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<
I,
sprout::variant<Types...>
>::type& get(sprout::variant<Types...>& operand) {
return operand.template get_at<I>();
}
} // namespace sprout
namespace sprout_adl {
//
// tuple_get
//
template<std::size_t I, typename... Types>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<
I,
sprout::variant<Types...>
>::type const&
tuple_get(sprout::variant<Types...> const& operand) {
return operand.template get_at<I>();
}
template<std::size_t I, typename... Types>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<
I,
sprout::variant<Types...>
>::type&
tuple_get(sprout::variant<Types...>& operand) {
return operand.template get_at<I>();
}
} // namespace sprout_adl
#endif // #ifndef SPROUT_VARIANT_GET_HPP