1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

change range functions adapt

This commit is contained in:
bolero-MURAKAMI 2016-04-17 16:11:43 +09:00
parent 92cc7881d6
commit 8278a2642c
15 changed files with 454 additions and 100 deletions

View file

@ -282,47 +282,6 @@ namespace sprout {
lhs.swap(rhs);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::iterator
range_begin(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
return sprout::const_iterator_cast<typename sprout::array<T, N>::iterator>(sprout::as_const(t).begin());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::iterator
range_end(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
return sprout::const_iterator_cast<typename sprout::array<T, N>::iterator>(sprout::as_const(t).end());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::reference
range_at(sprout::array<T, N>& t, typename sprout::array<T, N>::size_type i) {
return const_cast<typename sprout::array<T, N>::reference>(sprout::as_const(t).at(i));
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::reference
range_front(sprout::array<T, N>& t) {
return const_cast<typename sprout::array<T, N>::reference>(sprout::as_const(t).front());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::reference
range_back(sprout::array<T, N>& t) {
return const_cast<typename sprout::array<T, N>::reference>(sprout::as_const(t).back());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::iterator
range_nth(sprout::array<T, N>& t, typename sprout::array<T, N>::size_type i) {
return sprout::const_iterator_cast<typename sprout::array<T, N>::iterator>(sprout::as_const(t).nth(i));
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::size_type
range_index_of(sprout::array<T, N>& t, typename sprout::array<T, N>::iterator p) SPROUT_NOEXCEPT {
return sprout::as_const(t).index_of(p);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::pointer
range_data(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
return const_cast<typename sprout::array<T, N>::pointer>(sprout::as_const(t).data());
}
//
// to_array
//

View file

@ -23,6 +23,13 @@ namespace sprout {
// ADL callable range_at(cont, i) -> range_at(cont, i)
// [default]
// Container is T[N] -> cont[i]
// otherwise, Container is not const
// && sprout::is_const_cast_convertible<const_reference, reference>
// && (callable sprout::as_const(cont).at(i)
// || callable sprout::as_const(cont).begin()
// || ADL(without sprout) callable begin(sprout::as_const(cont))
// )
// -> const_cast<reference>(sprout::at(sprout::as_const(cont), i))
// otherwise, callable cont.at(i) -> cont.at(i)
// otherwise -> *sprout::next(sprout::begin(cont), i)
//

View file

@ -23,6 +23,13 @@ namespace sprout {
// ADL callable range_back(cont) -> range_back(cont)
// [default]
// Container is T[N] -> cont[N - 1]
// otherwise, Container is not const
// && sprout::is_const_cast_convertible<const_reference, reference>
// && (callable sprout::as_const(cont).back()
// || callable sprout::as_const(cont).begin()
// || ADL(without sprout) callable begin(sprout::as_const(cont))
// )
// -> const_cast<reference>(sprout::back(sprout::as_const(cont)))
// otherwise, callable cont.back() -> cont.back()
// otherwise -> *sprout::next(sprout::begin(cont), sprout::size(cont) - 1)
//

View file

@ -23,8 +23,14 @@ namespace sprout {
// ADL callable range_begin(cont) -> range_begin(cont)
// [default]
// Container is T[N] -> iterator(cont)
// otherwise, ADL callable begin(cont) -> begin(cont)
// otherwise, callabe cont.begin() -> cont.begin()
// otherwise, Container is not const
// && sprout::is_const_iterator_cast_convertible<const_iterator, iterator>
// && (callable sprout::as_const(cont).begin()
// || ADL(without sprout) callable begin(sprout::as_const(cont))
// )
// -> sprout::const_iterator_cast<iterator>(sprout::begin(sprout::as_const(cont)))
// otherwise, callable cont.begin() -> cont.begin()
// otherwise, ADL(without sprout) callable begin(cont) -> begin(cont)
// otherwise -> std::begin(cont)
//
template<typename Container>

View file

@ -15,11 +15,14 @@
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/is_const_cast_convertible.hpp>
#include <sprout/type_traits/is_within_namespace_sprout.hpp>
#include <sprout/container/traits_fwd.hpp>
#include <sprout/container/container_traits.hpp>
#include <sprout/container/range_functions_fwd.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/iterator/const_iterator_cast.hpp>
#include <sprout/utility/as_const.hpp>
#include <sprout/adl/not_found.hpp>
namespace sprout_adl {
@ -132,30 +135,34 @@ namespace sprout {
{};
#endif
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
range_adl_begin(Container& cont) {
using std::begin;
return begin(cont);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
range_adl_begin(Container const& cont) {
using std::begin;
return begin(cont);
}
template<typename T>
struct is_substitutable_const_begin
: public sprout::bool_constant<
sprout::is_const_iterator_cast_convertible<
typename sprout::container_traits<T const>::iterator,
typename sprout::container_traits<T>::iterator
>::value
&& (
sprout::detail::has_mem_begin<T const>::value
|| sprout::detail::has_adl_begin_without_sprout<T const&>::value
)
>
{};
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::detail::has_adl_begin_without_sprout<Container&>::value,
sprout::detail::is_substitutable_const_begin<Container>::value,
typename sprout::container_traits<Container>::iterator
>::type
range_begin_impl(Container& cont) {
return sprout_container_range_detail::range_adl_begin(cont);
typedef typename sprout::container_traits<Container>::iterator type;
return sprout::const_iterator_cast<type>(sprout::begin(sprout::as_const(cont)));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_adl_begin_without_sprout<Container&>::value && sprout::detail::has_mem_begin<Container>::value,
!sprout::detail::is_substitutable_const_begin<Container>::value
&& sprout::detail::has_mem_begin<Container>::value
,
typename sprout::container_traits<Container>::iterator
>::type
range_begin_impl(Container& cont) {
@ -163,7 +170,21 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_adl_begin_without_sprout<Container&>::value && !sprout::detail::has_mem_begin<Container>::value,
!sprout::detail::is_substitutable_const_begin<Container>::value
&& !sprout::detail::has_mem_begin<Container>::value
&& sprout::detail::has_adl_begin_without_sprout<Container&>::value
,
typename sprout::container_traits<Container>::iterator
>::type
range_begin_impl(Container& cont) {
return sprout_container_range_detail::range_adl_begin(cont);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::is_substitutable_const_begin<Container>::value
&& !sprout::detail::has_mem_begin<Container>::value
&& !sprout::detail::has_adl_begin_without_sprout<Container&>::value
,
typename sprout::container_traits<Container>::iterator
>::type
range_begin_impl(Container& cont) {
@ -171,15 +192,7 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::detail::has_adl_begin_without_sprout<Container const&>::value,
typename sprout::container_traits<Container const>::iterator
>::type
range_begin_impl(Container const& cont) {
return sprout_container_range_detail::range_adl_begin(cont);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_adl_begin_without_sprout<Container const&>::value && sprout::detail::has_mem_begin<Container const>::value,
sprout::detail::has_mem_begin<Container const>::value,
typename sprout::container_traits<Container const>::iterator
>::type
range_begin_impl(Container const& cont) {
@ -187,7 +200,19 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_adl_begin_without_sprout<Container const&>::value && !sprout::detail::has_mem_begin<Container const>::value,
!sprout::detail::has_mem_begin<Container const>::value
&& sprout::detail::has_adl_begin_without_sprout<Container const&>::value
,
typename sprout::container_traits<Container const>::iterator
>::type
range_begin_impl(Container const& cont) {
return sprout_container_range_detail::range_adl_begin(cont);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_mem_begin<Container const>::value
&& !sprout::detail::has_adl_begin_without_sprout<Container const&>::value
,
typename sprout::container_traits<Container const>::iterator
>::type
range_begin_impl(Container const& cont) {
@ -236,22 +261,34 @@ namespace sprout {
{};
#endif
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
range_adl_end(Container& cont) {
using std::end;
return end(cont);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
range_adl_end(Container const& cont) {
using std::end;
return end(cont);
}
template<typename T>
struct is_substitutable_const_end
: public sprout::bool_constant<
sprout::is_const_iterator_cast_convertible<
typename sprout::container_traits<T const>::iterator,
typename sprout::container_traits<T>::iterator
>::value
&& (
sprout::detail::has_mem_end<T const>::value
|| sprout::detail::has_adl_end_without_sprout<T const&>::value
)
>
{};
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::detail::has_adl_end_without_sprout<Container&>::value,
sprout::detail::is_substitutable_const_end<Container>::value,
typename sprout::container_traits<Container>::iterator
>::type
range_end_impl(Container& cont) {
typedef typename sprout::container_traits<Container>::iterator type;
return sprout::const_iterator_cast<type>(sprout::end(sprout::as_const(cont)));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::is_substitutable_const_end<Container>::value
&& sprout::detail::has_adl_end_without_sprout<Container&>::value
,
typename sprout::container_traits<Container>::iterator
>::type
range_end_impl(Container& cont) {
@ -259,7 +296,10 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_adl_end_without_sprout<Container&>::value && sprout::detail::has_mem_end<Container>::value,
!sprout::detail::is_substitutable_const_end<Container>::value
&& !sprout::detail::has_adl_end_without_sprout<Container&>::value
&& sprout::detail::has_mem_end<Container>::value
,
typename sprout::container_traits<Container>::iterator
>::type
range_end_impl(Container& cont) {
@ -267,7 +307,10 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_adl_end_without_sprout<Container&>::value && !sprout::detail::has_mem_end<Container>::value,
!sprout::detail::is_substitutable_const_end<Container>::value
&& !sprout::detail::has_adl_end_without_sprout<Container&>::value
&& !sprout::detail::has_mem_end<Container>::value
,
typename sprout::container_traits<Container>::iterator
>::type
range_end_impl(Container& cont) {
@ -398,9 +441,35 @@ namespace sprout {
{};
#endif
template<typename T>
struct is_substitutable_const_front
: public sprout::bool_constant<
sprout::is_const_cast_convertible<
typename sprout::container_traits<T const>::reference,
typename sprout::container_traits<T>::reference
>::value
&& (
sprout::detail::has_mem_front<T const>::value
|| sprout::detail::has_mem_begin<T const>::value
|| sprout::detail::has_adl_begin_without_sprout<T const&>::value
)
>
{};
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::detail::has_mem_front<Container>::value,
sprout::detail::is_substitutable_const_front<Container>::value,
typename sprout::container_traits<Container>::reference
>::type
range_front_impl(Container& cont) {
typedef typename sprout::container_traits<Container>::reference type;
return const_cast<type>(sprout::front(sprout::as_const(cont)));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::is_substitutable_const_front<Container>::value
&& sprout::detail::has_mem_front<Container>::value
,
typename sprout::container_traits<Container>::reference
>::type
range_front_impl(Container& cont) {
@ -408,7 +477,9 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_mem_front<Container>::value,
!sprout::detail::is_substitutable_const_front<Container>::value
&& !sprout::detail::has_mem_front<Container>::value
,
typename sprout::container_traits<Container>::reference
>::type
range_front_impl(Container& cont) {
@ -453,9 +524,35 @@ namespace sprout {
{};
#endif
template<typename T>
struct is_substitutable_const_back
: public sprout::bool_constant<
sprout::is_const_cast_convertible<
typename sprout::container_traits<T const>::reference,
typename sprout::container_traits<T>::reference
>::value
&& (
sprout::detail::has_mem_back<T const>::value
|| sprout::detail::has_mem_begin<T const>::value
|| sprout::detail::has_adl_begin_without_sprout<T const&>::value
)
>
{};
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::detail::has_mem_back<Container>::value,
sprout::detail::is_substitutable_const_back<Container>::value,
typename sprout::container_traits<Container>::reference
>::type
range_back_impl(Container& cont) {
typedef typename sprout::container_traits<Container>::reference type;
return const_cast<type>(sprout::back(sprout::as_const(cont)));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::is_substitutable_const_back<Container>::value
&& sprout::detail::has_mem_back<Container>::value
,
typename sprout::container_traits<Container>::reference
>::type
range_back_impl(Container& cont) {
@ -463,7 +560,9 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_mem_back<Container>::value,
!sprout::detail::is_substitutable_const_back<Container>::value
&& !sprout::detail::has_mem_back<Container>::value
,
typename sprout::container_traits<Container>::reference
>::type
range_back_impl(Container& cont) {
@ -508,9 +607,35 @@ namespace sprout {
{};
#endif
template<typename T>
struct is_substitutable_const_at
: public sprout::bool_constant<
sprout::is_const_cast_convertible<
typename sprout::container_traits<T const>::reference,
typename sprout::container_traits<T>::reference
>::value
&& (
sprout::detail::has_mem_at<T const>::value
|| sprout::detail::has_mem_begin<T const>::value
|| sprout::detail::has_adl_begin_without_sprout<T const&>::value
)
>
{};
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::detail::has_mem_at<Container>::value,
sprout::detail::is_substitutable_const_at<Container>::value,
typename sprout::container_traits<Container>::reference
>::type
range_at_impl(Container& cont, typename sprout::container_traits<Container>::size_type i) {
typedef typename sprout::container_traits<Container>::reference type;
return const_cast<type>(sprout::at(sprout::as_const(cont), i));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::is_substitutable_const_at<Container>::value
&& sprout::detail::has_mem_at<Container>::value
,
typename sprout::container_traits<Container>::reference
>::type
range_at_impl(Container& cont, typename sprout::container_traits<Container>::size_type i) {
@ -518,7 +643,9 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_mem_at<Container>::value,
!sprout::detail::is_substitutable_const_at<Container>::value
&& !sprout::detail::has_mem_at<Container>::value
,
typename sprout::container_traits<Container>::reference
>::type
range_at_impl(Container& cont, typename sprout::container_traits<Container>::size_type i) {
@ -563,9 +690,35 @@ namespace sprout {
{};
#endif
template<typename T>
struct is_substitutable_const_nth
: public sprout::bool_constant<
sprout::is_const_iterator_cast_convertible<
typename sprout::container_traits<T const>::iterator,
typename sprout::container_traits<T>::iterator
>::value
&& (
sprout::detail::has_mem_nth<T const>::value
|| sprout::detail::has_mem_begin<T const>::value
|| sprout::detail::has_adl_begin_without_sprout<T const&>::value
)
>
{};
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::detail::has_mem_nth<Container>::value,
sprout::detail::is_substitutable_const_nth<Container>::value,
typename sprout::container_traits<Container>::iterator
>::type
range_nth_impl(Container& cont, typename sprout::container_traits<Container>::size_type i) {
typedef typename sprout::container_traits<Container>::iterator type;
return sprout::const_iterator_cast<type>(sprout::nth(sprout::as_const(cont), i));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::is_substitutable_const_nth<Container>::value
&& sprout::detail::has_mem_nth<Container>::value
,
typename sprout::container_traits<Container>::iterator
>::type
range_nth_impl(Container& cont, typename sprout::container_traits<Container>::size_type i) {
@ -573,7 +726,9 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_mem_nth<Container>::value,
!sprout::detail::is_substitutable_const_nth<Container>::value
&& !sprout::detail::has_mem_nth<Container>::value
,
typename sprout::container_traits<Container>::iterator
>::type
range_nth_impl(Container& cont, typename sprout::container_traits<Container>::size_type i) {
@ -618,9 +773,35 @@ namespace sprout {
{};
#endif
template<typename T>
struct is_substitutable_const_index_of
: public sprout::bool_constant<
sprout::is_const_iterator_cast_convertible<
typename sprout::container_traits<T const>::iterator,
typename sprout::container_traits<T>::iterator
>::value
&& (
sprout::detail::has_mem_index_of<T const>::value
|| sprout::detail::has_mem_begin<T const>::value
|| sprout::detail::has_adl_begin_without_sprout<T const&>::value
)
>
{};
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::detail::has_mem_index_of<Container>::value,
sprout::detail::is_substitutable_const_index_of<Container>::value,
typename sprout::container_traits<Container>::size_type
>::type
range_index_of_impl(Container& cont, typename sprout::container_traits<Container>::iterator p) {
typedef typename sprout::container_traits<Container>::iterator type;
return sprout::index_of(sprout::as_const(cont), sprout::const_iterator_cast<type>(p));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::is_substitutable_const_index_of<Container>::value
&& sprout::detail::has_mem_index_of<Container>::value
,
typename sprout::container_traits<Container>::size_type
>::type
range_index_of_impl(Container& cont, typename sprout::container_traits<Container>::iterator p) {
@ -628,7 +809,9 @@ namespace sprout {
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::has_mem_index_of<Container>::value,
!sprout::detail::is_substitutable_const_index_of<Container>::value
&& !sprout::detail::has_mem_index_of<Container>::value
,
typename sprout::container_traits<Container>::size_type
>::type
range_index_of_impl(Container& cont, typename sprout::container_traits<Container>::iterator p) {
@ -650,6 +833,62 @@ namespace sprout {
range_index_of_impl(Container const& cont, typename sprout::container_traits<Container const>::iterator p) {
return sprout::distance(sprout::begin(cont), p);
}
template<typename T>
struct has_mem_data_test {
public:
template<
typename U = T,
typename = typename sprout::identity<decltype(std::declval<U>().data())>::type
>
static sprout::true_type test(int);
static sprout::false_type test(...);
};
#if defined(_MSC_VER) && (_MSC_VER > 1900)
template<typename T, typename Base_ = typename sprout::identity<decltype(sprout::detail::has_mem_data_test<T>::test(0))>::type>
struct has_mem_data
: public Base_
{};
#else
template<typename T>
struct has_mem_data
: public sprout::identity<decltype(sprout::detail::has_mem_data_test<T>::test(0))>::type
{};
#endif
template<typename T>
struct is_substitutable_const_data
: public sprout::bool_constant<
sprout::is_const_cast_convertible<
typename sprout::container_traits<T const>::pointer,
typename sprout::container_traits<T>::pointer
>::value
&& sprout::detail::has_mem_data<T const>::value
>
{};
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::detail::is_substitutable_const_data<Container>::value,
typename sprout::container_traits<Container>::pointer
>::type
range_data_impl(Container& cont) {
typedef typename sprout::container_traits<Container>::pointer type;
return const_cast<type>(sprout::data(sprout::as_const(cont)));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<
!sprout::detail::is_substitutable_const_data<Container>::value,
typename sprout::container_traits<Container>::pointer
>::type
range_data_impl(Container& cont) {
return cont.data();
}
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::pointer
range_data_impl(Container const& cont) {
return cont.data();
}
} // namespace detail
} // namespace sprout
@ -746,12 +985,12 @@ namespace sprout_container_range_detail {
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::pointer
range_data(Container& cont) {
return cont.data();
return sprout::detail::range_data_impl(cont);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::pointer
range_data(Container const& cont) {
return cont.data();
return sprout::detail::range_data_impl(cont);
}
} // namespace sprout_container_range_detail
@ -1084,5 +1323,10 @@ namespace sprout {
#include <sprout/container/begin.hpp>
#include <sprout/container/end.hpp>
#include <sprout/container/size.hpp>
#include <sprout/container/front.hpp>
#include <sprout/container/back.hpp>
#include <sprout/container/nth.hpp>
#include <sprout/container/index_of.hpp>
#include <sprout/container/data.hpp>
#endif // #ifndef SPROUT_CONTAINER_CONTAINER_RANGE_TRAITS_HPP

View file

@ -23,6 +23,10 @@ namespace sprout {
// ADL callable range_data(cont) -> range_data(cont)
// [default]
// Container is T[N] -> pointer(cont)
// otherwise, Container is not const
// && sprout::is_const_cast_convertible<const_pointer, pointer>
// && callable sprout::as_const(cont).data()
// -> const_cast<pointer>(sprout::data(sprout::as_const(cont)))
// cont.data()
//
template<typename Container>

View file

@ -23,8 +23,14 @@ namespace sprout {
// ADL callable range_end(cont) -> range_end(cont)
// [default]
// Container is T[N] -> iterator(cont)
// otherwise, ADL callable end(cont) -> end(cont)
// otherwise, callabe cont.end() -> cont.end()
// otherwise, Container is not const
// && sprout::is_const_iterator_cast_convertible<const_iterator, iterator>
// && (callable sprout::as_const(cont).end()
// || ADL(without sprout) callable end(sprout::as_const(cont))
// )
// -> sprout::const_iterator_cast<iterator>(sprout::end(sprout::as_const(cont)))
// otherwise, callable cont.end() -> cont.end()
// otherwise, ADL(without sprout) callable end(cont) -> end(cont)
// otherwise -> std::end(cont)
//
template<typename Container>

View file

@ -23,6 +23,13 @@ namespace sprout {
// ADL callable range_front(cont) -> range_front(cont)
// [default]
// Container is T[N] -> cont[0]
// otherwise, Container is not const
// && sprout::is_const_cast_convertible<const_reference, reference>
// && (callable sprout::as_const(cont).front()
// || callable sprout::as_const(cont).begin()
// || ADL(without sprout) callable begin(sprout::as_const(cont))
// )
// -> const_cast<reference>(sprout::front(sprout::as_const(cont)))
// otherwise, callable cont.front() -> cont.front()
// otherwise -> *sprout::begin(cont)
//

View file

@ -23,8 +23,15 @@ namespace sprout {
// ADL callable range_index_of(cont, p) -> range_index_of(cont, p)
// [default]
// Container is T[N] -> p - iterator(cont)
// otherwise, Container is not const
// && sprout::is_const_iterator_cast_convertible<const_iterator, iterator>
// && (callable sprout::as_const(cont).index_of(p)
// || callable sprout::as_const(cont).begin()
// || ADL(without sprout) callable begin(sprout::as_const(cont))
// )
// -> sprout::index_of(sprout::as_const(cont), sprout::const_iterator_cast<iterator>(p))
// otherwise, callable cont.index_of(p) -> cont.index_of(p)
// otherwise -> sprout::distance(begin(cont), p)
// otherwise -> sprout::distance(sprout::begin(cont), p)
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::size_type

View file

@ -23,6 +23,13 @@ namespace sprout {
// ADL callable range_nth(cont, i) -> range_nth(cont, i)
// [default]
// Container is T[N] -> iterator(cont) + i
// otherwise, Container is not const
// && sprout::is_const_iterator_cast_convertible<const_iterator, iterator>
// && (callable sprout::as_const(cont).nth(i)
// || callable sprout::as_const(cont).begin()
// || ADL(without sprout) callable begin(sprout::as_const(cont))
// )
// -> sprout::const_iterator_cast<iterator>(sprout::nth(sprout::as_const(cont), i))
// otherwise, callable cont.nth(i) -> cont.nth(i)
// otherwise -> sprout::next(sprout::begin(cont), i)
//

View file

@ -11,6 +11,7 @@
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/is_same.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/adl/not_found.hpp>
@ -21,7 +22,7 @@ namespace sprout {
//
template<typename From, typename To>
struct is_const_iterator_cast_convertible
: public sprout::false_type
: public sprout::is_same<typename std::remove_cv<From>::type, typename std::remove_cv<To>::type>
{};
template<typename From, typename To>
struct is_const_iterator_cast_convertible<From, To const>
@ -105,6 +106,11 @@ namespace sprout {
const_iterator_conversion(U* it) {
return const_cast<T>(it);
}
template<typename T>
inline SPROUT_CONSTEXPR T
const_iterator_conversion(T const& it) {
return it;
}
} // namespace iterator_detail
} // namespace sprout

View file

@ -0,0 +1,43 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_TYPE_TRAITS_IS_CONST_CAST_CONVERTIBLE_HPP
#define SPROUT_TYPE_TRAITS_IS_CONST_CAST_CONVERTIBLE_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/integral_constant.hpp>
namespace sprout {
//
// is_const_cast_convertible
//
namespace detail {
template<typename From, typename To>
struct is_const_cast_convertible_test {
public:
template<
typename FromU = From,
typename = typename sprout::identity<decltype(const_cast<To>(std::declval<FromU>()))>::type
>
static sprout::true_type test(int);
static sprout::false_type test(...);
};
} // namespace detail
template<typename From, typename To>
struct is_const_cast_convertible
: public sprout::identity<decltype(sprout::detail::is_const_cast_convertible_test<From, To>::test(0))>::type
{};
#if SPROUT_USE_VARIABLE_TEMPLATES
template<typename From, typename To>
SPROUT_STATIC_CONSTEXPR bool is_const_cast_convertible_v = sprout::is_const_cast_convertible<From, To>::value;
#endif // #if SPROUT_USE_VARIABLE_TEMPLATES
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_IS_CONST_CAST_CONVERTIBLE_HPP

View file

@ -14,6 +14,7 @@
#include <sprout/type_traits/is_base_of.hpp>
#include <sprout/type_traits/is_convertible.hpp>
#include <sprout/type_traits/is_const_cast_convertible.hpp>
#include <sprout/type_traits/is_convert_constructible.hpp>
#include <sprout/type_traits/is_nullptr_cast.hpp>
#include <sprout/type_traits/is_upcast.hpp>

View file

@ -13,6 +13,7 @@
#include <testspr/algorithm.hpp>
#include <testspr/iterator.hpp>
#include <testspr/range.hpp>
#include <testspr/utility.hpp>
#include <testspr/typeinfo.hpp>
#include <testspr/print.hpp>

49
testspr/utility.hpp Normal file
View file

@ -0,0 +1,49 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef TESTSPR_UTILITY_HPP
#define TESTSPR_UTILITY_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/as_non_const.hpp>
namespace testspr {
//
// as_const
//
template<typename T>
inline SPROUT_CONSTEXPR typename std::conditional<
std::is_lvalue_reference<T>::value,
typename std::remove_reference<T>::type const&,
typename std::remove_reference<T>::type const&&
>::type
as_const(T&& t) {
return SPROUT_FORWARD(T, t);
}
//
// as_non_const
//
template<typename T>
inline SPROUT_CONSTEXPR typename std::conditional<
std::is_lvalue_reference<T>::value,
typename std::remove_const<typename std::remove_reference<T>::type>::type&,
typename std::remove_const<typename std::remove_reference<T>::type>::type&&
>::type
as_non_const(T&& t) {
typedef typename std::conditional<
std::is_lvalue_reference<T>::value,
typename std::remove_const<typename std::remove_reference<T>::type>::type&,
typename std::remove_const<typename std::remove_reference<T>::type>::type&&
>::type type;
return const_cast<type>(t);
}
} // namespace testspr
#endif // #ifndef TESTSPR_UTILITY_HPP