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

75 lines
3.2 KiB
C++
Raw Permalink Normal View History

/*=============================================================================
Copyright (c) 2011-2019 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_INDEX_OF_HPP
#define SPROUT_CONTAINER_INDEX_OF_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 {
//
// index_of
//
// effect:
2016-04-10 04:48:41 +00:00
// sprout::container_range_traits<Container>::range_index_of(cont, p)
// [default]
2016-04-10 04:48:41 +00:00
// ADL callable range_index_of(cont, p) -> range_index_of(cont, p)
// [default]
// Container is T[N] -> p - iterator(cont)
2016-04-17 07:11:43 +00:00
// otherwise, Container is not const
// && sprout::is_const_iterator_cast_convertible<const_iterator, iterator>
// && (callable sprout::as_const(cont).index_of(p)
// || callable sprout::as_const(cont).begin()
// || ADL(without sprout) callable begin(sprout::as_const(cont))
// )
// -> sprout::index_of(sprout::as_const(cont), sprout::const_iterator_cast<iterator>(p))
2016-04-14 11:14:49 +00:00
// otherwise, callable cont.index_of(p) -> cont.index_of(p)
2016-04-17 07:11:43 +00:00
// otherwise -> sprout::distance(sprout::begin(cont), p)
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::size_type
index_of(Container& cont, typename sprout::container_traits<Container>::iterator p) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<Container>::range_index_of(cont, p);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::size_type
index_of(Container const& cont, typename sprout::container_traits<Container const>::iterator p) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<Container const>::range_index_of(cont, p);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::size_type
index_of(T (& arr)[N], typename sprout::container_traits<T[N]>::iterator p) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<T[N]>::range_index_of(arr, p);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::size_type
index_of(T const (& arr)[N], typename sprout::container_traits<T const[N]>::iterator p) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<T const[N]>::range_index_of(arr, p);
}
//
// cindex_of
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::size_type
cindex_of(Container const& cont, typename sprout::container_traits<Container const>::iterator p) {
return sprout::index_of(cont, p);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::size_type
cindex_of(T const (& arr)[N], typename sprout::container_traits<T const[N]>::iterator p) {
return sprout::index_of(arr, p);
}
} // namespace sprout
#include <sprout/container/container_range_traits.hpp>
#endif // #ifndef SPROUT_CONTAINER_INDEX_OF_HPP