Sprout/sprout/sub_array.hpp

948 lines
34 KiB
C++
Raw Normal View History

2011-09-01 02:48:32 +00:00
#ifndef SPROUT_SUB_ARRAY_HPP
#define SPROUT_SUB_ARRAY_HPP
#include <algorithm>
#include <utility>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/index_tuple.hpp>
#include <sprout/fixed_container/traits.hpp>
#include <sprout/fixed_container/functions.hpp>
2011-10-01 15:19:13 +00:00
#include <sprout/iterator/operation.hpp>
2011-10-30 08:40:35 +00:00
#include <sprout/utility/forward.hpp>
2011-09-01 02:48:32 +00:00
#include <sprout/detail/if.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
namespace sprout {
namespace detail {
struct is_non_reference_array_tag {};
struct is_not_non_reference_array_tag {};
2011-09-03 13:26:26 +00:00
template<typename Container>
2011-09-01 02:48:32 +00:00
class sub_array_impl {
protected:
2011-09-03 13:26:26 +00:00
typedef Container container_type;
typedef typename std::remove_reference<container_type>::type fixed_container_type;
typedef typename std::remove_const<fixed_container_type>::type internal_type;
2011-09-01 02:48:32 +00:00
protected:
2011-09-03 13:26:26 +00:00
SPROUT_STATIC_CONSTEXPR bool is_reference = std::is_reference<container_type>::value;
SPROUT_STATIC_CONSTEXPR bool is_const = std::is_const<fixed_container_type>::value;
2011-09-01 02:48:32 +00:00
protected:
2011-09-03 13:26:26 +00:00
typedef typename sprout::fixed_container_traits<fixed_container_type>::value_type value_type;
2011-09-01 02:48:32 +00:00
typedef typename sprout::detail::if_c<
is_const,
2011-09-03 13:26:26 +00:00
typename sprout::fixed_container_traits<fixed_container_type>::const_iterator,
typename sprout::fixed_container_traits<fixed_container_type>::iterator
2011-09-01 02:48:32 +00:00
>::type iterator;
2011-09-03 13:26:26 +00:00
typedef typename sprout::fixed_container_traits<fixed_container_type>::const_iterator const_iterator;
2011-09-01 02:48:32 +00:00
typedef typename sprout::detail::if_c<
is_const,
2011-09-03 13:26:26 +00:00
typename sprout::fixed_container_traits<fixed_container_type>::const_reference,
typename sprout::fixed_container_traits<fixed_container_type>::reference
2011-09-01 02:48:32 +00:00
>::type reference;
2011-09-03 13:26:26 +00:00
typedef typename sprout::fixed_container_traits<fixed_container_type>::const_reference const_reference;
typedef typename sprout::fixed_container_traits<fixed_container_type>::size_type size_type;
typedef typename sprout::fixed_container_traits<fixed_container_type>::difference_type difference_type;
2011-09-01 02:48:32 +00:00
typedef typename sprout::detail::if_c<
is_const,
2011-09-03 13:26:26 +00:00
typename sprout::fixed_container_traits<fixed_container_type>::const_pointer,
typename sprout::fixed_container_traits<fixed_container_type>::pointer
2011-09-01 02:48:32 +00:00
>::type pointer;
2011-09-03 13:26:26 +00:00
typedef typename sprout::fixed_container_traits<fixed_container_type>::const_pointer const_pointer;
2011-09-01 02:48:32 +00:00
protected:
2011-09-03 13:26:26 +00:00
SPROUT_STATIC_CONSTEXPR size_type static_size = sprout::fixed_container_traits<fixed_container_type>::fixed_size;
SPROUT_STATIC_CONSTEXPR size_type fixed_size = static_size;
2011-09-01 02:48:32 +00:00
protected:
typedef typename sprout::detail::if_c<
is_reference,
2011-09-03 13:26:26 +00:00
fixed_container_type*,
typename std::remove_const<fixed_container_type>::type
2011-09-01 02:48:32 +00:00
>::type holder_type;
typedef typename sprout::detail::if_c<
is_reference,
2011-09-03 13:26:26 +00:00
fixed_container_type&,
fixed_container_type const&
2011-09-01 02:48:32 +00:00
>::type param_type;
2011-09-03 13:26:26 +00:00
typedef fixed_container_type const& const_param_type;
2011-09-01 02:48:32 +00:00
protected:
typedef typename sprout::detail::if_c<
std::is_array<holder_type>::value,
sprout::detail::is_non_reference_array_tag,
sprout::detail::is_not_non_reference_array_tag
>::type array_tag;
protected:
template<typename Arr>
static SPROUT_CONSTEXPR typename std::enable_if<
std::is_reference<Arr>::value,
holder_type
>::type to_holder(param_type arr) {
return &arr;
}
template<typename Arr>
static SPROUT_CONSTEXPR typename std::enable_if<
!std::is_reference<Arr>::value,
holder_type const&
>::type to_holder(param_type arr) {
return arr;
}
template<typename Arr>
static SPROUT_CONSTEXPR typename std::enable_if<
std::is_reference<Arr>::value,
param_type
>::type to_param(holder_type arr) {
return *arr;
}
template<typename Arr>
static SPROUT_CONSTEXPR typename std::enable_if<
!std::is_reference<Arr>::value,
param_type
>::type to_param(holder_type& arr) {
return arr;
}
template<typename Arr>
static SPROUT_CONSTEXPR typename std::enable_if<
!std::is_reference<Arr>::value,
param_type
>::type to_param(holder_type const& arr) {
return arr;
}
template<typename Arr>
static SPROUT_CONSTEXPR typename std::enable_if<
std::is_reference<Arr>::value,
const_param_type
>::type to_const_param(holder_type arr) {
return *arr;
}
template<typename Arr>
static SPROUT_CONSTEXPR typename std::enable_if<
!std::is_reference<Arr>::value,
const_param_type
>::type to_const_param(holder_type const& arr) {
return arr;
}
protected:
holder_type array_;
difference_type first_;
difference_type last_;
public:
sub_array_impl() = default;
protected:
2011-09-03 13:26:26 +00:00
template<typename ContainerTag, std::ptrdiff_t... Indexes>
2011-09-01 02:48:32 +00:00
SPROUT_CONSTEXPR sub_array_impl(
2011-09-03 13:26:26 +00:00
ContainerTag,
2011-09-01 02:48:32 +00:00
param_type arr,
sprout::index_tuple<Indexes...>,
const_iterator first,
const_iterator last,
2011-09-03 13:26:26 +00:00
typename std::enable_if<std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
2011-09-01 02:48:32 +00:00
)
2011-09-03 13:26:26 +00:00
: array_{to_holder<Container>(arr)[Indexes]...}
2011-09-01 02:48:32 +00:00
, first_(NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(sprout::cbegin(arr), first))
, last_(NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(sprout::cbegin(arr), last))
{}
2011-09-03 13:26:26 +00:00
template<typename ContainerTag, std::ptrdiff_t... Indexes>
2011-09-01 02:48:32 +00:00
SPROUT_CONSTEXPR sub_array_impl(
2011-09-03 13:26:26 +00:00
ContainerTag,
2011-09-01 02:48:32 +00:00
param_type arr,
sprout::index_tuple<Indexes...>,
const_iterator first,
const_iterator last,
2011-09-03 13:26:26 +00:00
typename std::enable_if<!std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
2011-09-01 02:48:32 +00:00
)
2011-09-03 13:26:26 +00:00
: array_(to_holder<Container>(arr))
2011-09-01 02:48:32 +00:00
, first_(NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(sprout::cbegin(arr), first))
, last_(NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(sprout::cbegin(arr), last))
{}
2011-09-03 13:26:26 +00:00
template<typename ContainerTag, std::ptrdiff_t... Indexes>
2011-09-01 02:48:32 +00:00
SPROUT_CONSTEXPR sub_array_impl(
2011-09-03 13:26:26 +00:00
ContainerTag,
2011-09-01 02:48:32 +00:00
param_type arr,
sprout::index_tuple<Indexes...>,
difference_type first,
difference_type last,
2011-09-03 13:26:26 +00:00
typename std::enable_if<std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
2011-09-01 02:48:32 +00:00
)
2011-09-03 13:26:26 +00:00
: array_{to_holder<Container>(arr)[Indexes]...}
2011-09-01 02:48:32 +00:00
, first_(first)
, last_(last)
{}
2011-09-03 13:26:26 +00:00
template<typename ContainerTag, std::ptrdiff_t... Indexes>
2011-09-01 02:48:32 +00:00
SPROUT_CONSTEXPR sub_array_impl(
2011-09-03 13:26:26 +00:00
ContainerTag,
2011-09-01 02:48:32 +00:00
param_type arr,
sprout::index_tuple<Indexes...>,
difference_type first,
difference_type last,
2011-09-03 13:26:26 +00:00
typename std::enable_if<!std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
2011-09-01 02:48:32 +00:00
)
2011-09-03 13:26:26 +00:00
: array_(to_holder<Container>(arr))
2011-09-01 02:48:32 +00:00
, first_(first)
, last_(last)
{}
};
} // namespace detail
//
// sub_array
//
2011-09-03 13:26:26 +00:00
template<typename Container>
2011-09-01 02:48:32 +00:00
class sub_array
2011-09-03 13:26:26 +00:00
: private sprout::detail::sub_array_impl<Container>
2011-09-01 02:48:32 +00:00
{
private:
2011-09-03 13:26:26 +00:00
typedef sprout::detail::sub_array_impl<Container> impl_type;
2011-09-01 02:48:32 +00:00
public:
typedef typename impl_type::container_type container_type;
typedef typename impl_type::fixed_container_type fixed_container_type;
2011-09-03 13:26:26 +00:00
typedef typename impl_type::internal_type internal_type;
typedef sub_array<typename sprout::fixed_container_traits<internal_type>::clone_type> clone_type;
2011-09-01 02:48:32 +00:00
public:
2011-09-03 13:26:26 +00:00
SPROUT_STATIC_CONSTEXPR bool is_reference = impl_type::is_reference;
SPROUT_STATIC_CONSTEXPR bool is_const = impl_type::is_const;
2011-09-01 02:48:32 +00:00
public:
typedef typename impl_type::value_type value_type;
typedef typename impl_type::iterator iterator;
typedef typename impl_type::const_iterator const_iterator;
typedef typename impl_type::reference reference;
typedef typename impl_type::const_reference const_reference;
typedef typename impl_type::size_type size_type;
typedef typename impl_type::difference_type difference_type;
typedef typename impl_type::pointer pointer;
typedef typename impl_type::const_pointer const_pointer;
public:
2011-09-03 13:26:26 +00:00
SPROUT_STATIC_CONSTEXPR size_type static_size = impl_type::static_size;
SPROUT_STATIC_CONSTEXPR size_type fixed_size = impl_type::fixed_size;
2011-09-01 02:48:32 +00:00
public:
typedef typename impl_type::holder_type holder_type;
typedef typename impl_type::param_type param_type;
typedef typename impl_type::const_param_type const_param_type;
private:
typedef typename impl_type::array_tag array_tag;
private:
using impl_type::array_;
using impl_type::first_;
using impl_type::last_;
public:
// construct/copy/destroy:
2011-09-01 02:48:32 +00:00
sub_array() = default;
SPROUT_CONSTEXPR sub_array(param_type arr, const_iterator first, const_iterator last)
: impl_type(
array_tag(),
arr,
typename sprout::index_range<0, fixed_size>::type(),
first,
last
)
{}
SPROUT_CONSTEXPR sub_array(param_type arr, difference_type first, difference_type last)
: impl_type(
array_tag(),
arr,
typename sprout::index_range<0, fixed_size>::type(),
first,
last
)
{}
2011-09-03 13:26:26 +00:00
SPROUT_CONSTEXPR sub_array(sub_array<Container> const& other, const_iterator first, const_iterator last)
2011-09-01 02:48:32 +00:00
: impl_type(
array_tag(),
2011-09-03 13:26:26 +00:00
impl_type::template to_param<Container>(other.array_),
2011-09-01 02:48:32 +00:00
typename sprout::index_range<0, fixed_size>::type(),
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(sprout::begin(other.get_array()), first),
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(sprout::begin(other.get_array()), last)
)
{}
2011-09-03 13:26:26 +00:00
SPROUT_CONSTEXPR sub_array(sub_array<Container> const& other, difference_type first, difference_type last)
2011-09-01 02:48:32 +00:00
: impl_type(
array_tag(),
2011-09-03 13:26:26 +00:00
impl_type::template to_param<Container>(other.array_),
2011-09-01 02:48:32 +00:00
typename sprout::index_range<0, fixed_size>::type(),
first + other.first_,
last + other.first_
)
{}
void fill(const_reference value) {
std::fill_n(begin(), size(), value);
2011-09-01 02:48:32 +00:00
}
template<typename Container2>
void swap(sub_array<Container2>& other) {
using std::swap;
swap(other.array_, array_);
swap(other.first_, first_);
swap(other.last_, last_);
2011-09-01 02:48:32 +00:00
}
// iterators:
2011-09-01 02:48:32 +00:00
iterator begin() {
2011-10-01 15:19:13 +00:00
return sprout::next(sprout::begin(get_array()), first_);
2011-09-01 02:48:32 +00:00
}
SPROUT_CONSTEXPR const_iterator begin() const {
2011-10-01 15:19:13 +00:00
return sprout::next(sprout::begin(get_array()), first_);
2011-09-01 02:48:32 +00:00
}
iterator end() {
2011-10-01 15:19:13 +00:00
return sprout::next(sprout::begin(get_array()), last_);
2011-09-01 02:48:32 +00:00
}
SPROUT_CONSTEXPR const_iterator end() const {
2011-10-01 15:19:13 +00:00
return sprout::next(sprout::begin(get_array()), last_);
2011-09-01 02:48:32 +00:00
}
SPROUT_CONSTEXPR const_iterator cbegin() const {
return sprout::next(sprout::begin(get_array()), first_);
}
2011-09-01 02:48:32 +00:00
SPROUT_CONSTEXPR const_iterator cend() const {
2011-10-01 15:19:13 +00:00
return sprout::next(sprout::begin(get_array()), last_);
2011-09-01 02:48:32 +00:00
}
// capacity:
SPROUT_CONSTEXPR size_type size() const {
return last_ - first_;
}
SPROUT_CONSTEXPR size_type max_size() const {
return size();
}
SPROUT_CONSTEXPR bool empty() const {
return size() == 0;
}
// element access:
2011-09-01 02:48:32 +00:00
reference operator[](size_type i) {
2011-10-01 15:19:13 +00:00
return *sprout::next(sprout::begin(get_array()), first_ + i);
2011-09-01 02:48:32 +00:00
}
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
2011-10-01 15:19:13 +00:00
return *sprout::next(sprout::begin(get_array()), first_ + i);
2011-09-01 02:48:32 +00:00
}
reference at(size_type i) {
return i < size()
? *sprout::next(sprout::begin(get_array()), first_ + i)
: (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), first_ + i))
;
2011-09-01 02:48:32 +00:00
}
SPROUT_CONSTEXPR const_reference at(size_type i) const {
return i < size()
? *sprout::next(sprout::begin(get_array()), first_ + i)
: (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), first_ + i))
;
2011-09-01 02:48:32 +00:00
}
reference front() {
2011-10-01 15:19:13 +00:00
return *sprout::next(sprout::begin(get_array()), first_);
2011-09-01 02:48:32 +00:00
}
SPROUT_CONSTEXPR const_reference front() const {
2011-10-01 15:19:13 +00:00
return *sprout::next(sprout::begin(get_array()), first_);
2011-09-01 02:48:32 +00:00
}
reference back() {
2011-10-01 15:19:13 +00:00
return *sprout::next(sprout::begin(get_array()), last_ - 1);
2011-09-01 02:48:32 +00:00
}
SPROUT_CONSTEXPR const_reference back() const {
2011-10-01 15:19:13 +00:00
return *sprout::next(sprout::begin(get_array()), last_ - 1);
2011-09-01 02:48:32 +00:00
}
2011-09-01 02:48:32 +00:00
pointer data() {
return get_array().data() + first_;
}
SPROUT_CONSTEXPR const_pointer data() const {
return get_array().data() + first_;
}
// others:
2011-09-03 13:26:26 +00:00
template<typename Container2>
sub_array<Container>& operator=(sub_array<Container2> const& rhs) {
2011-09-01 02:48:32 +00:00
array_ = rhs.array_;
first_ = rhs.first_;
last_ = rhs.last_;
return *this;
}
2011-09-03 13:26:26 +00:00
template<typename Container2>
sub_array<Container>& operator=(sub_array<Container2>&& rhs) {
2011-09-01 02:48:32 +00:00
array_ = std::move(rhs.array_);
first_ = std::move(rhs.first_);
last_ = std::move(rhs.last_);
return *this;
}
pointer c_array() {
return data();
}
void assign(const_reference value) {
fill(value);
}
void rangecheck(size_type i) const {
if (i >= size()) {
throw std::out_of_range("sub_array<>: index out of range");
}
}
param_type get_fixed() {
return impl_type::template to_param<Container>(array_);
}
SPROUT_CONSTEXPR const_param_type get_fixed() const {
return impl_type::template to_const_param<Container>(array_);
}
SPROUT_CONSTEXPR const_param_type get_cfixed() const {
return impl_type::template to_const_param<Container>(array_);
}
param_type get_array() {
return impl_type::template to_param<Container>(array_);
}
SPROUT_CONSTEXPR const_param_type get_array() const {
return impl_type::template to_const_param<Container>(array_);
}
2011-09-01 02:48:32 +00:00
};
2011-10-10 12:06:34 +00:00
template<typename Container>
SPROUT_CONSTEXPR typename sprout::sub_array<Container>::size_type sprout::sub_array<Container>::static_size;
template<typename Container>
SPROUT_CONSTEXPR typename sprout::sub_array<Container>::size_type sprout::sub_array<Container>::fixed_size;
//
// operator==
// operator!=
// operator<
// operator>
// operator<=
// operator>=
//
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline bool operator==(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
2011-09-01 02:48:32 +00:00
return NS_SSCRISK_CEL_OR_SPROUT_DETAIL::equal(sprout::begin(lhs), sprout::end(lhs), sprout::begin(rhs));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline bool operator!=(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
2011-09-01 02:48:32 +00:00
return !(lhs == rhs);
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline bool operator<(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
2011-09-01 02:48:32 +00:00
return NS_SSCRISK_CEL_OR_SPROUT_DETAIL::lexicographical_compare(sprout::begin(lhs), sprout::end(lhs), sprout::begin(rhs), sprout::end(rhs));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline bool operator>(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
2011-09-01 02:48:32 +00:00
return rhs < lhs;
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline bool operator<=(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
2011-09-01 02:48:32 +00:00
return !(rhs < lhs);
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline bool operator>=(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
2011-09-01 02:48:32 +00:00
return !(lhs < rhs);
}
//
// swap
//
2011-09-03 13:26:26 +00:00
template<typename Container>
2011-09-26 01:53:29 +00:00
inline void swap(sprout::sub_array<Container>& lhs, sprout::sub_array<Container>& rhs) {
2011-09-01 02:48:32 +00:00
lhs.swap(rhs);
}
//
// fixed_container_traits
//
2011-09-03 13:26:26 +00:00
template<typename Container>
struct fixed_container_traits<sprout::sub_array<Container> >
: public sprout::detail::fixed_container_traits_base<sprout::sub_array<Container> >
2011-09-01 02:48:32 +00:00
{
public:
2011-09-03 13:26:26 +00:00
typedef typename sprout::sub_array<Container>::fixed_container_type fixed_container_type;
typedef typename sprout::sub_array<Container>::internal_type internal_type;
typedef typename sprout::sub_array<Container>::clone_type clone_type;
2011-09-01 02:48:32 +00:00
public:
2011-09-03 13:26:26 +00:00
SPROUT_STATIC_CONSTEXPR typename sprout::detail::fixed_container_traits_base<sprout::sub_array<Container> >::size_type fixed_size
= std::tuple_size<typename std::remove_const<internal_type>::type>::value
2011-09-01 02:48:32 +00:00
;
};
//
// rebind_fixed_size
//
2011-09-03 13:26:26 +00:00
template<typename Container>
struct rebind_fixed_size<sprout::sub_array<Container> > {
2011-09-01 02:48:32 +00:00
public:
2011-09-03 13:26:26 +00:00
template<typename sprout::fixed_container_traits<sprout::sub_array<Container> >::size_type S>
2011-09-01 02:48:32 +00:00
struct apply {
public:
typedef sprout::sub_array<
typename sprout::rebind_fixed_size<
2011-09-03 13:26:26 +00:00
typename sprout::fixed_container_traits<sprout::sub_array<Container> >::internal_type
2011-09-01 02:48:32 +00:00
>::template apply<S>::type
> type;
};
};
//
// get_fixed_functor
//
2011-09-03 13:26:26 +00:00
template<typename Container>
struct get_fixed_functor<sprout::sub_array<Container> > {
private:
typedef typename sprout::fixed_container_traits<sprout::sub_array<Container> >::fixed_container_type fixed_container_type;
2011-09-01 02:48:32 +00:00
public:
2011-09-03 13:26:26 +00:00
fixed_container_type& operator()(sprout::sub_array<Container>& cont) const {
2011-09-01 02:48:32 +00:00
return cont.get_fixed();
}
2011-09-03 13:26:26 +00:00
SPROUT_CONSTEXPR fixed_container_type const& operator()(sprout::sub_array<Container> const& cont) const {
2011-09-01 02:48:32 +00:00
return cont.get_fixed();
}
};
2011-09-03 13:26:26 +00:00
//
// clone_functor
//
template<typename Container>
struct clone_functor<sprout::sub_array<Container> > {
private:
typedef typename sprout::fixed_container_traits<sprout::sub_array<Container> >::clone_type clone_type;
2011-10-30 08:40:35 +00:00
private:
template<typename Other>
SPROUT_CONSTEXPR clone_type make(
Other&& cont,
typename sprout::fixed_container_traits<sprout::sub_array<Container> >::difference_type first,
typename sprout::fixed_container_traits<sprout::sub_array<Container> >::difference_type last
) const
{
return clone_type(
sprout::clone(sprout::get_fixed(sprout::forward<Other>(cont))),
first,
last
);
2011-09-03 13:26:26 +00:00
}
2011-10-30 08:40:35 +00:00
public:
template<typename Other>
SPROUT_CONSTEXPR clone_type operator()(Other&& cont) const {
return make(
sprout::forward<Other>(cont),
sprout::fixed_begin_offset(cont),
sprout::fixed_end_offset(cont)
);
2011-09-03 13:26:26 +00:00
}
};
//
// make_clone_functor
//
template<typename Container>
struct make_clone_functor<sprout::sub_array<Container> > {
private:
typedef typename sprout::fixed_container_traits<sprout::sub_array<Container> >::clone_type clone_type;
typedef typename sprout::fixed_container_traits<sprout::sub_array<Container> >::internal_type internal_type;
private:
SPROUT_CONSTEXPR clone_type make(typename sprout::fixed_container_traits<internal_type>::clone_type const& arr) const {
return clone_type(arr, sprout::begin(arr), sprout::end(arr));
}
public:
template<typename... Args>
2011-10-30 08:40:35 +00:00
SPROUT_CONSTEXPR clone_type operator()(Args&&... args) const {
return make(sprout::make_clone<internal_type>(sprout::forward<Args>(args)...));
2011-09-03 13:26:26 +00:00
}
};
//
// remake_clone_functor
//
template<typename Container>
struct remake_clone_functor<sprout::sub_array<Container> > {
private:
typedef typename sprout::fixed_container_traits<sprout::sub_array<Container> >::clone_type clone_type;
typedef typename sprout::fixed_container_traits<sprout::sub_array<Container> >::internal_type internal_type;
private:
template<typename Other>
SPROUT_CONSTEXPR clone_type remake(
2011-10-30 08:40:35 +00:00
Other&& other,
2011-09-03 13:26:26 +00:00
typename sprout::fixed_container_traits<sprout::sub_array<Container> >::difference_type size,
typename sprout::fixed_container_traits<internal_type>::clone_type const& cloned
) const
{
return clone_type(
cloned,
2011-10-01 15:19:13 +00:00
sprout::next(sprout::begin(cloned), sprout::fixed_begin_offset(other)),
sprout::next(sprout::begin(cloned), sprout::fixed_begin_offset(other) + size)
2011-09-03 13:26:26 +00:00
);
}
public:
template<typename Other, typename... Args>
SPROUT_CONSTEXPR clone_type operator()(
2011-10-30 08:40:35 +00:00
Other&& other,
2011-09-03 13:26:26 +00:00
typename sprout::fixed_container_traits<sprout::sub_array<Container> >::difference_type size,
2011-10-30 08:40:35 +00:00
Args&&... args
2011-09-03 13:26:26 +00:00
) const
{
2011-10-30 08:40:35 +00:00
return remake(
sprout::forward<Other>(other),
size,
sprout::make_clone<internal_type>(sprout::forward<Args>(args)...)
);
2011-09-03 13:26:26 +00:00
}
};
namespace detail {
template<typename T, typename Enable = void>
2011-10-10 12:06:34 +00:00
struct is_sub_array_impl
: public std::false_type
{};
template<typename T>
struct is_sub_array_impl<
T,
typename std::enable_if<
std::is_same<
T,
sprout::sub_array<typename T::container_type>
>::value
>::type
2011-10-10 12:06:34 +00:00
>
: public std::true_type
{};
} // namespace detail
2011-09-01 02:48:32 +00:00
//
// is_sub_array
//
template<typename T>
struct is_sub_array
: public sprout::detail::is_sub_array_impl<T>
{};
2011-09-01 02:48:32 +00:00
//
// sub
//
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container&> >::const_iterator first,
typename sprout::fixed_container_traits<sprout::sub_array<Container&> >::const_iterator last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<Container&>(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container&> >::difference_type first,
typename sprout::fixed_container_traits<sprout::sub_array<Container&> >::difference_type last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<Container&>(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container&> >::const_iterator first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub(arr, first, sprout::end(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container&> >::difference_type first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub(arr, first, sprout::size(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub
//
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::const_iterator first,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::const_iterator last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<Container const&>(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::difference_type first,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::difference_type last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<Container const&>(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::const_iterator first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub(arr, first, sprout::end(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::difference_type first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub(arr, first, sprout::size(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub
//
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::fixed_container_traits<Container>::const_iterator first,
typename sprout::fixed_container_traits<Container>::const_iterator last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return Container(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::fixed_container_traits<Container>::difference_type first,
typename sprout::fixed_container_traits<Container>::difference_type last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return Container(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::fixed_container_traits<Container>::const_iterator first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub(arr, first, sprout::end(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::fixed_container_traits<Container>::difference_type first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub(arr, first, sprout::size(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// csub
//
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::const_iterator first,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::const_iterator last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<Container const&>(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::difference_type first,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::difference_type last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<Container const&>(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::const_iterator first
2011-09-01 02:48:32 +00:00
)
{
return sprout::csub(arr, first, sprout::end(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::fixed_container_traits<sprout::sub_array<Container const&> >::difference_type first
2011-09-01 02:48:32 +00:00
)
{
return sprout::csub(arr, first, sprout::size(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr
2011-09-01 02:48:32 +00:00
)
{
return sprout::csub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// csub
//
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type const&> >::type csub(
Container const& arr,
typename sprout::fixed_container_traits<Container>::const_iterator first,
typename sprout::fixed_container_traits<Container>::const_iterator last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<typename Container::fixed_container_type const&>(arr.get_array(), first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type const&> >::type csub(
Container const& arr,
typename sprout::fixed_container_traits<Container>::difference_type first,
typename sprout::fixed_container_traits<Container>::difference_type last
2011-09-01 02:48:32 +00:00
)
{
2011-10-01 15:19:13 +00:00
return sprout::sub_array<typename Container::fixed_container_type const&>(
arr.get_array(),
sprout::next(sprout::begin(arr), first),
sprout::next(sprout::begin(arr), last)
);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type const&> >::type csub(
Container const& arr,
typename sprout::fixed_container_traits<Container>::const_iterator first
2011-09-01 02:48:32 +00:00
)
{
return sprout::csub(arr, first, sprout::end(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type const&> >::type csub(
Container const& arr,
typename sprout::fixed_container_traits<Container>::difference_type first
2011-09-01 02:48:32 +00:00
)
{
return sprout::csub(arr, first, sprout::size(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type const&> >::type csub(
Container const& arr
2011-09-01 02:48:32 +00:00
)
{
return sprout::csub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub_copy
//
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::fixed_container_traits<Container>::const_iterator first,
typename sprout::fixed_container_traits<Container>::const_iterator last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<Container>(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::fixed_container_traits<Container>::difference_type first,
typename sprout::fixed_container_traits<Container>::difference_type last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<Container>(arr, first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::fixed_container_traits<Container>::const_iterator first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub_copy(arr, first, sprout::end(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::fixed_container_traits<Container>::difference_type first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub_copy(arr, first, sprout::size(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub_copy
//
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type> >::type sub_copy(
Container const& arr,
typename sprout::fixed_container_traits<Container>::const_iterator first,
typename sprout::fixed_container_traits<Container>::const_iterator last
2011-09-01 02:48:32 +00:00
)
{
2011-09-03 13:26:26 +00:00
return sprout::sub_array<typename Container::fixed_container_type>(arr.get_array(), first, last);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type> >::type sub_copy(
Container const& arr,
typename sprout::fixed_container_traits<Container>::difference_type first,
typename sprout::fixed_container_traits<Container>::difference_type last
2011-09-01 02:48:32 +00:00
)
{
2011-10-01 15:19:13 +00:00
return sprout::sub_array<typename Container::fixed_container_type>(
arr.get_array(),
sprout::next(sprout::begin(arr), first),
sprout::next(sprout::begin(arr), last)
);
2011-09-01 02:48:32 +00:00
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type> >::type sub_copy(
Container const& arr,
typename sprout::fixed_container_traits<Container>::const_iterator first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub_copy(arr, first, sprout::end(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type> >::type sub_copy(
Container const& arr,
typename sprout::fixed_container_traits<Container>::difference_type first
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub_copy(arr, first, sprout::size(arr));
}
2011-09-03 13:26:26 +00:00
template<typename Container>
SPROUT_CONSTEXPR inline typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::fixed_container_type> >::type sub_copy(
Container const& arr
2011-09-01 02:48:32 +00:00
)
{
return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr));
}
} // namespace sprout
namespace std {
//
// tuple_size
//
2011-09-03 13:26:26 +00:00
template<typename Container>
struct tuple_size<sprout::sub_array<Container> > {
2011-09-01 02:48:32 +00:00
public:
2011-09-03 13:26:26 +00:00
SPROUT_STATIC_CONSTEXPR std::size_t value = std::tuple_size<
2011-09-01 02:48:32 +00:00
typename std::remove_const<
2011-09-03 13:26:26 +00:00
typename std::remove_reference<Container>::type
2011-09-01 02:48:32 +00:00
>::type
>::value;
};
//
// tuple_element
//
2011-09-03 13:26:26 +00:00
template<std::size_t I, typename Container>
struct tuple_element<I, sprout::sub_array<Container> > {
2011-09-01 02:48:32 +00:00
public:
typedef typename std::tuple_element<
I,
typename std::remove_const<
2011-09-03 13:26:26 +00:00
typename std::remove_reference<Container>::type
2011-09-01 02:48:32 +00:00
>::type
>::type type;
};
} // namespace std
#endif // #ifndef SPROUT_SUB_ARRAY_HPP