mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix std::array adapt
This commit is contained in:
parent
69c9233ca0
commit
14865d4d64
4 changed files with 70 additions and 20 deletions
|
@ -632,7 +632,7 @@ namespace sprout {
|
||||||
typename sprout::container_traits<Container>::size_type
|
typename sprout::container_traits<Container>::size_type
|
||||||
>::type
|
>::type
|
||||||
range_index_of_impl(Container& cont, typename sprout::container_traits<Container>::iterator p) {
|
range_index_of_impl(Container& cont, typename sprout::container_traits<Container>::iterator p) {
|
||||||
return sprout::distance(begin(cont), p);
|
return sprout::distance(sprout::begin(cont), p);
|
||||||
}
|
}
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
|
@ -648,7 +648,7 @@ namespace sprout {
|
||||||
typename sprout::container_traits<Container const>::size_type
|
typename sprout::container_traits<Container const>::size_type
|
||||||
>::type
|
>::type
|
||||||
range_index_of_impl(Container const& cont, typename sprout::container_traits<Container const>::iterator p) {
|
range_index_of_impl(Container const& cont, typename sprout::container_traits<Container const>::iterator p) {
|
||||||
return sprout::distance(begin(cont), p);
|
return sprout::distance(sprout::begin(cont), p);
|
||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
@ -658,24 +658,22 @@ namespace sprout_container_range_detail {
|
||||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
|
||||||
range_begin(Container& cont) {
|
range_begin(Container& cont) {
|
||||||
return sprout::detail::range_begin_impl(cont);
|
return sprout::detail::range_begin_impl(cont);
|
||||||
// return cont.begin();
|
|
||||||
}
|
}
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
|
||||||
range_begin(Container const& cont) {
|
range_begin(Container const& cont) {
|
||||||
return sprout::detail::range_begin_impl(cont);
|
return sprout::detail::range_begin_impl(cont);
|
||||||
// return cont.begin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container>::iterator
|
||||||
range_end(Container& cont) {
|
range_end(Container& cont) {
|
||||||
return cont.end();
|
return sprout::detail::range_end_impl(cont);
|
||||||
}
|
}
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
|
inline SPROUT_CONSTEXPR typename sprout::container_traits<Container const>::iterator
|
||||||
range_end(Container const& cont) {
|
range_end(Container const& cont) {
|
||||||
return cont.end();
|
return sprout::detail::range_end_impl(cont);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
|
|
|
@ -9,16 +9,37 @@
|
||||||
#define SPROUT_CONTAINER_STD_ARRAY_HPP
|
#define SPROUT_CONTAINER_STD_ARRAY_HPP
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <utility>
|
||||||
|
#include <type_traits>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
#include <sprout/workaround/std/cstddef.hpp>
|
||||||
# include <type_traits>
|
#include <sprout/container/traits.hpp>
|
||||||
# include <sprout/workaround/std/cstddef.hpp>
|
#include <sprout/iterator/index_iterator.hpp>
|
||||||
# include <sprout/container/traits.hpp>
|
#include <sprout/utility/forward.hpp>
|
||||||
# include <sprout/iterator/index_iterator.hpp>
|
#include <sprout/utility/as_const.hpp>
|
||||||
#endif
|
#include <sprout/memory/addressof.hpp>
|
||||||
|
#include <sprout/functional/transparent.hpp>
|
||||||
|
|
||||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
|
||||||
namespace sprout {
|
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
|
// container_traits
|
||||||
//
|
//
|
||||||
|
@ -27,8 +48,8 @@ namespace sprout {
|
||||||
: public sprout::detail::container_traits_default<std::array<T, N> >
|
: public sprout::detail::container_traits_default<std::array<T, N> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef sprout::index_iterator<std::array<T, N>&, true> 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> const_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> >
|
struct container_range_traits<std::array<T, N> >
|
||||||
: public sprout::detail::container_range_traits_default<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:
|
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
|
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::iterator
|
||||||
range_begin(std::array<T, N>& cont) {
|
range_begin(std::array<T, N>& cont) {
|
||||||
return typename sprout::container_traits<std::array<T, N> >::iterator(cont, 0);
|
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) {
|
range_begin(std::array<T, N> const& cont) {
|
||||||
return typename sprout::container_traits<std::array<T, N> const>::iterator(cont, 0);
|
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
|
static SPROUT_CONSTEXPR typename sprout::container_traits<std::array<T, N> >::iterator
|
||||||
range_end(std::array<T, N>& cont) {
|
range_end(std::array<T, N>& cont) {
|
||||||
return typename sprout::container_traits<std::array<T, N> >::iterator(cont, cont.size());
|
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) {
|
range_end(std::array<T, N> const& cont) {
|
||||||
return typename sprout::container_traits<std::array<T, N> const>::iterator(cont, cont.size());
|
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
|
} // namespace sprout
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_CONTAINER_STD_ARRAY_HPP
|
#endif // #ifndef SPROUT_CONTAINER_STD_ARRAY_HPP
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <sprout/workaround/std/cstddef.hpp>
|
#include <sprout/workaround/std/cstddef.hpp>
|
||||||
#include <sprout/utility/move.hpp>
|
#include <sprout/utility/move.hpp>
|
||||||
|
#include <sprout/utility/as_const.hpp>
|
||||||
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
|
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
|
||||||
#include <sprout/tuple/tuple/get.hpp>
|
#include <sprout/tuple/tuple/get.hpp>
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ namespace sprout {
|
||||||
static SPROUT_CONSTEXPR T&
|
static SPROUT_CONSTEXPR T&
|
||||||
tuple_get(std::array<T, N>& t) SPROUT_NOEXCEPT {
|
tuple_get(std::array<T, N>& t) SPROUT_NOEXCEPT {
|
||||||
static_assert(I < N, "tuple_get: index out of range");
|
static_assert(I < N, "tuple_get: index out of range");
|
||||||
return t[I];
|
return const_cast<T&>(sprout::as_const(t)[I]);
|
||||||
}
|
}
|
||||||
template<std::size_t I>
|
template<std::size_t I>
|
||||||
static SPROUT_CONSTEXPR T const&
|
static SPROUT_CONSTEXPR T const&
|
||||||
|
|
|
@ -46,10 +46,10 @@
|
||||||
struct SPROUT_PP_CAT(is_within_namespace_, NAME) \
|
struct SPROUT_PP_CAT(is_within_namespace_, NAME) \
|
||||||
: public sprout::is_within_tag_namespace<NAMESPACE::SPROUT_ADL_TEST_TAG(NAME), T> \
|
: public sprout::is_within_tag_namespace<NAMESPACE::SPROUT_ADL_TEST_TAG(NAME), T> \
|
||||||
{}; \
|
{}; \
|
||||||
SPROUT_IS_WITHIN_NAMESPACE_V(NAME, NAMESPACE);
|
SPROUT_IS_WITHIN_NAMESPACE_V(NAME, NAMESPACE)
|
||||||
#if SPROUT_USE_VARIABLE_TEMPLATES
|
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||||
# define SPROUT_IS_WITHIN_NAMESPACE_V(NAME, NAMESPACE) \
|
# define SPROUT_IS_WITHIN_NAMESPACE_V(NAME, NAMESPACE) \
|
||||||
template<typename T>
|
template<typename T> \
|
||||||
SPROUT_STATIC_CONSTEXPR bool SPROUT_PP_CAT(SPROUT_PP_CAT(is_within_namespace_, NAME), _v) = SPROUT_PP_CAT(is_within_namespace_, NAME)<T>::value
|
SPROUT_STATIC_CONSTEXPR bool SPROUT_PP_CAT(SPROUT_PP_CAT(is_within_namespace_, NAME), _v) = SPROUT_PP_CAT(is_within_namespace_, NAME)<T>::value
|
||||||
#else // #if SPROUT_USE_VARIABLE_TEMPLATES
|
#else // #if SPROUT_USE_VARIABLE_TEMPLATES
|
||||||
# define SPROUT_IS_WITHIN_NAMESPACE_V(NAME, NAMESPACE) \
|
# define SPROUT_IS_WITHIN_NAMESPACE_V(NAME, NAMESPACE) \
|
||||||
|
|
Loading…
Reference in a new issue