fix type-traits

This commit is contained in:
bolero-MURAKAMI 2012-04-13 21:23:49 +09:00
parent 8f818ee63f
commit 3eafabb1ed
15 changed files with 202 additions and 136 deletions

View file

@ -261,30 +261,24 @@ namespace sprout {
return sprout::detail::to_array_impl(arr, typename sprout::index_range<0, N>::type());
}
namespace detail {
template<typename T, typename Enable = void>
struct is_array_impl
: public std::false_type
{};
template<typename T>
struct is_array_impl<
T,
typename std::enable_if<
std::is_same<
T,
sprout::array<typename T::value_type, T::static_size>
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
//
// is_array
//
template<typename T>
struct is_array
: public sprout::detail::is_array_impl<T>
: public std::false_type
{};
template<typename T>
struct is_array<T const>
: public sprout::is_array<T>
{};
template<typename T>
struct is_array<T const volatile>
: public sprout::is_array<T>
{};
template<typename T, std::size_t N>
struct is_array<sprout::array<T, N> >
: public std::true_type
{};
} // namespace sprout

View file

@ -25,6 +25,14 @@ namespace sprout {
struct is_bind_expression<T const>
: public sprout::is_bind_expression<T>
{};
template<typename T>
struct is_bind_expression<T volatile>
: public sprout::is_bind_expression<T>
{};
template<typename T>
struct is_bind_expression<T const volatile>
: public sprout::is_bind_expression<T>
{};
template<typename T>
struct is_placeholder
@ -34,6 +42,14 @@ namespace sprout {
struct is_placeholder<T const>
: public sprout::is_placeholder<T>
{};
template<typename T>
struct is_placeholder<T volatile>
: public sprout::is_placeholder<T>
{};
template<typename T>
struct is_placeholder<T const volatile>
: public sprout::is_placeholder<T>
{};
//
// placeholder

View file

@ -196,10 +196,6 @@ namespace sprout {
: public std::false_type
{};
template<typename T>
struct is_reference_wrapper<sprout::reference_wrapper<T> >
: public std::true_type
{};
template<typename T>
struct is_reference_wrapper<T const>
: public sprout::is_reference_wrapper<T>
{};
@ -211,6 +207,10 @@ namespace sprout {
struct is_reference_wrapper<T const volatile>
: public sprout::is_reference_wrapper<T>
{};
template<typename T>
struct is_reference_wrapper<sprout::reference_wrapper<T> >
: public std::true_type
{};
//
// unwrap_reference

View file

@ -175,6 +175,26 @@ namespace sprout {
lhs.swap(rhs);
}
//
// is_index_iterator
//
template<typename T>
struct is_index_iterator
: public std::false_type
{};
template<typename T>
struct is_index_iterator<T const>
: public sprout::is_index_iterator<T>
{};
template<typename T>
struct is_index_iterator<T const volatile>
: public sprout::is_index_iterator<T>
{};
template<typename Container>
struct is_index_iterator<sprout::index_iterator<Container> >
: public std::true_type
{};
//
// next
//

View file

@ -95,30 +95,28 @@ namespace sprout {
lhs.swap(rhs);
}
namespace detail {
template<typename T, typename Enable = void>
struct is_range_container_impl
: public std::false_type
{};
template<typename T>
struct is_range_container_impl<
T,
typename std::enable_if<
std::is_same<
T,
sprout::range::range_container<typename T::iterator>
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
//
// is_range_container
//
template<typename T>
struct is_range_container
: public sprout::range::detail::is_range_container_impl<T>
: public std::false_type
{};
template<typename T>
struct is_range_container<T const>
: public sprout::range::is_range_container<T>
{};
template<typename T>
struct is_range_container<T volatile>
: public sprout::range::is_range_container<T>
{};
template<typename T>
struct is_range_container<T const volatile>
: public sprout::range::is_range_container<T>
{};
template<typename Iterator>
struct is_range_container<sprout::range::range_container<Iterator> >
: public std::true_type
{};
} // namespace range

View file

@ -169,33 +169,6 @@ namespace sprout {
typedef sprout::reverse_iterator<iterator> reverse_iterator;
typedef sprout::reverse_iterator<const_iterator> const_reverse_iterator;
typedef Traits traits_type;
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
private:
template<typename U, typename Enable = void>
struct is_index_iterator_impl
: public std::false_type
{};
template<typename U>
struct is_index_iterator_impl<
U,
typename std::enable_if<
std::is_same<
U,
sprout::index_iterator<typename U::container_type>
>::value
&& std::is_same<
typename std::iterator_traits<U>::value_type,
value_type
>::value
>::type
>
: public std::true_type
{};
template<typename U>
struct is_index_iterator
: public is_index_iterator_impl<U>
{};
#endif
public:
SPROUT_STATIC_CONSTEXPR size_type npos = -1;
SPROUT_STATIC_CONSTEXPR size_type static_size = N;
@ -226,7 +199,7 @@ namespace sprout {
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
template<typename ConstIterator>
static SPROUT_CONSTEXPR typename std::enable_if<
is_index_iterator<ConstIterator>::value,
sprout::is_index_iterator<ConstIterator>::value,
int
>::type compare_impl_1(value_type const* dest, size_type pos1, size_type n1, ConstIterator s, size_type n2) {
return compare_impl_2(
@ -244,7 +217,7 @@ namespace sprout {
}
template<typename ConstIterator>
static SPROUT_CONSTEXPR typename std::enable_if<
is_index_iterator<ConstIterator>::value,
sprout::is_index_iterator<ConstIterator>::value,
int
>::type compare_impl_1(const_iterator dest, size_type pos1, size_type n1, ConstIterator s, size_type n2) {
return compare_impl_2(
@ -530,7 +503,7 @@ namespace sprout {
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
template<typename ConstIterator>
typename std::enable_if<
is_index_iterator<ConstIterator>::value,
sprout::is_index_iterator<ConstIterator>::value,
basic_string<T, N, Traits>&
>::type assign(ConstIterator s, size_type n) {
maxcheck(n);
@ -545,35 +518,35 @@ namespace sprout {
}
template<typename ConstIterator>
typename std::enable_if<
is_index_iterator<ConstIterator>::value,
sprout::is_index_iterator<ConstIterator>::value,
basic_string<T, N, Traits>&
>::type assign(ConstIterator s) {
return assign(s, traits_type::length(s));
}
template<typename ConstIterator>
typename std::enable_if<
is_index_iterator<ConstIterator>::value,
sprout::is_index_iterator<ConstIterator>::value,
basic_string<T, N, Traits>&
>::type operator=(ConstIterator rhs) {
return assign(rhs);
}
template<typename ConstIterator>
SPROUT_CONSTEXPR typename std::enable_if<
is_index_iterator<ConstIterator>::value,
sprout::is_index_iterator<ConstIterator>::value,
int
>::type compare(ConstIterator s) const {
return compare(0, size(), s, traits_type::length(s));
}
template<typename ConstIterator>
SPROUT_CONSTEXPR typename std::enable_if<
is_index_iterator<ConstIterator>::value,
sprout::is_index_iterator<ConstIterator>::value,
int
>::type compare(size_type pos1, size_type n1, ConstIterator s) const {
return compare(pos1, n1, s, traits_type::length(s));
}
template<typename ConstIterator>
SPROUT_CONSTEXPR typename std::enable_if<
is_index_iterator<ConstIterator>::value,
sprout::is_index_iterator<ConstIterator>::value,
int
>::type compare(size_type pos1, size_type n1, ConstIterator s, size_type n2) const {
return !(size() < pos1)
@ -1003,57 +976,44 @@ namespace sprout {
typedef sprout::basic_string<char32_t, N> type;
};
namespace detail {
template<typename T, typename Enable = void>
struct is_basic_string_impl
: public std::false_type
{};
template<typename T>
struct is_basic_string_impl<
T,
typename std::enable_if<
std::is_same<
T,
sprout::basic_string<typename T::value_type, T::static_size, typename T::traits_type>
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
//
// is_basic_string
//
template<typename T>
struct is_basic_string
: public sprout::detail::is_basic_string_impl<T>
: public std::false_type
{};
template<typename T>
struct is_basic_string<T const>
: public sprout::is_basic_string<T>
{};
template<typename T>
struct is_basic_string<T const volatile>
: public sprout::is_basic_string<T>
{};
template<typename T, std::size_t N, typename Traits>
struct is_basic_string<sprout::basic_string<T, N, Traits> >
: public std::true_type
{};
namespace detail {
template<typename T, typename Elem, typename Enable = void>
struct is_string_of_impl
: public std::false_type
{};
template<typename T, typename Elem>
struct is_string_of_impl<
T,
Elem,
typename std::enable_if<
std::is_same<
T,
sprout::basic_string<Elem, T::static_size>
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
//
// is_string_of
//
template<typename T, typename Elem>
struct is_string_of
: public sprout::detail::is_string_of_impl<T, Elem>
: public std::false_type
{};
template<typename T, typename Elem>
struct is_string_of<T const, Elem>
: public sprout::is_string_of<T, Elem>
{};
template<typename T, typename Elem>
struct is_string_of<T const volatile, Elem>
: public sprout::is_string_of<T, Elem>
{};
template<typename T, std::size_t N, typename Traits, typename Elem>
struct is_string_of<sprout::basic_string<T, N, Traits>, Elem>
: public std::true_type
{};
//

View file

@ -520,30 +520,24 @@ namespace sprout {
}
};
namespace detail {
template<typename T, typename Enable = void>
struct is_sub_array_impl
: public std::false_type
{};
template<typename T>
struct is_sub_array_impl<
T,
typename std::enable_if<
std::is_same<
T,
sprout::sub_array<typename T::container_type>
>::value
>::type
>
: public std::true_type
{};
} // namespace detail
//
// is_sub_array
//
template<typename T>
struct is_sub_array
: public sprout::detail::is_sub_array_impl<T>
: public std::false_type
{};
template<typename T>
struct is_sub_array<T const>
: public sprout::is_sub_array<T>
{};
template<typename T>
struct is_sub_array<T const volatile>
: public sprout::is_sub_array<T>
{};
template<typename Container>
struct is_sub_array<sprout::sub_array<Container> >
: public std::true_type
{};
//

View file

@ -407,6 +407,18 @@ namespace sprout {
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
@ -415,6 +427,18 @@ namespace sprout {
struct tuple_element
: public std::tuple_element<I, T>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T const>
: public sprout::tuples::tuple_element<I, T>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T volatile>
: public sprout::tuples::tuple_element<I, T>
{};
template<std::size_t I, typename T>
struct tuple_element<I, T const volatile>
: public sprout::tuples::tuple_element<I, T>
{};
//
// get

View file

@ -19,6 +19,14 @@ namespace sprout {
struct is_expr<T const>
: public sprout::weed::traits::is_expr<T>
{};
template<typename T>
struct is_expr<T volatile>
: public sprout::weed::traits::is_expr<T>
{};
template<typename T>
struct is_expr<T const volatile>
: public sprout::weed::traits::is_expr<T>
{};
template<typename Tag, typename... Args>
struct is_expr<sprout::weed::expr<Tag, Args...> >
: public std::true_type

View file

@ -18,6 +18,14 @@ namespace sprout {
struct is_c_str<T const>
: public sprout::weed::traits::is_c_str<T>
{};
template<typename T>
struct is_c_str<T volatile>
: public sprout::weed::traits::is_c_str<T>
{};
template<typename T>
struct is_c_str<T const volatile>
: public sprout::weed::traits::is_c_str<T>
{};
template<std::size_t N>
struct is_c_str<char const[N]>
: public std::true_type

View file

@ -18,6 +18,14 @@ namespace sprout {
struct is_char_type<T const>
: public sprout::weed::traits::is_char_type<T>
{};
template<typename T>
struct is_char_type<T volatile>
: public sprout::weed::traits::is_char_type<T>
{};
template<typename T>
struct is_char_type<T const volatile>
: public sprout::weed::traits::is_char_type<T>
{};
template<>
struct is_char_type<char>
: public std::true_type

View file

@ -20,6 +20,14 @@ namespace sprout {
struct is_container<T const>
: public sprout::weed::traits::is_container<T>
{};
template<typename T>
struct is_container<T volatile>
: public sprout::weed::traits::is_container<T>
{};
template<typename T>
struct is_container<T const volatile>
: public sprout::weed::traits::is_container<T>
{};
template<typename T, std::size_t N>
struct is_container<sprout::array<T, N> >
: public std::true_type

View file

@ -19,6 +19,14 @@ namespace sprout {
struct is_string<T const>
: public sprout::weed::traits::is_string<T>
{};
template<typename T>
struct is_string<T volatile>
: public sprout::weed::traits::is_string<T>
{};
template<typename T>
struct is_string<T const volatile>
: public sprout::weed::traits::is_string<T>
{};
template<typename T, std::size_t N, typename Traits>
struct is_string<sprout::basic_string<T, N, Traits> >
: public std::true_type

View file

@ -19,6 +19,14 @@ namespace sprout {
struct is_tuple<T const>
: public sprout::weed::traits::is_tuple<T>
{};
template<typename T>
struct is_tuple<T volatile>
: public sprout::weed::traits::is_tuple<T>
{};
template<typename T>
struct is_tuple<T const volatile>
: public sprout::weed::traits::is_tuple<T>
{};
template<typename... Types>
struct is_tuple<sprout::tuples::tuple<Types...> >
: public std::true_type

View file

@ -13,12 +13,24 @@ namespace sprout {
//
template<typename T>
struct is_unused
: public std::is_same<T, sprout::weed::unused>
: public std::false_type
{};
template<typename T>
struct is_unused<T const>
: public sprout::weed::traits::is_unused<T>
{};
template<typename T>
struct is_unused<T volatile>
: public sprout::weed::traits::is_unused<T>
{};
template<typename T>
struct is_unused<T const volatile>
: public sprout::weed::traits::is_unused<T>
{};
template<>
struct is_unused<sprout::weed::unused>
: public std::true_type
{};
} // namespace traits
} // namespace weed
} // namespace sprout