Sprout/sprout/container/data.hpp

71 lines
2.5 KiB
C++
Raw Normal View History

2014-07-12 12:37:49 +00:00
/*=============================================================================
2016-02-25 09:48:28 +00:00
Copyright (c) 2011-2016 Bolero MURAKAMI
2014-07-12 12:37:49 +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_DATA_HPP
#define SPROUT_CONTAINER_DATA_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 {
//
// data
//
// effect:
2016-04-10 04:48:41 +00:00
// sprout::container_range_traits<Container>::range_data(cont)
2014-07-12 12:37:49 +00:00
// [default]
2016-04-10 04:48:41 +00:00
// ADL callable range_data(cont) -> range_data(cont)
// [default]
// Container is T[N] -> pointer(cont)
2016-04-17 07:11:43 +00:00
// otherwise, Container is not const
// && sprout::is_const_cast_convertible<const_pointer, pointer>
// && callable sprout::as_const(cont).data()
// -> const_cast<pointer>(sprout::data(sprout::as_const(cont)))
2016-04-10 04:48:41 +00:00
// cont.data()
2014-07-12 12:37:49 +00:00
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::pointer
data(Container& cont) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<Container>::range_data(cont);
2014-07-12 12:37:49 +00:00
}
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::pointer
data(Container const& cont) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<Container>::range_data(cont);
2014-07-12 12:37:49 +00:00
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T[N]>::pointer
data(T (& arr)[N]) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<T[N]>::range_data(arr);
2014-07-12 12:37:49 +00:00
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::pointer
data(T const (& arr)[N]) {
2016-04-10 04:48:41 +00:00
return sprout::container_range_traits<T const[N]>::range_data(arr);
2014-07-12 12:37:49 +00:00
}
//
// cdata
//
template<typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::pointer
cdata(Container const& cont) {
return sprout::data(cont);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR typename sprout::container_traits<T const[N]>::pointer
cdata(T const (& arr)[N]) {
return sprout::data(arr);
}
} // namespace sprout
#include <sprout/container/container_range_traits.hpp>
#endif // #ifndef SPROUT_CONTAINER_DATA_HPP