2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2015-01-10 10:13:57 +00:00
|
|
|
Copyright (c) 2011-2015 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)
|
|
|
|
=============================================================================*/
|
2012-06-22 10:14:21 +00:00
|
|
|
#ifndef SPROUT_SUB_ARRAY_SUB_ARRAY_HPP
|
|
|
|
#define SPROUT_SUB_ARRAY_SUB_ARRAY_HPP
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
2013-04-06 04:06:51 +00:00
|
|
|
#include <sprout/index_tuple/metafunction.hpp>
|
2012-06-22 10:14:21 +00:00
|
|
|
#include <sprout/container/traits.hpp>
|
|
|
|
#include <sprout/container/functions.hpp>
|
|
|
|
#include <sprout/iterator/operation.hpp>
|
2013-10-31 09:57:41 +00:00
|
|
|
#include <sprout/algorithm/cxx14/fill_n.hpp>
|
2012-10-05 15:58:56 +00:00
|
|
|
#include <sprout/utility/swap.hpp>
|
2013-10-31 09:57:41 +00:00
|
|
|
#include <sprout/utility/move.hpp>
|
2012-06-22 10:14:21 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace detail {
|
|
|
|
struct is_non_reference_array_tag {};
|
|
|
|
struct is_not_non_reference_array_tag {};
|
|
|
|
|
|
|
|
template<typename Container>
|
|
|
|
class sub_array_impl {
|
|
|
|
protected:
|
|
|
|
typedef Container container_type;
|
|
|
|
typedef typename std::remove_reference<container_type>::type internal_type;
|
|
|
|
protected:
|
|
|
|
SPROUT_STATIC_CONSTEXPR bool is_reference = std::is_reference<container_type>::value;
|
|
|
|
SPROUT_STATIC_CONSTEXPR bool is_const = std::is_const<internal_type>::value;
|
|
|
|
protected:
|
|
|
|
typedef typename sprout::container_traits<internal_type>::const_iterator impl_const_iterator;
|
|
|
|
typedef typename sprout::container_traits<internal_type>::difference_type impl_difference_type;
|
|
|
|
protected:
|
|
|
|
typedef typename std::conditional<
|
|
|
|
is_reference,
|
|
|
|
internal_type*,
|
|
|
|
typename std::remove_const<internal_type>::type
|
|
|
|
>::type holder_type;
|
|
|
|
typedef typename std::conditional<
|
|
|
|
is_reference,
|
|
|
|
internal_type&,
|
|
|
|
internal_type const&
|
|
|
|
>::type param_type;
|
|
|
|
typedef internal_type const& const_param_type;
|
|
|
|
protected:
|
|
|
|
typedef typename std::conditional<
|
|
|
|
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;
|
|
|
|
}
|
2014-04-14 08:00:28 +00:00
|
|
|
template<typename Arr>
|
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
std::is_reference<Arr>::value,
|
|
|
|
internal_type&
|
|
|
|
>::type to_held(holder_type arr) {
|
|
|
|
return *arr;
|
|
|
|
}
|
|
|
|
template<typename Arr>
|
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
!std::is_reference<Arr>::value,
|
|
|
|
internal_type&
|
|
|
|
>::type to_held(holder_type& arr) {
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
template<typename Arr>
|
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
!std::is_reference<Arr>::value,
|
|
|
|
internal_type const&
|
|
|
|
>::type to_held(holder_type const& arr) {
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
template<typename Arr>
|
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
std::is_reference<Arr>::value,
|
|
|
|
internal_type const&
|
|
|
|
>::type to_const_held(holder_type arr) {
|
|
|
|
return *arr;
|
|
|
|
}
|
|
|
|
template<typename Arr>
|
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
!std::is_reference<Arr>::value,
|
|
|
|
internal_type const&
|
|
|
|
>::type to_const_held(holder_type const& arr) {
|
|
|
|
return arr;
|
|
|
|
}
|
2012-06-22 10:14:21 +00:00
|
|
|
protected:
|
|
|
|
holder_type array_;
|
2013-02-26 07:14:04 +00:00
|
|
|
impl_difference_type to_first_;
|
|
|
|
impl_difference_type to_last_;
|
2012-06-22 10:14:21 +00:00
|
|
|
public:
|
2013-11-10 09:36:04 +00:00
|
|
|
SPROUT_CONSTEXPR sub_array_impl()
|
|
|
|
: array_()
|
|
|
|
, to_first_()
|
|
|
|
, to_last_()
|
|
|
|
{}
|
|
|
|
sub_array_impl(sub_array_impl const&) = default;
|
2012-06-22 10:14:21 +00:00
|
|
|
protected:
|
|
|
|
template<typename ContainerTag, sprout::index_t... Indexes>
|
|
|
|
SPROUT_CONSTEXPR sub_array_impl(
|
|
|
|
ContainerTag,
|
|
|
|
param_type arr,
|
|
|
|
sprout::index_tuple<Indexes...>,
|
|
|
|
impl_const_iterator first,
|
|
|
|
impl_const_iterator last,
|
|
|
|
typename std::enable_if<std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
|
|
|
|
)
|
|
|
|
: array_{to_holder<Container>(arr)[Indexes]...}
|
2013-02-26 07:14:04 +00:00
|
|
|
, to_first_(sprout::distance(sprout::cbegin(arr), first))
|
|
|
|
, to_last_(sprout::distance(sprout::cbegin(arr), last))
|
2012-06-22 10:14:21 +00:00
|
|
|
{}
|
|
|
|
template<typename ContainerTag, sprout::index_t... Indexes>
|
|
|
|
SPROUT_CONSTEXPR sub_array_impl(
|
|
|
|
ContainerTag,
|
|
|
|
param_type arr,
|
|
|
|
sprout::index_tuple<Indexes...>,
|
|
|
|
impl_const_iterator first,
|
|
|
|
impl_const_iterator last,
|
|
|
|
typename std::enable_if<!std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
|
|
|
|
)
|
|
|
|
: array_(to_holder<Container>(arr))
|
2013-02-26 07:14:04 +00:00
|
|
|
, to_first_(sprout::distance(sprout::cbegin(arr), first))
|
|
|
|
, to_last_(sprout::distance(sprout::cbegin(arr), last))
|
2012-06-22 10:14:21 +00:00
|
|
|
{}
|
|
|
|
template<typename ContainerTag, sprout::index_t... Indexes>
|
|
|
|
SPROUT_CONSTEXPR sub_array_impl(
|
|
|
|
ContainerTag,
|
|
|
|
param_type arr,
|
|
|
|
sprout::index_tuple<Indexes...>,
|
2013-02-26 07:14:04 +00:00
|
|
|
impl_difference_type to_first,
|
|
|
|
impl_difference_type to_last,
|
2012-06-22 10:14:21 +00:00
|
|
|
typename std::enable_if<std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
|
|
|
|
)
|
|
|
|
: array_{to_holder<Container>(arr)[Indexes]...}
|
2013-02-26 07:14:04 +00:00
|
|
|
, to_first_(to_first)
|
|
|
|
, to_last_(to_last)
|
2012-06-22 10:14:21 +00:00
|
|
|
{}
|
|
|
|
template<typename ContainerTag, sprout::index_t... Indexes>
|
|
|
|
SPROUT_CONSTEXPR sub_array_impl(
|
|
|
|
ContainerTag,
|
|
|
|
param_type arr,
|
|
|
|
sprout::index_tuple<Indexes...>,
|
2013-02-26 07:14:04 +00:00
|
|
|
impl_difference_type to_first,
|
|
|
|
impl_difference_type to_last,
|
2012-06-22 10:14:21 +00:00
|
|
|
typename std::enable_if<!std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
|
|
|
|
)
|
|
|
|
: array_(to_holder<Container>(arr))
|
2013-02-26 07:14:04 +00:00
|
|
|
, to_first_(to_first)
|
|
|
|
, to_last_(to_last)
|
2012-06-22 10:14:21 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
//
|
|
|
|
// sub_array
|
|
|
|
//
|
|
|
|
template<typename Container>
|
|
|
|
class sub_array
|
|
|
|
: private sprout::detail::sub_array_impl<Container>
|
|
|
|
, public sprout::container_traits_facade<typename std::remove_reference<Container>::type>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef sprout::detail::sub_array_impl<Container> impl_type;
|
|
|
|
typedef sprout::container_traits_facade<typename std::remove_reference<Container>::type> facade_type;
|
|
|
|
public:
|
|
|
|
typedef typename impl_type::container_type container_type;
|
|
|
|
typedef typename impl_type::internal_type internal_type;
|
|
|
|
public:
|
|
|
|
SPROUT_STATIC_CONSTEXPR bool is_reference = impl_type::is_reference;
|
|
|
|
SPROUT_STATIC_CONSTEXPR bool is_const = impl_type::is_const;
|
|
|
|
public:
|
|
|
|
typedef typename facade_type::iterator iterator;
|
|
|
|
typedef typename facade_type::const_iterator const_iterator;
|
|
|
|
typedef typename facade_type::reference reference;
|
|
|
|
typedef typename facade_type::const_reference const_reference;
|
|
|
|
typedef typename facade_type::size_type size_type;
|
|
|
|
typedef typename facade_type::difference_type difference_type;
|
|
|
|
typedef typename facade_type::pointer pointer;
|
|
|
|
typedef typename facade_type::const_pointer const_pointer;
|
|
|
|
public:
|
2013-01-13 16:33:54 +00:00
|
|
|
SPROUT_STATIC_CONSTEXPR size_type enumerable_size = sprout::detail::static_size_or_zero<facade_type>::value;
|
2012-06-22 10:14:21 +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_;
|
2013-02-26 07:14:04 +00:00
|
|
|
using impl_type::to_first_;
|
|
|
|
using impl_type::to_last_;
|
2012-06-22 10:14:21 +00:00
|
|
|
public:
|
|
|
|
// construct/copy/destroy:
|
2014-01-13 15:18:06 +00:00
|
|
|
SPROUT_CONSTEXPR sub_array() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL
|
2013-11-10 09:36:04 +00:00
|
|
|
sub_array(sub_array const&) = default;
|
2012-06-22 10:14:21 +00:00
|
|
|
SPROUT_CONSTEXPR sub_array(param_type arr, const_iterator first, const_iterator last)
|
|
|
|
: impl_type(
|
|
|
|
array_tag(),
|
|
|
|
arr,
|
2013-03-31 06:14:10 +00:00
|
|
|
sprout::make_index_tuple<enumerable_size>::make(),
|
2012-06-22 10:14:21 +00:00
|
|
|
first,
|
|
|
|
last
|
|
|
|
)
|
|
|
|
{}
|
2013-02-26 07:14:04 +00:00
|
|
|
SPROUT_CONSTEXPR sub_array(param_type arr, difference_type to_first, difference_type to_last)
|
2012-06-22 10:14:21 +00:00
|
|
|
: impl_type(
|
|
|
|
array_tag(),
|
|
|
|
arr,
|
2013-03-31 06:14:10 +00:00
|
|
|
sprout::make_index_tuple<enumerable_size>::make(),
|
2013-02-26 07:14:04 +00:00
|
|
|
to_first,
|
|
|
|
to_last
|
2012-06-22 10:14:21 +00:00
|
|
|
)
|
|
|
|
{}
|
2013-02-26 01:43:27 +00:00
|
|
|
SPROUT_CONSTEXPR sub_array(sub_array const& other, const_iterator first, const_iterator last)
|
2012-06-22 10:14:21 +00:00
|
|
|
: impl_type(
|
|
|
|
array_tag(),
|
|
|
|
impl_type::template to_param<Container>(other.array_),
|
2013-03-31 06:14:10 +00:00
|
|
|
sprout::make_index_tuple<enumerable_size>::make(),
|
2013-01-03 08:01:50 +00:00
|
|
|
sprout::distance(sprout::begin(other.get_array()), first),
|
|
|
|
sprout::distance(sprout::begin(other.get_array()), last)
|
2012-06-22 10:14:21 +00:00
|
|
|
)
|
|
|
|
{}
|
2013-02-26 07:14:04 +00:00
|
|
|
SPROUT_CONSTEXPR sub_array(sub_array const& other, difference_type to_first, difference_type to_last)
|
2012-06-22 10:14:21 +00:00
|
|
|
: impl_type(
|
|
|
|
array_tag(),
|
|
|
|
impl_type::template to_param<Container>(other.array_),
|
2013-03-31 06:14:10 +00:00
|
|
|
sprout::make_index_tuple<enumerable_size>::make(),
|
2013-02-26 07:14:04 +00:00
|
|
|
other.to_first_ + to_first,
|
|
|
|
other.to_first_ + to_last
|
2012-06-22 10:14:21 +00:00
|
|
|
)
|
|
|
|
{}
|
2013-11-10 09:36:04 +00:00
|
|
|
template<typename Container2>
|
|
|
|
SPROUT_CXX14_CONSTEXPR sub_array& operator=(sub_array<Container2> const& rhs) {
|
|
|
|
array_ = rhs.array_;
|
|
|
|
to_first_ = rhs.to_first_;
|
|
|
|
to_last_ = rhs.to_last_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
template<typename Container2>
|
|
|
|
SPROUT_CXX14_CONSTEXPR sub_array& operator=(sub_array<Container2>&& rhs) {
|
|
|
|
array_ = sprout::move(rhs.array_);
|
|
|
|
to_first_ = sprout::move(rhs.to_first_);
|
|
|
|
to_last_ = sprout::move(rhs.to_last_);
|
|
|
|
return *this;
|
|
|
|
}
|
2012-06-22 10:14:21 +00:00
|
|
|
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR void fill(const_reference value) {
|
2013-10-31 09:57:41 +00:00
|
|
|
sprout::fill_n(begin(), size(), value);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
template<typename Container2>
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR void swap(sub_array<Container2>& other)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::swap(other.array_, array_))
|
2012-10-05 15:58:56 +00:00
|
|
|
{
|
|
|
|
sprout::swap(other.array_, array_);
|
2013-02-26 07:14:04 +00:00
|
|
|
sprout::swap(other.to_first_, to_first_);
|
|
|
|
sprout::swap(other.to_last_, to_last_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
// iterators:
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR iterator begin() {
|
2013-02-26 07:14:04 +00:00
|
|
|
return sprout::next(sprout::begin(get_array()), to_first_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_iterator begin() const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return sprout::next(sprout::begin(get_array()), to_first_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR iterator end() {
|
2013-02-26 07:14:04 +00:00
|
|
|
return sprout::next(sprout::begin(get_array()), to_last_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_iterator end() const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return sprout::next(sprout::begin(get_array()), to_last_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_iterator cbegin() const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return sprout::next(sprout::begin(get_array()), to_first_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_iterator cend() const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return sprout::next(sprout::begin(get_array()), to_last_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
// capacity:
|
|
|
|
SPROUT_CONSTEXPR size_type size() const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return to_last_ - to_first_;
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR size_type max_size() const {
|
|
|
|
return size();
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR bool empty() const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return to_first_ == to_last_;
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
// element access:
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR reference operator[](size_type i) {
|
2013-02-26 07:14:04 +00:00
|
|
|
return *sprout::next(sprout::begin(get_array()), to_first_ + i);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return *sprout::next(sprout::begin(get_array()), to_first_ + i);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR reference at(size_type i) {
|
2013-02-26 08:03:30 +00:00
|
|
|
return i < size() ? *sprout::next(sprout::begin(get_array()), to_first_ + i)
|
2013-02-26 07:14:04 +00:00
|
|
|
: (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), to_first_ + i))
|
2012-06-22 10:14:21 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reference at(size_type i) const {
|
2013-02-26 08:03:30 +00:00
|
|
|
return i < size() ? *sprout::next(sprout::begin(get_array()), to_first_ + i)
|
2013-02-26 07:14:04 +00:00
|
|
|
: (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), to_first_ + i))
|
2012-06-22 10:14:21 +00:00
|
|
|
;
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR reference front() {
|
2013-02-26 07:14:04 +00:00
|
|
|
return *sprout::next(sprout::begin(get_array()), to_first_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reference front() const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return *sprout::next(sprout::begin(get_array()), to_first_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR reference back() {
|
2013-02-26 07:14:04 +00:00
|
|
|
return *sprout::next(sprout::begin(get_array()), to_last_ - 1);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_reference back() const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return *sprout::next(sprout::begin(get_array()), to_last_ - 1);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR pointer data() {
|
2013-02-26 07:14:04 +00:00
|
|
|
return get_array().data() + to_first_;
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_pointer data() const {
|
2013-02-26 07:14:04 +00:00
|
|
|
return get_array().data() + to_first_;
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
|
|
|
// others:
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR pointer c_array() {
|
2012-06-22 10:14:21 +00:00
|
|
|
return data();
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CONSTEXPR const_pointer c_array() const {
|
|
|
|
return data();
|
|
|
|
}
|
|
|
|
SPROUT_CXX14_CONSTEXPR void assign(const_reference value) {
|
2012-06-22 10:14:21 +00:00
|
|
|
fill(value);
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR void rangecheck(size_type i) const {
|
2012-06-22 10:14:21 +00:00
|
|
|
if (i >= size()) {
|
|
|
|
throw std::out_of_range("sub_array<>: index out of range");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-14 08:00:28 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR internal_type& get_internal() {
|
|
|
|
return impl_type::template to_held<Container>(array_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
2014-04-14 08:00:28 +00:00
|
|
|
SPROUT_CONSTEXPR internal_type const& get_internal() const {
|
|
|
|
return impl_type::template to_const_held<Container>(array_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
2014-04-14 08:00:28 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR internal_type& get_array() {
|
|
|
|
return impl_type::template to_held<Container>(array_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
2014-04-14 08:00:28 +00:00
|
|
|
SPROUT_CONSTEXPR internal_type const& get_array() const {
|
|
|
|
return impl_type::template to_const_held<Container>(array_);
|
2012-06-22 10:14:21 +00:00
|
|
|
}
|
2013-02-26 07:14:04 +00:00
|
|
|
SPROUT_CONSTEXPR difference_type to_first() const {
|
|
|
|
return to_first_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR difference_type to_last() const {
|
|
|
|
return to_last_;
|
|
|
|
}
|
2013-02-26 08:03:30 +00:00
|
|
|
SPROUT_CONSTEXPR difference_type from_begin() const {
|
|
|
|
return to_first_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR difference_type from_end() const {
|
|
|
|
return to_last_ - sprout::size(get_array());
|
|
|
|
}
|
2015-03-19 14:43:13 +00:00
|
|
|
|
|
|
|
SPROUT_CXX14_CONSTEXPR iterator nth(size_type i) {
|
|
|
|
return i < size()
|
|
|
|
? sprout::next(begin(), i)
|
|
|
|
: (throw std::out_of_range("sub_array<>: index out of range"), iterator())
|
|
|
|
;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR const_iterator nth(size_type i) const {
|
|
|
|
return i < size()
|
|
|
|
? sprout::next(begin(), i)
|
|
|
|
: (throw std::out_of_range("array<>: index out of range"), const_iterator())
|
|
|
|
;
|
|
|
|
}
|
|
|
|
SPROUT_CXX14_CONSTEXPR size_type index_of(iterator p) {
|
|
|
|
return sprout::distance(begin(), p);
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR size_type index_of(const_iterator p) const {
|
|
|
|
return sprout::distance(begin(), p);
|
|
|
|
}
|
2012-06-22 10:14:21 +00:00
|
|
|
};
|
|
|
|
template<typename Container>
|
2013-01-13 16:33:54 +00:00
|
|
|
SPROUT_CONSTEXPR_OR_CONST typename sprout::sub_array<Container>::size_type sprout::sub_array<Container>::enumerable_size;
|
2012-06-22 10:14:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// swap
|
|
|
|
//
|
|
|
|
template<typename Container>
|
2013-10-30 09:15:57 +00:00
|
|
|
inline SPROUT_CXX14_CONSTEXPR void
|
2012-10-05 15:58:56 +00:00
|
|
|
swap(sprout::sub_array<Container>& lhs, sprout::sub_array<Container>& rhs)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs))
|
2012-10-05 15:58:56 +00:00
|
|
|
{
|
2012-06-22 10:14:21 +00:00
|
|
|
lhs.swap(rhs);
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
2013-02-07 14:12:57 +00:00
|
|
|
#include <sprout/sub_array/container.hpp>
|
|
|
|
|
2012-06-22 10:14:21 +00:00
|
|
|
#endif // #ifndef SPROUT_SUB_ARRAY_SUB_ARRAY_HPP
|