2014-07-12 09:04:45 +00:00
|
|
|
/*=============================================================================
|
2019-01-07 08:47:17 +00:00
|
|
|
Copyright (c) 2011-2019 Bolero MURAKAMI
|
2014-07-12 09:04:45 +00:00
|
|
|
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_FRONT_HPP
|
|
|
|
#define SPROUT_CONTAINER_FRONT_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 {
|
|
|
|
//
|
|
|
|
// front
|
|
|
|
//
|
|
|
|
// effect:
|
2016-04-10 04:48:41 +00:00
|
|
|
// sprout::container_range_traits<Container>::range_front(cont)
|
2014-07-12 09:04:45 +00:00
|
|
|
// [default]
|
2016-04-10 04:48:41 +00:00
|
|
|
// ADL callable range_front(cont) -> range_front(cont)
|
|
|
|
// [default]
|
|
|
|
// Container is T[N] -> cont[0]
|
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).front()
|
|
|
|
// || 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::front(sprout::as_const(cont)))
|
2016-04-14 11:14:49 +00:00
|
|
|
// otherwise, callable cont.front() -> cont.front()
|
2016-04-10 04:48:41 +00:00
|
|
|
// otherwise -> *sprout::begin(cont)
|
2014-07-12 09:04:45 +00:00
|
|
|
//
|
|
|
|
template<typename Container>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::reference
|
|
|
|
front(Container& cont) {
|
2016-04-10 04:48:41 +00:00
|
|
|
return sprout::container_range_traits<Container>::range_front(cont);
|
2014-07-12 09:04:45 +00:00
|
|
|
}
|
|
|
|
template<typename Container>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::reference
|
|
|
|
front(Container const& cont) {
|
2016-04-10 04:48:41 +00:00
|
|
|
return sprout::container_range_traits<Container const>::range_front(cont);
|
2014-07-12 09:04:45 +00:00
|
|
|
}
|
|
|
|
template<typename T, std::size_t N>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::reference
|
|
|
|
front(T (& arr)[N]) {
|
2016-04-10 04:48:41 +00:00
|
|
|
return sprout::container_range_traits<T[N]>::range_front(arr);
|
2014-07-12 09:04:45 +00:00
|
|
|
}
|
|
|
|
template<typename T, std::size_t N>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::reference
|
|
|
|
front(T const (& arr)[N]) {
|
2016-04-10 04:48:41 +00:00
|
|
|
return sprout::container_range_traits<T const[N]>::range_front(arr);
|
2014-07-12 09:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// cfront
|
|
|
|
//
|
|
|
|
template<typename Container>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::reference
|
|
|
|
cfront(Container const& cont) {
|
|
|
|
return sprout::front(cont);
|
|
|
|
}
|
|
|
|
template<typename T, std::size_t N>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::reference
|
|
|
|
cfront(T const (& arr)[N]) {
|
|
|
|
return sprout::front(arr);
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#include <sprout/container/container_range_traits.hpp>
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_CONTAINER_FRONT_HPP
|