Sprout/sprout/container/at.hpp

77 lines
3.3 KiB
C++
Raw Normal View History

/*=============================================================================
2016-02-25 09:48:28 +00:00
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_AT_HPP
#define SPROUT_CONTAINER_AT_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 {
//
// at
//
// effect:
2016-04-10 04:48:41 +00:00
// sprout::container_range_traits<Container>::range_at(cont, i)
// [default]
2016-04-10 04:48:41 +00:00
// ADL callable range_at(cont, i) -> range_at(cont, i)
// [default]
2016-04-17 15:34:15 +00:00
// Container is T[N] -> cont[sprout::range_index_check(cont, i)]
2016-04-17 07:11:43 +00:00
// otherwise, Container is not const
// && sprout::is_const_cast_convertible<const_reference, reference>
// && (callable sprout::as_const(cont).at(i)
2016-04-17 10:36:56 +00:00
// || callable sprout::as_const(cont)[i]
2016-04-17 07:11:43 +00:00
// || callable sprout::as_const(cont).begin()
// || ADL(without sprout) callable begin(sprout::as_const(cont))
// )
// -> const_cast<reference>(sprout::at(sprout::as_const(cont), i))
2016-04-14 11:14:49 +00:00
// otherwise, callable cont.at(i) -> cont.at(i)
2016-04-17 10:36:56 +00:00
// otherwise, callable cont[i] -> cont[sprout::range_index_check(cont, i)]
// otherwise -> *sprout::next(sprout::begin(cont), sprout::range_index_check(cont, i))
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::reference
at(Container& cont, typename sprout::container_traits<Container>::size_type i) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<Container>::range_at(cont, i);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::reference
at(Container const& cont, typename sprout::container_traits<Container const>::size_type i) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<Container const>::range_at(cont, i);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::reference
at(T (& arr)[N], typename sprout::container_traits<T[N]>::size_type i) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<T[N]>::range_at(arr, i);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::reference
at(T const (& arr)[N], typename sprout::container_traits<T const[N]>::size_type i) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<T const[N]>::range_at(arr, i);
}
//
// cat
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::reference
cat(Container const& cont, typename sprout::container_traits<Container const>::size_type i) {
return sprout::at(cont, i);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::reference
cat(T const (& arr)[N], typename sprout::container_traits<T const[N]>::size_type i) {
return sprout::at(arr, i);
}
} // namespace sprout
#include <sprout/container/container_range_traits.hpp>
#endif // #ifndef SPROUT_CONTAINER_AT_HPP