From 92cc7881d659aafb26694be73eeeb62796e33c65 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 16 Apr 2016 20:12:55 +0900 Subject: [PATCH] change sprout::array adapt --- sprout/array/array.hpp | 42 ++++++++++ sprout/container/boost/array.hpp | 82 ++++++++++++++++--- sprout/container/std/array.hpp | 5 +- sprout/container/std/complex.hpp | 1 - .../type_traits/is_within_tag_namespace.hpp | 4 +- 5 files changed, 117 insertions(+), 17 deletions(-) diff --git a/sprout/array/array.hpp b/sprout/array/array.hpp index e1e7ee1b..bd944814 100644 --- a/sprout/array/array.hpp +++ b/sprout/array/array.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -281,6 +282,47 @@ namespace sprout { lhs.swap(rhs); } + template + inline SPROUT_CONSTEXPR typename sprout::array::iterator + range_begin(sprout::array& t) SPROUT_NOEXCEPT { + return sprout::const_iterator_cast::iterator>(sprout::as_const(t).begin()); + } + template + inline SPROUT_CONSTEXPR typename sprout::array::iterator + range_end(sprout::array& t) SPROUT_NOEXCEPT { + return sprout::const_iterator_cast::iterator>(sprout::as_const(t).end()); + } + template + inline SPROUT_CONSTEXPR typename sprout::array::reference + range_at(sprout::array& t, typename sprout::array::size_type i) { + return const_cast::reference>(sprout::as_const(t).at(i)); + } + template + inline SPROUT_CONSTEXPR typename sprout::array::reference + range_front(sprout::array& t) { + return const_cast::reference>(sprout::as_const(t).front()); + } + template + inline SPROUT_CONSTEXPR typename sprout::array::reference + range_back(sprout::array& t) { + return const_cast::reference>(sprout::as_const(t).back()); + } + template + inline SPROUT_CONSTEXPR typename sprout::array::iterator + range_nth(sprout::array& t, typename sprout::array::size_type i) { + return sprout::const_iterator_cast::iterator>(sprout::as_const(t).nth(i)); + } + template + inline SPROUT_CONSTEXPR typename sprout::array::size_type + range_index_of(sprout::array& t, typename sprout::array::iterator p) SPROUT_NOEXCEPT { + return sprout::as_const(t).index_of(p); + } + template + inline SPROUT_CONSTEXPR typename sprout::array::pointer + range_data(sprout::array& t) SPROUT_NOEXCEPT { + return const_cast::pointer>(sprout::as_const(t).data()); + } + // // to_array // diff --git a/sprout/container/boost/array.hpp b/sprout/container/boost/array.hpp index 8d7ea509..846fb1a2 100644 --- a/sprout/container/boost/array.hpp +++ b/sprout/container/boost/array.hpp @@ -8,17 +8,35 @@ #ifndef SPROUT_CONTAINER_BOOST_ARRAY_HPP #define SPROUT_CONTAINER_BOOST_ARRAY_HPP +#include #include #include -#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION -# include -# include -# include -# include -#endif +#include +#include +#include +#include +#include +#include -#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION namespace sprout { + namespace detail { + template + struct elems_subscript; + template<> + struct elems_subscript + : public sprout::transparent<> + { + public: + template + SPROUT_CONSTEXPR decltype(std::declval().elems[std::declval()]) + operator()(T&& x, U&& y) + const SPROUT_NOEXCEPT_IF_EXPR(std::declval().elems[std::declval()]) + { + return SPROUT_FORWARD(T, x).elems[SPROUT_FORWARD(U, y)]; + } + }; + } // namespace detail + // // container_traits // @@ -27,8 +45,8 @@ namespace sprout { : public sprout::detail::container_traits_default > { public: - typedef sprout::index_iterator&, true> iterator; - typedef sprout::index_iterator const&, true> const_iterator; + typedef sprout::index_iterator&, true, sprout::detail::elems_subscript<> > iterator; + typedef sprout::index_iterator const&, true, sprout::detail::elems_subscript<> > const_iterator; }; // @@ -39,6 +57,7 @@ namespace sprout { : public sprout::detail::container_range_traits_default > { public: + // iterators: static SPROUT_CONSTEXPR typename sprout::container_traits >::iterator range_begin(boost::array& cont) { return typename sprout::container_traits >::iterator(cont, 0); @@ -47,7 +66,6 @@ namespace sprout { range_begin(boost::array const& cont) { return typename sprout::container_traits const>::iterator(cont, 0); } - static SPROUT_CONSTEXPR typename sprout::container_traits >::iterator range_end(boost::array& cont) { return typename sprout::container_traits >::iterator(cont, cont.size()); @@ -56,8 +74,50 @@ namespace sprout { range_end(boost::array const& cont) { return typename sprout::container_traits const>::iterator(cont, cont.size()); } + // capacity: + static SPROUT_CONSTEXPR typename sprout::container_traits const>::size_type + range_size(boost::array const& cont) { + return N; + } + static SPROUT_CONSTEXPR typename sprout::container_traits const>::size_type + range_empty(boost::array const& cont) { + return N != 0; + } + // element access: + static SPROUT_CONSTEXPR typename sprout::container_traits >::reference + range_front(boost::array& cont) { + return cont.elems[0]; + } + static SPROUT_CONSTEXPR typename sprout::container_traits const>::reference + range_front(boost::array const& cont) { + return cont.elems[0]; + } + static SPROUT_CONSTEXPR typename sprout::container_traits >::reference + range_back(boost::array& cont) { + return cont.elems[N - 1]; + } + static SPROUT_CONSTEXPR typename sprout::container_traits const>::reference + range_back(boost::array const& cont) { + return cont.elems[N - 1]; + } + static SPROUT_CONSTEXPR typename sprout::container_traits >::reference + range_at(boost::array& cont, typename sprout::container_traits >::size_type i) { + return cont.elems[i]; + } + static SPROUT_CONSTEXPR typename sprout::container_traits const>::reference + range_at(boost::array const& cont, typename sprout::container_traits const>::size_type i) { + return cont.elems[i]; + } + // data access: + static SPROUT_CONSTEXPR typename sprout::container_traits >::pointer + range_data(boost::array& cont) { + return cont.elems; + } + static SPROUT_CONSTEXPR typename sprout::container_traits const>::pointer + range_data(boost::array const& cont) { + return cont.elems; + } }; } // namespace sprout -#endif #endif // #ifndef SPROUT_CONTAINER_BOOST_ARRAY_HPP diff --git a/sprout/container/std/array.hpp b/sprout/container/std/array.hpp index 3c4d84ae..4e312940 100644 --- a/sprout/container/std/array.hpp +++ b/sprout/container/std/array.hpp @@ -32,10 +32,9 @@ namespace sprout { template SPROUT_CONSTEXPR decltype(std::declval()[std::declval()]) operator()(T&& x, U&& y) - const SPROUT_NOEXCEPT_IF_EXPR(std::declval()[std::declval()]) + const SPROUT_NOEXCEPT_IF_EXPR(const_cast()[std::declval()])>(sprout::as_const(std::declval())[std::declval()])) { - typedef decltype(std::declval()[std::declval()]) type; - return const_cast(sprout::as_const(x)[SPROUT_FORWARD(U, y)]); + return const_cast()[std::declval()])>(sprout::as_const(x)[SPROUT_FORWARD(U, y)]); } }; } // namespace detail diff --git a/sprout/container/std/complex.hpp b/sprout/container/std/complex.hpp index 01816451..9ab2bdde 100644 --- a/sprout/container/std/complex.hpp +++ b/sprout/container/std/complex.hpp @@ -74,7 +74,6 @@ namespace sprout { range_begin(std::complex const& cont) { return typename sprout::container_traits const>::iterator(cont, 0); } - static SPROUT_CONSTEXPR typename sprout::container_traits >::iterator range_end(std::complex& cont) { return typename sprout::container_traits >::iterator(cont, 2); diff --git a/sprout/type_traits/is_within_tag_namespace.hpp b/sprout/type_traits/is_within_tag_namespace.hpp index 7689547a..a3cc667c 100644 --- a/sprout/type_traits/is_within_tag_namespace.hpp +++ b/sprout/type_traits/is_within_tag_namespace.hpp @@ -30,7 +30,7 @@ #define SPROUT_ADL_TESTER_DECL(NAME) \ SPROUT_ADL_TEST_TAG_DECL(NAME); \ template \ - void sprout_adl_tester(sprout_adl_test::SPROUT_PP_CAT(NAME, _tag)&&, T&&) + void sprout_adl_tester(sprout_adl_test::SPROUT_PP_CAT(NAME, _tag)*&&, T&&) // // SPROUT_ADL_TEST_TAG @@ -68,7 +68,7 @@ namespace sprout_adl_tester_detail { public: template< typename Tag0 = Tag, typename U = T, - typename R = typename sprout::identity(), std::declval()))>::type + typename R = typename sprout::identity(), std::declval()))>::type > static sprout::is_found_via_adl test(int); static sprout::false_type test(...);