/*============================================================================= Copyright (c) 2011-2019 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_SUBSCRIPT_AT_HPP #define SPROUT_CONTAINER_SUBSCRIPT_AT_HPP #include #include #include #include namespace sprout { // // subscript_at // // effect: // sprout::container_range_traits::range_subscript_at(cont, i) // [default] // ADL callable range_subscript_at(cont, i) -> range_subscript_at(cont, i) // [default] // Container is T[N] -> cont[i] // otherwise, Container is not const // && sprout::is_const_reference_cast_convertible // && (callable sprout::as_const(cont)[i] // || callable sprout::as_const(cont).begin() // || ADL(without sprout) callable begin(sprout::as_const(cont)) // ) // -> sprout::const_reference_cast(sprout::subscript_at(sprout::as_const(cont), i)) // otherwise, callable cont[i] -> cont[i] // otherwise -> *sprout::next(sprout::begin(cont), i) // template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference subscript_at(Container& cont, typename sprout::container_traits::size_type i) { return sprout::container_range_traits::range_subscript_at(cont, i); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference subscript_at(Container const& cont, typename sprout::container_traits::size_type i) { return sprout::container_range_traits::range_subscript_at(cont, i); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference subscript_at(T (& arr)[N], typename sprout::container_traits::size_type i) { return sprout::container_range_traits::range_subscript_at(arr, i); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference subscript_at(T const (& arr)[N], typename sprout::container_traits::size_type i) { return sprout::container_range_traits::range_subscript_at(arr, i); } // // csubscript_at // template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference csubscript_at(Container const& cont, typename sprout::container_traits::size_type i) { return sprout::subscript_at(cont, i); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference csubscript_at(T const (& arr)[N], typename sprout::container_traits::size_type i) { return sprout::subscript_at(arr, i); } } // namespace sprout #include #endif // #ifndef SPROUT_CONTAINER_SUBSCRIPT_AT_HPP