1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-12-03 21:15:42 +00:00
Sprout/sprout/container/nth.hpp

68 lines
2.7 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_NTH_HPP
#define SPROUT_CONTAINER_NTH_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 {
//
// nth
//
// effect:
2016-04-10 04:48:41 +00:00
// sprout::container_range_traits<Container>::range_nth(cont, i)
// [default]
2016-04-10 04:48:41 +00:00
// ADL callable range_nth(cont, i) -> range_nth(cont, i)
// [default]
// Container is T[N] -> iterator(cont) + i
2016-04-14 11:14:49 +00:00
// otherwise, callable cont.nth(i) -> cont.nth(i)
2016-04-10 04:48:41 +00:00
// otherwise -> sprout::next(sprout::begin(cont), i)
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
nth(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_nth(cont, i);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
nth(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_nth(cont, i);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::iterator
nth(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_nth(arr, i);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::iterator
nth(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_nth(arr, i);
}
//
// cnth
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
cnth(Container const& cont, typename sprout::container_traits<Container const>::size_type i) {
return sprout::nth(cont, i);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::iterator
cnth(T const (& arr)[N], typename sprout::container_traits<T const[N]>::size_type i) {
return sprout::nth(arr, i);
}
} // namespace sprout
#include <sprout/container/container_range_traits.hpp>
#endif // #ifndef SPROUT_CONTAINER_NTH_HPP