mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix std::array adapt
This commit is contained in:
parent
69c9233ca0
commit
14865d4d64
4 changed files with 70 additions and 20 deletions
|
@ -9,16 +9,37 @@
|
|||
#define SPROUT_CONTAINER_STD_ARRAY_HPP
|
||||
|
||||
#include <array>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
# include <type_traits>
|
||||
# include <sprout/workaround/std/cstddef.hpp>
|
||||
# include <sprout/container/traits.hpp>
|
||||
# include <sprout/iterator/index_iterator.hpp>
|
||||
#endif
|
||||
#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>
|
||||
|
||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
||||
namespace sprout {
|
||||
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
|
||||
|
||||
//
|
||||
// container_traits
|
||||
//
|
||||
|
@ -27,8 +48,8 @@ namespace sprout {
|
|||
: public sprout::detail::container_traits_default<std::array<T, N> >
|
||||
{
|
||||
public:
|
||||
typedef sprout::index_iterator<std::array<T, N>&, true> iterator;
|
||||
typedef sprout::index_iterator<std::array<T, N> const&, true> const_iterator;
|
||||
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;
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -38,7 +59,14 @@ namespace sprout {
|
|||
struct container_range_traits<std::array<T, N> >
|
||||
: public sprout::detail::container_range_traits_default<std::array<T, N> >
|
||||
{
|
||||
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:
|
||||
// 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);
|
||||
|
@ -47,7 +75,6 @@ namespace sprout {
|
|||
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());
|
||||
|
@ -56,8 +83,32 @@ namespace sprout {
|
|||
range_end(std::array<T, N> const& cont) {
|
||||
return typename sprout::container_traits<std::array<T, N> const>::iterator(cont, cont.size());
|
||||
}
|
||||
// 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));
|
||||
}
|
||||
};
|
||||
} // namespace sprout
|
||||
#endif
|
||||
|
||||
#endif // #ifndef SPROUT_CONTAINER_STD_ARRAY_HPP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue