mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
change sprout::array adapt
This commit is contained in:
parent
14865d4d64
commit
92cc7881d6
5 changed files with 117 additions and 17 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <sprout/container/functions.hpp>
|
#include <sprout/container/functions.hpp>
|
||||||
#include <sprout/iterator/operation.hpp>
|
#include <sprout/iterator/operation.hpp>
|
||||||
#include <sprout/iterator/reverse_iterator.hpp>
|
#include <sprout/iterator/reverse_iterator.hpp>
|
||||||
|
#include <sprout/iterator/const_iterator_cast.hpp>
|
||||||
#include <sprout/algorithm/cxx14/copy.hpp>
|
#include <sprout/algorithm/cxx14/copy.hpp>
|
||||||
#include <sprout/algorithm/cxx14/move.hpp>
|
#include <sprout/algorithm/cxx14/move.hpp>
|
||||||
#include <sprout/algorithm/cxx14/fill_n.hpp>
|
#include <sprout/algorithm/cxx14/fill_n.hpp>
|
||||||
|
@ -281,6 +282,47 @@ namespace sprout {
|
||||||
lhs.swap(rhs);
|
lhs.swap(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::iterator
|
||||||
|
range_begin(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
|
||||||
|
return sprout::const_iterator_cast<typename sprout::array<T, N>::iterator>(sprout::as_const(t).begin());
|
||||||
|
}
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::iterator
|
||||||
|
range_end(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
|
||||||
|
return sprout::const_iterator_cast<typename sprout::array<T, N>::iterator>(sprout::as_const(t).end());
|
||||||
|
}
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::reference
|
||||||
|
range_at(sprout::array<T, N>& t, typename sprout::array<T, N>::size_type i) {
|
||||||
|
return const_cast<typename sprout::array<T, N>::reference>(sprout::as_const(t).at(i));
|
||||||
|
}
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::reference
|
||||||
|
range_front(sprout::array<T, N>& t) {
|
||||||
|
return const_cast<typename sprout::array<T, N>::reference>(sprout::as_const(t).front());
|
||||||
|
}
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::reference
|
||||||
|
range_back(sprout::array<T, N>& t) {
|
||||||
|
return const_cast<typename sprout::array<T, N>::reference>(sprout::as_const(t).back());
|
||||||
|
}
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::iterator
|
||||||
|
range_nth(sprout::array<T, N>& t, typename sprout::array<T, N>::size_type i) {
|
||||||
|
return sprout::const_iterator_cast<typename sprout::array<T, N>::iterator>(sprout::as_const(t).nth(i));
|
||||||
|
}
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::size_type
|
||||||
|
range_index_of(sprout::array<T, N>& t, typename sprout::array<T, N>::iterator p) SPROUT_NOEXCEPT {
|
||||||
|
return sprout::as_const(t).index_of(p);
|
||||||
|
}
|
||||||
|
template<typename T, std::size_t N>
|
||||||
|
inline SPROUT_CONSTEXPR typename sprout::array<T, N>::pointer
|
||||||
|
range_data(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
|
||||||
|
return const_cast<typename sprout::array<T, N>::pointer>(sprout::as_const(t).data());
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// to_array
|
// to_array
|
||||||
//
|
//
|
||||||
|
|
|
@ -8,17 +8,35 @@
|
||||||
#ifndef SPROUT_CONTAINER_BOOST_ARRAY_HPP
|
#ifndef SPROUT_CONTAINER_BOOST_ARRAY_HPP
|
||||||
#define SPROUT_CONTAINER_BOOST_ARRAY_HPP
|
#define SPROUT_CONTAINER_BOOST_ARRAY_HPP
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
#include <boost/array.hpp>
|
#include <boost/array.hpp>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
#include <type_traits>
|
||||||
# include <type_traits>
|
#include <sprout/workaround/std/cstddef.hpp>
|
||||||
# include <sprout/workaround/std/cstddef.hpp>
|
#include <sprout/container/traits.hpp>
|
||||||
# include <sprout/container/traits.hpp>
|
#include <sprout/iterator/index_iterator.hpp>
|
||||||
# include <sprout/iterator/index_iterator.hpp>
|
#include <sprout/utility/forward.hpp>
|
||||||
#endif
|
#include <sprout/functional/transparent.hpp>
|
||||||
|
|
||||||
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
|
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
|
||||||
|
|
||||||
//
|
//
|
||||||
// container_traits
|
// container_traits
|
||||||
//
|
//
|
||||||
|
@ -27,8 +45,8 @@ namespace sprout {
|
||||||
: public sprout::detail::container_traits_default<boost::array<T, N> >
|
: public sprout::detail::container_traits_default<boost::array<T, N> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef sprout::index_iterator<boost::array<T, N>&, true> iterator;
|
typedef sprout::index_iterator<boost::array<T, N>&, true, sprout::detail::elems_subscript<> > iterator;
|
||||||
typedef sprout::index_iterator<boost::array<T, N> const&, true> const_iterator;
|
typedef sprout::index_iterator<boost::array<T, N> const&, true, sprout::detail::elems_subscript<> > const_iterator;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -39,6 +57,7 @@ namespace sprout {
|
||||||
: public sprout::detail::container_range_traits_default<boost::array<T, N> >
|
: public sprout::detail::container_range_traits_default<boost::array<T, N> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// iterators:
|
||||||
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::iterator
|
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::iterator
|
||||||
range_begin(boost::array<T, N>& cont) {
|
range_begin(boost::array<T, N>& cont) {
|
||||||
return typename sprout::container_traits<boost::array<T, N> >::iterator(cont, 0);
|
return typename sprout::container_traits<boost::array<T, N> >::iterator(cont, 0);
|
||||||
|
@ -47,7 +66,6 @@ namespace sprout {
|
||||||
range_begin(boost::array<T, N> const& cont) {
|
range_begin(boost::array<T, N> const& cont) {
|
||||||
return typename sprout::container_traits<boost::array<T, N> const>::iterator(cont, 0);
|
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
|
static SPROUT_CONSTEXPR typename sprout::container_traits<boost::array<T, N> >::iterator
|
||||||
range_end(boost::array<T, N>& cont) {
|
range_end(boost::array<T, N>& cont) {
|
||||||
return typename sprout::container_traits<boost::array<T, N> >::iterator(cont, cont.size());
|
return typename sprout::container_traits<boost::array<T, N> >::iterator(cont, cont.size());
|
||||||
|
@ -56,8 +74,50 @@ namespace sprout {
|
||||||
range_end(boost::array<T, N> const& cont) {
|
range_end(boost::array<T, N> const& cont) {
|
||||||
return typename sprout::container_traits<boost::array<T, N> const>::iterator(cont, cont.size());
|
return typename sprout::container_traits<boost::array<T, N> const>::iterator(cont, cont.size());
|
||||||
}
|
}
|
||||||
|
// 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
|
||||||
|
range_at(boost::array<T, N>& cont, typename sprout::container_traits<boost::array<T, N> >::size_type i) {
|
||||||
|
return cont.elems[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[i];
|
||||||
|
}
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_CONTAINER_BOOST_ARRAY_HPP
|
#endif // #ifndef SPROUT_CONTAINER_BOOST_ARRAY_HPP
|
||||||
|
|
|
@ -32,10 +32,9 @@ namespace sprout {
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
SPROUT_CONSTEXPR decltype(std::declval<T>()[std::declval<U>()])
|
SPROUT_CONSTEXPR decltype(std::declval<T>()[std::declval<U>()])
|
||||||
operator()(T&& x, U&& y)
|
operator()(T&& x, U&& y)
|
||||||
const SPROUT_NOEXCEPT_IF_EXPR(std::declval<T>()[std::declval<U>()])
|
const SPROUT_NOEXCEPT_IF_EXPR(const_cast<decltype(std::declval<T>()[std::declval<U>()])>(sprout::as_const(std::declval<T>())[std::declval<U>()]))
|
||||||
{
|
{
|
||||||
typedef decltype(std::declval<T>()[std::declval<U>()]) type;
|
return const_cast<decltype(std::declval<T>()[std::declval<U>()])>(sprout::as_const(x)[SPROUT_FORWARD(U, y)]);
|
||||||
return const_cast<type>(sprout::as_const(x)[SPROUT_FORWARD(U, y)]);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
|
@ -74,7 +74,6 @@ namespace sprout {
|
||||||
range_begin(std::complex<T> const& cont) {
|
range_begin(std::complex<T> const& cont) {
|
||||||
return typename sprout::container_traits<std::complex<T> const>::iterator(cont, 0);
|
return typename sprout::container_traits<std::complex<T> const>::iterator(cont, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SPROUT_CONSTEXPR typename sprout::container_traits<std::complex<T> >::iterator
|
static SPROUT_CONSTEXPR typename sprout::container_traits<std::complex<T> >::iterator
|
||||||
range_end(std::complex<T>& cont) {
|
range_end(std::complex<T>& cont) {
|
||||||
return typename sprout::container_traits<std::complex<T> >::iterator(cont, 2);
|
return typename sprout::container_traits<std::complex<T> >::iterator(cont, 2);
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#define SPROUT_ADL_TESTER_DECL(NAME) \
|
#define SPROUT_ADL_TESTER_DECL(NAME) \
|
||||||
SPROUT_ADL_TEST_TAG_DECL(NAME); \
|
SPROUT_ADL_TEST_TAG_DECL(NAME); \
|
||||||
template<typename T> \
|
template<typename T> \
|
||||||
void sprout_adl_tester(sprout_adl_test::SPROUT_PP_CAT(NAME, _tag)&&, T&&)
|
void sprout_adl_tester(sprout_adl_test::SPROUT_PP_CAT(NAME, _tag)*&&, T&&)
|
||||||
|
|
||||||
//
|
//
|
||||||
// SPROUT_ADL_TEST_TAG
|
// SPROUT_ADL_TEST_TAG
|
||||||
|
@ -68,7 +68,7 @@ namespace sprout_adl_tester_detail {
|
||||||
public:
|
public:
|
||||||
template<
|
template<
|
||||||
typename Tag0 = Tag, typename U = T,
|
typename Tag0 = Tag, typename U = T,
|
||||||
typename R = typename sprout::identity<decltype(sprout_adl_tester(std::declval<Tag0>(), std::declval<U>()))>::type
|
typename R = typename sprout::identity<decltype(sprout_adl_tester(std::declval<Tag0*>(), std::declval<U>()))>::type
|
||||||
>
|
>
|
||||||
static sprout::is_found_via_adl<R> test(int);
|
static sprout::is_found_via_adl<R> test(int);
|
||||||
static sprout::false_type test(...);
|
static sprout::false_type test(...);
|
||||||
|
|
Loading…
Reference in a new issue