Sprout/sprout/container/boost/array.hpp

133 lines
5.4 KiB
C++
Raw Normal View History

2016-04-08 03:51:11 +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_BOOST_ARRAY_HPP
#define SPROUT_CONTAINER_BOOST_ARRAY_HPP
2016-04-16 11:12:55 +00:00
#include <utility>
2016-04-08 03:51:11 +00:00
#include <boost/array.hpp>
#include <sprout/config.hpp>
2016-04-16 11:12:55 +00:00
#include <type_traits>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/container/traits.hpp>
2016-04-17 10:36:56 +00:00
#include <sprout/container/range_index_check.hpp>
2016-04-16 11:12:55 +00:00
#include <sprout/iterator/index_iterator.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/functional/transparent.hpp>
2016-04-08 03:51:11 +00:00
namespace sprout {
2016-04-16 11:12:55 +00:00
namespace detail {
template<typename T = void>
struct elems_subscript;
template<>
struct elems_subscript<void>
: public sprout::transparent<>
{
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>().elems[std::declval<U>()])
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_IF_EXPR(std::declval<T>().elems[std::declval<U>()])
{
return SPROUT_FORWARD(T, x).elems[SPROUT_FORWARD(U, y)];
}
};
} // namespace detail
2016-04-08 03:51:11 +00:00
//
// container_traits
//
template<typename T, std::size_t N>
struct container_traits<boost::array<T, N> >
: public sprout::detail::container_traits_default<boost::array<T, N> >
{
public:
2016-04-16 11:12:55 +00:00
typedef sprout::index_iterator<boost::array<T, N>&, true, sprout::detail::elems_subscript<> > iterator;
typedef sprout::index_iterator<boost::array<T, N> const&, true, sprout::detail::elems_subscript<> > const_iterator;
2016-04-08 03:51:11 +00:00
};
//
// container_range_traits
//
template<typename T, std::size_t N>
struct container_range_traits<boost::array<T, N> >
: public sprout::detail::container_range_traits_default<boost::array<T, N> >
{
public:
2016-04-16 11:12:55 +00:00
// iterators:
2016-04-08 03:51:11 +00:00
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::iterator
range_begin(boost::array<T, N>& cont) {
return typename sprout::container_traits<boost::array<T, N> >::iterator(cont, 0);
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> const>::iterator
range_begin(boost::array<T, N> const& cont) {
return typename sprout::container_traits<boost::array<T, N> const>::iterator(cont, 0);
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::iterator
range_end(boost::array<T, N>& cont) {
return typename sprout::container_traits<boost::array<T, N> >::iterator(cont, cont.size());
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> const>::iterator
range_end(boost::array<T, N> const& cont) {
return typename sprout::container_traits<boost::array<T, N> const>::iterator(cont, cont.size());
}
2016-04-16 11:12:55 +00:00
// capacity:
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> const>::size_type
range_size(boost::array<T, N> const& cont) {
return N;
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> const>::size_type
range_empty(boost::array<T, N> const& cont) {
return N != 0;
}
// element access:
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::reference
range_front(boost::array<T, N>& cont) {
return cont.elems[0];
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> const>::reference
range_front(boost::array<T, N> const& cont) {
return cont.elems[0];
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::reference
range_back(boost::array<T, N>& cont) {
return cont.elems[N - 1];
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> const>::reference
range_back(boost::array<T, N> const& cont) {
return cont.elems[N - 1];
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::reference
2016-04-17 10:36:56 +00:00
range_subscript_at(boost::array<T, N>& cont, typename sprout::container_traits<boost::array<T, N> >::size_type i) {
2016-04-16 11:12:55 +00:00
return cont.elems[i];
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> const>::reference
2016-04-17 10:36:56 +00:00
range_subscript_at(boost::array<T, N> const& cont, typename sprout::container_traits<boost::array<T, N> const>::size_type i) {
2016-04-16 11:12:55 +00:00
return cont.elems[i];
}
2016-04-17 10:36:56 +00:00
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::reference
range_at(boost::array<T, N>& cont, typename sprout::container_traits<boost::array<T, N> >::size_type i) {
return cont.elems[sprout::range_index_check(cont, i)];
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> const>::reference
range_at(boost::array<T, N> const& cont, typename sprout::container_traits<boost::array<T, N> const>::size_type i) {
return cont.elems[sprout::range_index_check(cont, i)];
}
2016-04-16 11:12:55 +00:00
// data access:
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::pointer
range_data(boost::array<T, N>& cont) {
return cont.elems;
}
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> const>::pointer
range_data(boost::array<T, N> const& cont) {
return cont.elems;
}
2016-04-08 03:51:11 +00:00
};
} // namespace sprout
#endif // #ifndef SPROUT_CONTAINER_BOOST_ARRAY_HPP