/*============================================================================= 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_BACK_HPP #define SPROUT_CONTAINER_BACK_HPP #include #include #include #include namespace sprout { // // back // // effect: // sprout::container_range_traits::range_back(cont) // [default] // 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 // && (callable sprout::as_const(cont).back() // || callable sprout::as_const(cont).begin() // || ADL(without sprout) callable begin(sprout::as_const(cont)) // ) // -> const_cast(sprout::back(sprout::as_const(cont))) // otherwise, callable cont.back() -> cont.back() // otherwise -> *sprout::next(sprout::begin(cont), sprout::size(cont) - 1) // template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference back(Container& cont) { return sprout::container_range_traits::range_back(cont); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference back(Container const& cont) { return sprout::container_range_traits::range_back(cont); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference back(T (& arr)[N]) { return sprout::container_range_traits::range_back(arr); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference back(T const (& arr)[N]) { return sprout::container_range_traits::range_back(arr); } // // cback // template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference cback(Container const& cont) { return sprout::back(cont); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference cback(T const (& arr)[N]) { return sprout::back(arr); } } // namespace sprout #include #endif // #ifndef SPROUT_CONTAINER_BACK_HPP