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

75 lines
2.8 KiB
C++
Raw Normal View History

/*=============================================================================
Copyright (c) 2011-2017 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 <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/container/traits_fwd.hpp>
#include <sprout/container/container_traits.hpp>
namespace sprout {
//
// back
//
// effect:
2016-04-10 04:48:41 +00:00
// sprout::container_range_traits<Container>::range_back(cont)
// [default]
2016-04-10 04:48:41 +00:00
// ADL callable range_back(cont) -> range_back(cont)
// [default]
// Container is T[N] -> cont[N - 1]
2016-04-17 07:11:43 +00:00
// otherwise, Container is not const
2016-04-19 00:05:41 +00:00
// && sprout::is_const_reference_cast_convertible<const_reference, reference>
2016-04-17 07:11:43 +00:00
// && (callable sprout::as_const(cont).back()
// || callable sprout::as_const(cont).begin()
// || ADL(without sprout) callable begin(sprout::as_const(cont))
// )
2016-04-19 00:05:41 +00:00
// -> sprout::const_reference_cast<reference>(sprout::back(sprout::as_const(cont)))
2016-04-14 11:14:49 +00:00
// otherwise, callable cont.back() -> cont.back()
2016-04-10 04:48:41 +00:00
// otherwise -> *sprout::next(sprout::begin(cont), sprout::size(cont) - 1)
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::reference
back(Container& cont) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<Container>::range_back(cont);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::reference
back(Container const& cont) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<Container const>::range_back(cont);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::reference
back(T (& arr)[N]) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<T[N]>::range_back(arr);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::reference
back(T const (& arr)[N]) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<T const[N]>::range_back(arr);
}
//
// cback
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::reference
cback(Container const& cont) {
return sprout::back(cont);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::reference
cback(T const (& arr)[N]) {
return sprout::back(arr);
}
} // namespace sprout
#include <sprout/container/container_range_traits.hpp>
#endif // #ifndef SPROUT_CONTAINER_BACK_HPP