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

115 lines
4.6 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2016-02-25 09:48:28 +00:00
Copyright (c) 2011-2016 Bolero MURAKAMI
2013-08-08 09:54:33 +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)
=============================================================================*/
2013-04-12 15:04:01 +00:00
#ifndef SPROUT_CONTAINER_STD_ARRAY_HPP
#define SPROUT_CONTAINER_STD_ARRAY_HPP
#include <array>
2016-04-16 09:59:02 +00:00
#include <utility>
#include <type_traits>
2013-04-12 15:04:01 +00:00
#include <sprout/config.hpp>
2016-04-16 09:59:02 +00:00
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/iterator/index_iterator.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/as_const.hpp>
#include <sprout/memory/addressof.hpp>
#include <sprout/functional/transparent.hpp>
2013-04-12 15:04:01 +00:00
namespace sprout {
2016-04-16 09:59:02 +00:00
namespace detail {
template<typename T = void>
struct const_subscript;
template<>
struct const_subscript<void>
: public sprout::transparent<>
{
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>()[std::declval<U>()])
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_IF_EXPR(std::declval<T>()[std::declval<U>()])
{
typedef decltype(std::declval<T>()[std::declval<U>()]) type;
return const_cast<type>(sprout::as_const(x)[SPROUT_FORWARD(U, y)]);
}
};
} // namespace detail
2013-04-12 15:04:01 +00:00
//
// container_traits
//
template<typename T, std::size_t N>
struct container_traits<std::array<T, N> >
: public sprout::detail::container_traits_default<std::array<T, N> >
{
public:
2016-04-16 09:59:02 +00:00
typedef sprout::index_iterator<std::array<T, N>&, true, sprout::detail::const_subscript<> > iterator;
typedef sprout::index_iterator<std::array<T, N> const&, true, sprout::detail::const_subscript<> > const_iterator;
2013-04-12 15:04:01 +00:00
};
//
// container_range_traits
2013-04-12 15:04:01 +00:00
//
template<typename T, std::size_t N>
2014-07-12 17:07:17 +00:00
struct container_range_traits<std::array<T, N> >
: public sprout::detail::container_range_traits_default<std::array<T, N> >
{
2016-04-16 09:59:02 +00:00
private:
typedef sprout::detail::container_range_traits_default<std::array<T, N> > base_type;
public:
using base_type::range_front;
using base_type::range_back;
using base_type::range_at;
public:
2016-04-16 09:59:02 +00:00
// iterators:
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::iterator
range_begin(std::array<T, N>& cont) {
return typename sprout::container_traits<std::array<T, N> >::iterator(cont, 0);
}
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> const>::iterator
range_begin(std::array<T, N> const& cont) {
return typename sprout::container_traits<std::array<T, N> const>::iterator(cont, 0);
}
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::iterator
range_end(std::array<T, N>& cont) {
return typename sprout::container_traits<std::array<T, N> >::iterator(cont, cont.size());
}
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> const>::iterator
range_end(std::array<T, N> const& cont) {
return typename sprout::container_traits<std::array<T, N> const>::iterator(cont, cont.size());
}
2016-04-16 09:59:02 +00:00
// element access:
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::reference
range_front(std::array<T, N>& cont) {
typedef typename sprout::container_traits<std::array<T, N> >::reference type;
return const_cast<type>(base_type::range_front(sprout::as_const(cont)));
}
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::reference
range_back(std::array<T, N>& cont) {
typedef typename sprout::container_traits<std::array<T, N> >::reference type;
return const_cast<type>(base_type::range_back(sprout::as_const(cont)));
}
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::reference
range_at(std::array<T, N>& cont, typename sprout::container_traits<std::array<T, N> >::size_type i) {
typedef typename sprout::container_traits<std::array<T, N> >::reference type;
return const_cast<type>(base_type::range_at(sprout::as_const(cont), i));
}
// data access:
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::pointer
range_data(std::array<T, N>& cont) {
return sprout::addressof(range_front(cont));
}
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> const>::pointer
range_data(std::array<T, N> const& cont) {
return sprout::addressof(range_front(cont));
}
};
2013-04-12 15:04:01 +00:00
} // namespace sprout
#endif // #ifndef SPROUT_CONTAINER_STD_ARRAY_HPP