/*============================================================================= 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_CONTAINER_BOOST_ARRAY_HPP #define SPROUT_CONTAINER_BOOST_ARRAY_HPP #include #include #include #include #include #include #include #include #include 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 // template struct container_traits > : public sprout::container_traits_default > { public: typedef sprout::index_iterator&, true, sprout::detail::elems_subscript<> > iterator; typedef sprout::index_iterator const&, true, sprout::detail::elems_subscript<> > const_iterator; }; // // container_range_traits // template struct container_range_traits > : public sprout::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); } static SPROUT_CONSTEXPR typename sprout::container_traits const>::iterator 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()); } static SPROUT_CONSTEXPR typename sprout::container_traits const>::iterator 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_subscript_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_subscript_at(boost::array const& cont, typename sprout::container_traits const>::size_type i) { return cont.elems[i]; } static SPROUT_CONSTEXPR typename sprout::container_traits >::reference range_at(boost::array& cont, typename sprout::container_traits >::size_type i) { return cont.elems[sprout::range_index_check(cont, 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[sprout::range_index_check(cont, 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 // #ifndef SPROUT_CONTAINER_BOOST_ARRAY_HPP