modify: tuple and hash support(class adapt) implemented in each class headers.

This commit is contained in:
bolero-MURAKAMI 2012-06-22 19:14:21 +09:00
parent 3a2610cb5c
commit ee8c952d05
35 changed files with 1720 additions and 1557 deletions

View file

@ -1,337 +1,12 @@
#ifndef SPROUT_ARRAY_HPP
#define SPROUT_ARRAY_HPP
#include <cstddef>
#include <algorithm>
#include <utility>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/index_tuple.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/move.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
# include <sprout/iterator/index_iterator.hpp>
#endif
namespace sprout {
//
// array
//
template<typename T, std::size_t N>
class array {
public:
typedef T value_type;
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
typedef sprout::index_iterator<array&> iterator;
typedef sprout::index_iterator<array const&> const_iterator;
#else
typedef T* iterator;
typedef T const* const_iterator;
#endif
typedef T& reference;
typedef T const& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T* pointer;
typedef T const* const_pointer;
typedef sprout::reverse_iterator<iterator> reverse_iterator;
typedef sprout::reverse_iterator<const_iterator> const_reverse_iterator;
public:
SPROUT_STATIC_CONSTEXPR size_type static_size = N;
public:
value_type elems[static_size ? static_size : 1];
public:
void fill(const_reference value) {
std::fill_n(begin(), size(), value);
}
void swap(array<T, N>& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval<T&>(), std::declval<T&>()))) {
std::swap_ranges(other.begin(), other.end(), begin());
}
// iterators:
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
iterator begin() SPROUT_NOEXCEPT {
return iterator(*this, 0);
}
SPROUT_CONSTEXPR const_iterator begin() const SPROUT_NOEXCEPT {
return const_iterator(*this, 0);
}
iterator end() SPROUT_NOEXCEPT {
return iterator(*this, size());
}
SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT {
return const_iterator(*this, size());
}
#else
iterator begin() SPROUT_NOEXCEPT {
return &elems[0];
}
SPROUT_CONSTEXPR const_iterator begin() const SPROUT_NOEXCEPT {
return &elems[0];
}
iterator end() SPROUT_NOEXCEPT {
return &elems[0] + size();
}
SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT {
return &elems[0] + size();
}
#endif
reverse_iterator rbegin() SPROUT_NOEXCEPT {
return reverse_iterator(end());
}
SPROUT_CONSTEXPR const_reverse_iterator rbegin() const SPROUT_NOEXCEPT {
return const_reverse_iterator(end());
}
reverse_iterator rend() SPROUT_NOEXCEPT {
return reverse_iterator(begin());
}
SPROUT_CONSTEXPR const_reverse_iterator rend() const SPROUT_NOEXCEPT {
return const_reverse_iterator(begin());
}
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT {
return const_iterator(*this, 0);
}
SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT {
return const_iterator(*this, size());
}
#else
SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT {
return &elems[0];
}
SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT {
return &elems[0] + size();
}
#endif
SPROUT_CONSTEXPR const_reverse_iterator crbegin() const SPROUT_NOEXCEPT {
return const_reverse_iterator(end());
}
SPROUT_CONSTEXPR const_reverse_iterator crend() const SPROUT_NOEXCEPT {
return const_reverse_iterator(begin());
}
// capacity:
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
return static_size;
}
SPROUT_CONSTEXPR size_type max_size() const SPROUT_NOEXCEPT {
return size();
}
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
return size() == 0;
}
// element access:
reference operator[](size_type i) {
return elems[i];
}
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
return elems[i];
}
reference at(size_type i) {
return i < size()
? elems[i]
: (throw std::out_of_range("array<>: index out of range"), elems[i])
;
}
SPROUT_CONSTEXPR const_reference at(size_type i) const {
return i < size()
? elems[i]
: (throw std::out_of_range("array<>: index out of range"), elems[i])
;
}
reference front() {
return elems[0];
}
SPROUT_CONSTEXPR const_reference front() const {
return elems[0];
}
reference back() {
return elems[size() - 1];
}
SPROUT_CONSTEXPR const_reference back() const {
return elems[size() - 1];
}
pointer data() SPROUT_NOEXCEPT {
return &elems[0];
}
SPROUT_CONSTEXPR const_pointer data() const SPROUT_NOEXCEPT {
return &elems[0];
}
// others:
template<typename T2>
array<T, N>& operator=(array<T2, N> const& rhs) {
std::copy(rhs.begin(), rhs.end(), begin());
return *this;
}
template<typename T2>
array<T, N>& operator=(array<T2, N>&& rhs) {
std::move(rhs.begin(), rhs.end(), begin());
return *this;
}
pointer c_array() SPROUT_NOEXCEPT {
return &elems[0];
}
void assign(const_reference value) {
fill(value);
}
void rangecheck(size_type i) const {
if (i >= size()) {
throw std::out_of_range("array<>: index out of range");
}
}
};
template<typename T, std::size_t N>
SPROUT_CONSTEXPR_OR_CONST typename sprout::array<T, N>::size_type sprout::array<T, N>::static_size;
//
// operator==
// operator!=
// operator<
// operator>
// operator<=
// operator>=
//
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator==(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::equal(lhs.begin(), lhs.end(), rhs.begin());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator!=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return !(lhs == rhs);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator<(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator>(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return rhs < lhs;
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator<=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return !(rhs < lhs);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator>=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return !(lhs < rhs);
}
//
// swap
//
template<typename T, std::size_t N>
inline void swap(sprout::array<T, N>& lhs, sprout::array<T, N>& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) {
lhs.swap(rhs);
}
//
// make_array
//
template<typename T, typename... Types>
inline SPROUT_CONSTEXPR sprout::array<T, sizeof...(Types)> make_array(Types&&... args) {
return sprout::array<T, sizeof...(Types)>{{sprout::forward<Types>(args)...}};
}
//
// make_common_array
//
template<typename... Types>
inline SPROUT_CONSTEXPR sprout::array<
typename std::decay<typename std::common_type<typename std::decay<Types>::type...>::type>::type,
sizeof...(Types)
> make_common_array(Types&&... args) {
return sprout::array<
typename std::decay<typename std::common_type<typename std::decay<Types>::type...>::type>::type,
sizeof...(Types)
>{{sprout::forward<Types>(args)...}};
}
namespace detail {
template<typename T, std::size_t N, sprout::index_t... Indexes>
inline SPROUT_CONSTEXPR sprout::array<T, N> to_array_impl(
T const (& arr)[N],
sprout::index_tuple<Indexes...>
)
{
return sprout::array<T, N>{{arr[Indexes]...}};
}
} // namespace detail
//
// to_array
//
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR sprout::array<T, N> to_array(T const (& arr)[N]) {
return sprout::detail::to_array_impl(arr, sprout::index_range<0, N>::make());
}
//
// is_array
//
template<typename T>
struct is_array
: public std::false_type
{};
template<typename T>
struct is_array<T const>
: public sprout::is_array<T>
{};
template<typename T>
struct is_array<T const volatile>
: public sprout::is_array<T>
{};
template<typename T, std::size_t N>
struct is_array<sprout::array<T, N> >
: public std::true_type
{};
namespace tuples {
//
// get
//
template<std::size_t I, typename T, std::size_t N>
inline SPROUT_CONSTEXPR T&
get(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
static_assert(I < N, "get: index out of range");
return t[I];
}
template<std::size_t I, typename T, std::size_t N>
inline SPROUT_CONSTEXPR T const&
get(sprout::array<T, N> const& t) SPROUT_NOEXCEPT {
static_assert(I < N, "get: index out of range");
return t[I];
}
template<std::size_t I, typename T, std::size_t N>
inline SPROUT_CONSTEXPR T&&
get(sprout::array<T, N>&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
namespace std {
//
// tuple_size
//
template<typename T, std::size_t N>
struct tuple_size<sprout::array<T, N> >
: public std::integral_constant<std::size_t, N>
{};
//
// tuple_element
//
template<std::size_t I, typename T, std::size_t N>
struct tuple_element<I, sprout::array<T, N> > {
public:
static_assert(I < N, "tuple_element<>: index out of range");
typedef T type;
};
} // namespace std
#include <sprout/array/array.hpp>
#include <sprout/array/comparison.hpp>
#include <sprout/array/hash.hpp>
#include <sprout/array/tuple.hpp>
#include <sprout/array/make_array.hpp>
#include <sprout/array/type_traits.hpp>
#endif // #ifndef SPROUT_ARRAY_HPP

214
sprout/array/array.hpp Normal file
View file

@ -0,0 +1,214 @@
#ifndef SPROUT_ARRAY_ARRAY_HPP
#define SPROUT_ARRAY_ARRAY_HPP
#include <cstddef>
#include <algorithm>
#include <utility>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/index_tuple.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
# include <sprout/iterator/index_iterator.hpp>
#endif
namespace sprout {
//
// array
//
template<typename T, std::size_t N>
class array {
public:
typedef T value_type;
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
typedef sprout::index_iterator<array&> iterator;
typedef sprout::index_iterator<array const&> const_iterator;
#else
typedef T* iterator;
typedef T const* const_iterator;
#endif
typedef T& reference;
typedef T const& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef T* pointer;
typedef T const* const_pointer;
typedef sprout::reverse_iterator<iterator> reverse_iterator;
typedef sprout::reverse_iterator<const_iterator> const_reverse_iterator;
public:
SPROUT_STATIC_CONSTEXPR size_type static_size = N;
public:
value_type elems[static_size ? static_size : 1];
public:
void fill(const_reference value) {
std::fill_n(begin(), size(), value);
}
void swap(array<T, N>& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval<T&>(), std::declval<T&>()))) {
std::swap_ranges(other.begin(), other.end(), begin());
}
// iterators:
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
iterator begin() SPROUT_NOEXCEPT {
return iterator(*this, 0);
}
SPROUT_CONSTEXPR const_iterator begin() const SPROUT_NOEXCEPT {
return const_iterator(*this, 0);
}
iterator end() SPROUT_NOEXCEPT {
return iterator(*this, size());
}
SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT {
return const_iterator(*this, size());
}
#else
iterator begin() SPROUT_NOEXCEPT {
return &elems[0];
}
SPROUT_CONSTEXPR const_iterator begin() const SPROUT_NOEXCEPT {
return &elems[0];
}
iterator end() SPROUT_NOEXCEPT {
return &elems[0] + size();
}
SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT {
return &elems[0] + size();
}
#endif
reverse_iterator rbegin() SPROUT_NOEXCEPT {
return reverse_iterator(end());
}
SPROUT_CONSTEXPR const_reverse_iterator rbegin() const SPROUT_NOEXCEPT {
return const_reverse_iterator(end());
}
reverse_iterator rend() SPROUT_NOEXCEPT {
return reverse_iterator(begin());
}
SPROUT_CONSTEXPR const_reverse_iterator rend() const SPROUT_NOEXCEPT {
return const_reverse_iterator(begin());
}
#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION
SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT {
return const_iterator(*this, 0);
}
SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT {
return const_iterator(*this, size());
}
#else
SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT {
return &elems[0];
}
SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT {
return &elems[0] + size();
}
#endif
SPROUT_CONSTEXPR const_reverse_iterator crbegin() const SPROUT_NOEXCEPT {
return const_reverse_iterator(end());
}
SPROUT_CONSTEXPR const_reverse_iterator crend() const SPROUT_NOEXCEPT {
return const_reverse_iterator(begin());
}
// capacity:
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
return static_size;
}
SPROUT_CONSTEXPR size_type max_size() const SPROUT_NOEXCEPT {
return size();
}
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
return size() == 0;
}
// element access:
reference operator[](size_type i) {
return elems[i];
}
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
return elems[i];
}
reference at(size_type i) {
return i < size()
? elems[i]
: (throw std::out_of_range("array<>: index out of range"), elems[i])
;
}
SPROUT_CONSTEXPR const_reference at(size_type i) const {
return i < size()
? elems[i]
: (throw std::out_of_range("array<>: index out of range"), elems[i])
;
}
reference front() {
return elems[0];
}
SPROUT_CONSTEXPR const_reference front() const {
return elems[0];
}
reference back() {
return elems[size() - 1];
}
SPROUT_CONSTEXPR const_reference back() const {
return elems[size() - 1];
}
pointer data() SPROUT_NOEXCEPT {
return &elems[0];
}
SPROUT_CONSTEXPR const_pointer data() const SPROUT_NOEXCEPT {
return &elems[0];
}
// others:
template<typename T2>
array<T, N>& operator=(array<T2, N> const& rhs) {
std::copy(rhs.begin(), rhs.end(), begin());
return *this;
}
template<typename T2>
array<T, N>& operator=(array<T2, N>&& rhs) {
std::move(rhs.begin(), rhs.end(), begin());
return *this;
}
pointer c_array() SPROUT_NOEXCEPT {
return &elems[0];
}
void assign(const_reference value) {
fill(value);
}
void rangecheck(size_type i) const {
if (i >= size()) {
throw std::out_of_range("array<>: index out of range");
}
}
};
template<typename T, std::size_t N>
SPROUT_CONSTEXPR_OR_CONST typename sprout::array<T, N>::size_type sprout::array<T, N>::static_size;
//
// swap
//
template<typename T, std::size_t N>
inline void swap(sprout::array<T, N>& lhs, sprout::array<T, N>& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) {
lhs.swap(rhs);
}
namespace detail {
template<typename T, std::size_t N, sprout::index_t... Indexes>
inline SPROUT_CONSTEXPR sprout::array<T, N> to_array_impl(
T const (& arr)[N],
sprout::index_tuple<Indexes...>
)
{
return sprout::array<T, N>{{arr[Indexes]...}};
}
} // namespace detail
//
// to_array
//
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR sprout::array<T, N> to_array(T const (& arr)[N]) {
return sprout::detail::to_array_impl(arr, sprout::index_range<0, N>::make());
}
} // namespace sprout
#endif // #ifndef SPROUT_ARRAY_ARRAY_HPP

View file

@ -0,0 +1,44 @@
#ifndef SPROUT_ARRAY_COMPARISON_HPP
#define SPROUT_ARRAY_COMPARISON_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/array/array.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
namespace sprout {
//
// operator==
// operator!=
// operator<
// operator>
// operator<=
// operator>=
//
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator==(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::equal(lhs.begin(), lhs.end(), rhs.begin());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator!=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return !(lhs == rhs);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator<(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator>(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return rhs < lhs;
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator<=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return !(rhs < lhs);
}
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR bool operator>=(sprout::array<T, N> const& lhs, sprout::array<T, N> const& rhs) {
return !(lhs < rhs);
}
} // namespace sprout
#endif // #ifndef SPROUT_ARRAY_COMPARISON_HPP

16
sprout/array/hash.hpp Normal file
View file

@ -0,0 +1,16 @@
#ifndef SPROUT_ARRAY_HASH_HPP
#define SPROUT_ARRAY_HASH_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/functional/hash/hash.hpp>
#include <sprout/array/array.hpp>
namespace sprout {
template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::array<T, N> const& v) {
return sprout::hash_range(v.begin(), v.end());
}
} // namespace sprout
#endif // #ifndef SPROUT_ARRAY_HASH_HPP

View file

@ -0,0 +1,35 @@
#ifndef SPROUT_ARRAY_MAKE_ARRAY_HPP
#define SPROUT_ARRAY_MAKE_ARRAY_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/index_tuple.hpp>
#include <sprout/array/array.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
//
// make_array
//
template<typename T, typename... Types>
inline SPROUT_CONSTEXPR sprout::array<T, sizeof...(Types)> make_array(Types&&... args) {
return sprout::array<T, sizeof...(Types)>{{sprout::forward<Types>(args)...}};
}
//
// make_common_array
//
template<typename... Types>
inline SPROUT_CONSTEXPR sprout::array<
typename std::decay<typename std::common_type<typename std::decay<Types>::type...>::type>::type,
sizeof...(Types)
> make_common_array(Types&&... args) {
return sprout::array<
typename std::decay<typename std::common_type<typename std::decay<Types>::type...>::type>::type,
sizeof...(Types)
>{{sprout::forward<Types>(args)...}};
}
} // namespace sprout
#endif // #ifndef SPROUT_ARRAY_MAKE_ARRAY_HPP

57
sprout/array/tuple.hpp Normal file
View file

@ -0,0 +1,57 @@
#ifndef SPROUT_ARRAY_TUPLE_HPP
#define SPROUT_ARRAY_TUPLE_HPP
#include <cstddef>
#include <tuple>
#include <type_traits>
#include <sprout/array/array.hpp>
#include <sprout/utility/move.hpp>
namespace sprout {
namespace tuples {
//
// get
//
template<std::size_t I, typename T, std::size_t N>
inline SPROUT_CONSTEXPR T&
get(sprout::array<T, N>& t) SPROUT_NOEXCEPT {
static_assert(I < N, "get: index out of range");
return t[I];
}
template<std::size_t I, typename T, std::size_t N>
inline SPROUT_CONSTEXPR T const&
get(sprout::array<T, N> const& t) SPROUT_NOEXCEPT {
static_assert(I < N, "get: index out of range");
return t[I];
}
template<std::size_t I, typename T, std::size_t N>
inline SPROUT_CONSTEXPR T&&
get(sprout::array<T, N>&& t) SPROUT_NOEXCEPT {
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
namespace std {
//
// tuple_size
//
template<typename T, std::size_t N>
struct tuple_size<sprout::array<T, N> >
: public std::integral_constant<std::size_t, N>
{};
//
// tuple_element
//
template<std::size_t I, typename T, std::size_t N>
struct tuple_element<I, sprout::array<T, N> > {
public:
static_assert(I < N, "tuple_element<>: index out of range");
typedef T type;
};
} // namespace std
#endif // #ifndef SPROUT_ARRAY_TUPLE_HPP

View file

@ -0,0 +1,31 @@
#ifndef SPROUT_ARRAY_TYPE_TRAITS_HPP
#define SPROUT_ARRAY_TYPE_TRAITS_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/array/array.hpp>
namespace sprout {
//
// is_array
//
template<typename T>
struct is_array
: public std::false_type
{};
template<typename T>
struct is_array<T const>
: public sprout::is_array<T>
{};
template<typename T>
struct is_array<T const volatile>
: public sprout::is_array<T>
{};
template<typename T, std::size_t N>
struct is_array<sprout::array<T, N> >
: public std::true_type
{};
} // namespace sprout
#endif // #ifndef SPROUT_ARRAY_TYPE_TRAITS_HPP

View file

@ -1,16 +0,0 @@
#ifndef SPROUT_FUNCTIONAL_HASH_ARRAY_HPP
#define SPROUT_FUNCTIONAL_HASH_ARRAY_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/functional/hash/hash.hpp>
#include <sprout/array.hpp>
namespace sprout {
template<typename T, std::size_t N>
SPROUT_CONSTEXPR std::size_t hash_value(sprout::array<T, N> const& v) {
return sprout::hash_range(v.begin(), v.end());
}
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_ARRAY_HPP

View file

@ -1,8 +0,0 @@
#ifndef SPROUT_FUNCTIONAL_HASH_BITSET_HPP
#define SPROUT_FUNCTIONAL_HASH_BITSET_HPP
#include <sprout/config.hpp>
#include <sprout/functional/hash/hash.hpp>
#include <sprout/bitset/hash.hpp>
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_BITSET_HPP

View file

@ -35,9 +35,9 @@ namespace sprout {
typename T,
typename sprout::enabler_if<std::is_pointer<typename std::remove_reference<T>::type>::value>::type
>
SPROUT_CONSTEXPR std::size_t hash_value(T&& v);
inline SPROUT_CONSTEXPR std::size_t hash_value(T&& v);
template<typename T, std::size_t N>
SPROUT_CONSTEXPR std::size_t hash_value(T const (&v)[N]);
inline SPROUT_CONSTEXPR std::size_t hash_value(T const (&v)[N]);
namespace hash_detail {
template<typename T>
@ -153,11 +153,11 @@ namespace sprout {
typename T,
typename sprout::enabler_if<std::is_pointer<typename std::remove_reference<T>::type>::value>::type = sprout::enabler
>
SPROUT_CONSTEXPR std::size_t hash_value(T&& v) {
inline SPROUT_CONSTEXPR std::size_t hash_value(T&& v) {
return sprout::hash_detail::hash_value_pointer(v);
}
template<typename T, std::size_t N>
SPROUT_CONSTEXPR std::size_t hash_value(T const (&v)[N]) {
inline SPROUT_CONSTEXPR std::size_t hash_value(T const (&v)[N]) {
return sprout::hash_range(&v[0], &v[0] + N);
}
@ -165,7 +165,7 @@ namespace sprout {
// to_hash
//
template<typename T>
SPROUT_CONSTEXPR std::size_t to_hash(T const& v) {
inline SPROUT_CONSTEXPR std::size_t to_hash(T const& v) {
using sprout::hash_value;
return hash_value(v);
}
@ -174,7 +174,7 @@ namespace sprout {
// hash_combine
//
template<typename T>
SPROUT_CONSTEXPR std::size_t hash_combine(std::size_t seed, T const& v) {
inline SPROUT_CONSTEXPR std::size_t hash_combine(std::size_t seed, T const& v) {
return seed ^ (sprout::to_hash(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
@ -182,11 +182,11 @@ namespace sprout {
// hash_range
//
template<typename Iterator>
SPROUT_CONSTEXPR std::size_t hash_range(Iterator first, Iterator last) {
inline SPROUT_CONSTEXPR std::size_t hash_range(Iterator first, Iterator last) {
return sprout::hash_range(0, first, last);
}
template<typename Iterator>
SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, Iterator first, Iterator last) {
inline SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, Iterator first, Iterator last) {
return first != last
? sprout::hash_range(sprout::hash_combine(seed, *first), sprout::next(first), last)
: seed

View file

@ -1,8 +0,0 @@
#ifndef SPROUT_FUNCTIONAL_HASH_STRING_HPP
#define SPROUT_FUNCTIONAL_HASH_STRING_HPP
#include <sprout/config.hpp>
#include <sprout/functional/hash/hash.hpp>
#include <sprout/string/hash.hpp>
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_STRING_HPP

View file

@ -1,15 +0,0 @@
#ifndef SPROUT_FUNCTIONAL_HASH_UUID_HPP
#define SPROUT_FUNCTIONAL_HASH_UUID_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/functional/hash/hash.hpp>
#include <sprout/uuid/uuid.hpp>
namespace sprout {
SPROUT_CONSTEXPR std::size_t hash_value(sprout::uuids::uuid const& v) {
return sprout::hash_range(v.begin(), v.end());
}
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_UUID_HPP

View file

@ -1,250 +1,12 @@
#ifndef SPROUT_PIT_HPP
#define SPROUT_PIT_HPP
#include <cstddef>
#include <utility>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator.hpp>
#include <sprout/iterator/value_iterator.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/array.hpp>
namespace sprout {
//
// pit
//
template<typename Container>
class pit {
public:
typedef Container container_type;
typedef typename sprout::container_traits<container_type>::value_type value_type;
typedef typename sprout::container_traits<container_type>::reference reference;
typedef typename sprout::container_traits<container_type>::const_reference const_reference;
typedef typename sprout::value_iterator<reference> iterator;
typedef typename sprout::value_iterator<const_reference> const_iterator;
typedef typename sprout::container_traits<container_type>::size_type size_type;
typedef typename sprout::container_traits<container_type>::difference_type difference_type;
typedef typename sprout::container_traits<container_type>::pointer pointer;
typedef typename sprout::container_traits<container_type>::const_pointer const_pointer;
typedef typename sprout::reverse_iterator<iterator> reverse_iterator;
typedef typename sprout::reverse_iterator<const_iterator> const_reverse_iterator;
public:
SPROUT_STATIC_CONSTEXPR size_type static_size = sprout::container_traits<container_type>::static_size;
public:
value_type elem;
public:
pit() = default;
void swap(pit& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval<value_type&>(), std::declval<value_type&>()))) {
using std::swap;
swap(elem, other.elem);
}
// iterators:
iterator begin() {
return iterator(elem, static_size);
}
SPROUT_CONSTEXPR const_iterator begin() const {
return const_iterator(elem, static_size);
}
iterator end() SPROUT_NOEXCEPT {
return iterator();
}
SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT {
return const_iterator();
}
reverse_iterator rbegin() SPROUT_NOEXCEPT {
return reverse_iterator(end());
}
SPROUT_CONSTEXPR const_reverse_iterator rbegin() const SPROUT_NOEXCEPT {
return const_reverse_iterator(end());
}
reverse_iterator rend() SPROUT_NOEXCEPT {
return reverse_iterator(begin());
}
SPROUT_CONSTEXPR const_reverse_iterator rend() const SPROUT_NOEXCEPT {
return const_reverse_iterator(begin());
}
SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT {
return const_iterator(elem, static_size);
}
SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT {
return const_iterator();
}
SPROUT_CONSTEXPR const_reverse_iterator crbegin() const SPROUT_NOEXCEPT {
return const_reverse_iterator(end());
}
SPROUT_CONSTEXPR const_reverse_iterator crend() const SPROUT_NOEXCEPT {
return const_reverse_iterator(begin());
}
// capacity:
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
return static_size;
}
SPROUT_CONSTEXPR size_type max_size() const SPROUT_NOEXCEPT {
return size();
}
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
return static_size == 0;
}
// element access:
reference operator[](size_type i) {
return elem;
}
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
return elem;
}
reference at(size_type i) {
return i < size()
? elem
: (throw std::out_of_range("pit<>: index out of range"), elem)
;
}
SPROUT_CONSTEXPR const_reference at(size_type i) const {
return i < size()
? elem
: (throw std::out_of_range("pit<>: index out of range"), elem)
;
}
reference front() {
return elem;
}
SPROUT_CONSTEXPR const_reference front() const {
return elem;
}
reference back() {
return elem;
}
SPROUT_CONSTEXPR const_reference back() const {
return elem;
}
// others:
void rangecheck(size_type i) const {
if (i >= size()) {
throw std::out_of_range("pit<>: index out of range");
}
}
};
template<typename Container>
SPROUT_CONSTEXPR_OR_CONST typename sprout::pit<Container>::size_type sprout::pit<Container>::static_size;
//
// operator==
// operator!=
// operator<
// operator>
// operator<=
// operator>=
//
template<typename Container>
inline SPROUT_CONSTEXPR bool operator==(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return lhs.front() == rhs.front();
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator!=(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return !(lhs == rhs);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator<(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return lhs.front() < rhs.front();
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator>(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return rhs < lhs;
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator<=(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return !(rhs < lhs);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator>=(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return !(lhs < rhs);
}
//
// swap
//
template<typename Container>
inline void swap(sprout::pit<Container>& lhs, sprout::pit<Container>& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) {
lhs.swap(rhs);
}
//
// container_construct_traits
//
template<typename Container>
struct container_construct_traits<sprout::pit<Container> > {
public:
typedef typename sprout::container_construct_traits<Container>::copied_type copied_type;
public:
template<typename Cont>
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) {
return copied_type();
}
template<typename... Args>
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
return sprout::make<copied_type>(sprout::forward<Args>(args)...);
}
template<typename Cont, typename... Args>
static SPROUT_CONSTEXPR copied_type remake(
Cont&& cont,
typename sprout::container_traits<sprout::pit<Container> >::difference_type size,
Args&&... args
)
{
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
}
};
//
// container_transform_traits
//
template<typename Container>
struct container_transform_traits<sprout::pit<Container> > {
public:
template<typename sprout::container_traits<sprout::pit<Container> >::size_type Size>
struct rebind_size {
public:
typedef sprout::pit<
typename sprout::container_transform_traits<Container>::template rebind_size<Size>::type
> type;
};
};
//
// blank
//
struct blank {};
//
// blank_pit
//
template<std::size_t N>
inline SPROUT_CONSTEXPR sprout::pit<sprout::array<sprout::blank, N> >
blank_pit() {
return sprout::pit<sprout::array<sprout::blank, N> >();
}
} // namespace sprout
namespace std {
//
// tuple_size
//
template<typename Container>
struct tuple_size<sprout::pit<Container> >
: public std::tuple_size<Container>
{};
//
// tuple_element
//
template<std::size_t I, typename Container>
struct tuple_element<I, sprout::pit<Container> >
: public std::tuple_element<I, Container>
{};
} // namespace std
#include <sprout/tuple/pit.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/pit/comparison.hpp>
#include <sprout/pit/hash.hpp>
#include <sprout/pit/tuple.hpp>
#include <sprout/pit/container.hpp>
#include <sprout/pit/blank.hpp>
#endif // #ifndef SPROUT_PIT_HPP

25
sprout/pit/blank.hpp Normal file
View file

@ -0,0 +1,25 @@
#ifndef SPROUT_PIT_BLANK_HPP
#define SPROUT_PIT_BLANK_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/array.hpp>
#include <sprout/pit/pit.hpp>
namespace sprout {
//
// blank
//
struct blank {};
//
// blank_pit
//
template<std::size_t N>
inline SPROUT_CONSTEXPR sprout::pit<sprout::array<sprout::blank, N> >
blank_pit() {
return sprout::pit<sprout::array<sprout::blank, N> >();
}
} // namespace sprout
#endif // #ifndef SPROUT_PIT_BLANK_HPP

42
sprout/pit/comparison.hpp Normal file
View file

@ -0,0 +1,42 @@
#ifndef SPROUT_PIT_COMPARISON_HPP
#define SPROUT_PIT_COMPARISON_HPP
#include <sprout/config.hpp>
#include <sprout/pit/pit.hpp>
namespace sprout {
//
// operator==
// operator!=
// operator<
// operator>
// operator<=
// operator>=
//
template<typename Container>
inline SPROUT_CONSTEXPR bool operator==(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return lhs.front() == rhs.front();
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator!=(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return !(lhs == rhs);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator<(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return lhs.front() < rhs.front();
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator>(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return rhs < lhs;
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator<=(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return !(rhs < lhs);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool operator>=(sprout::pit<Container> const& lhs, sprout::pit<Container> const& rhs) {
return !(lhs < rhs);
}
} // namespace sprout
#endif // #ifndef SPROUT_PIT_COMPARISON_HPP

54
sprout/pit/container.hpp Normal file
View file

@ -0,0 +1,54 @@
#ifndef SPROUT_PIT_CONTAINER_HPP
#define SPROUT_PIT_CONTAINER_HPP
#include <type_traits>
#include <sprout/utility/forward.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
namespace sprout {
//
// container_construct_traits
//
template<typename Container>
struct container_construct_traits<sprout::pit<Container> > {
public:
typedef typename sprout::container_construct_traits<Container>::copied_type copied_type;
public:
template<typename Cont>
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) {
return copied_type();
}
template<typename... Args>
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
return sprout::make<copied_type>(sprout::forward<Args>(args)...);
}
template<typename Cont, typename... Args>
static SPROUT_CONSTEXPR copied_type remake(
Cont&& cont,
typename sprout::container_traits<sprout::pit<Container> >::difference_type size,
Args&&... args
)
{
return sprout::remake<copied_type>(sprout::forward<Cont>(cont), size, sprout::forward<Args>(args)...);
}
};
//
// container_transform_traits
//
template<typename Container>
struct container_transform_traits<sprout::pit<Container> > {
public:
template<typename sprout::container_traits<sprout::pit<Container> >::size_type Size>
struct rebind_size {
public:
typedef sprout::pit<
typename sprout::container_transform_traits<Container>::template rebind_size<Size>::type
> type;
};
};
} // namespace sprout
#endif // #ifndef SPROUT_PIT_CONTAINER_HPP

View file

@ -1,9 +1,10 @@
#ifndef SPROUT_FUNCTIONAL_HASH_PIT_HPP
#define SPROUT_FUNCTIONAL_HASH_PIT_HPP
#ifndef SPROUT_PIT_HASH_HPP
#define SPROUT_PIT_HASH_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/functional/hash/hash.hpp>
#include <sprout/pit.hpp>
#include <sprout/pit/pit.hpp>
namespace sprout {
template<typename Container>
@ -12,4 +13,4 @@ namespace sprout {
}
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_PIT_HPP
#endif // #ifndef SPROUT_PIT_HASH_HPP

138
sprout/pit/pit.hpp Normal file
View file

@ -0,0 +1,138 @@
#ifndef SPROUT_PIT_PIT_HPP
#define SPROUT_PIT_PIT_HPP
#include <utility>
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator.hpp>
#include <sprout/iterator/value_iterator.hpp>
namespace sprout {
//
// pit
//
template<typename Container>
class pit {
public:
typedef Container container_type;
typedef typename sprout::container_traits<container_type>::value_type value_type;
typedef typename sprout::container_traits<container_type>::reference reference;
typedef typename sprout::container_traits<container_type>::const_reference const_reference;
typedef typename sprout::value_iterator<reference> iterator;
typedef typename sprout::value_iterator<const_reference> const_iterator;
typedef typename sprout::container_traits<container_type>::size_type size_type;
typedef typename sprout::container_traits<container_type>::difference_type difference_type;
typedef typename sprout::container_traits<container_type>::pointer pointer;
typedef typename sprout::container_traits<container_type>::const_pointer const_pointer;
typedef typename sprout::reverse_iterator<iterator> reverse_iterator;
typedef typename sprout::reverse_iterator<const_iterator> const_reverse_iterator;
public:
SPROUT_STATIC_CONSTEXPR size_type static_size = sprout::container_traits<container_type>::static_size;
public:
value_type elem;
public:
pit() = default;
void swap(pit& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval<value_type&>(), std::declval<value_type&>()))) {
using std::swap;
swap(elem, other.elem);
}
// iterators:
iterator begin() {
return iterator(elem, static_size);
}
SPROUT_CONSTEXPR const_iterator begin() const {
return const_iterator(elem, static_size);
}
iterator end() SPROUT_NOEXCEPT {
return iterator();
}
SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT {
return const_iterator();
}
reverse_iterator rbegin() SPROUT_NOEXCEPT {
return reverse_iterator(end());
}
SPROUT_CONSTEXPR const_reverse_iterator rbegin() const SPROUT_NOEXCEPT {
return const_reverse_iterator(end());
}
reverse_iterator rend() SPROUT_NOEXCEPT {
return reverse_iterator(begin());
}
SPROUT_CONSTEXPR const_reverse_iterator rend() const SPROUT_NOEXCEPT {
return const_reverse_iterator(begin());
}
SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT {
return const_iterator(elem, static_size);
}
SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT {
return const_iterator();
}
SPROUT_CONSTEXPR const_reverse_iterator crbegin() const SPROUT_NOEXCEPT {
return const_reverse_iterator(end());
}
SPROUT_CONSTEXPR const_reverse_iterator crend() const SPROUT_NOEXCEPT {
return const_reverse_iterator(begin());
}
// capacity:
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
return static_size;
}
SPROUT_CONSTEXPR size_type max_size() const SPROUT_NOEXCEPT {
return size();
}
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
return static_size == 0;
}
// element access:
reference operator[](size_type i) {
return elem;
}
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
return elem;
}
reference at(size_type i) {
return i < size()
? elem
: (throw std::out_of_range("pit<>: index out of range"), elem)
;
}
SPROUT_CONSTEXPR const_reference at(size_type i) const {
return i < size()
? elem
: (throw std::out_of_range("pit<>: index out of range"), elem)
;
}
reference front() {
return elem;
}
SPROUT_CONSTEXPR const_reference front() const {
return elem;
}
reference back() {
return elem;
}
SPROUT_CONSTEXPR const_reference back() const {
return elem;
}
// others:
void rangecheck(size_type i) const {
if (i >= size()) {
throw std::out_of_range("pit<>: index out of range");
}
}
};
template<typename Container>
SPROUT_CONSTEXPR_OR_CONST typename sprout::pit<Container>::size_type sprout::pit<Container>::static_size;
//
// swap
//
template<typename Container>
inline void swap(sprout::pit<Container>& lhs, sprout::pit<Container>& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) {
lhs.swap(rhs);
}
} // namespace sprout
#endif // #ifndef SPROUT_PIT_PIT_HPP

View file

@ -1,11 +1,11 @@
#ifndef SPROUT_TUPLE_PIT_HPP
#define SPROUT_TUPLE_PIT_HPP
#ifndef SPROUT_PIT_TUPLE_HPP
#define SPROUT_PIT_TUPLE_HPP
#include <cstddef>
#include <tuple>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/pit/pit.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/pit.hpp>
namespace sprout {
namespace tuples {
@ -36,4 +36,22 @@ namespace sprout {
using sprout::tuples::get;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_PIT_HPP
namespace std {
//
// tuple_size
//
template<typename Container>
struct tuple_size<sprout::pit<Container> >
: public std::tuple_size<Container>
{};
//
// tuple_element
//
template<std::size_t I, typename Container>
struct tuple_element<I, sprout::pit<Container> >
: public std::tuple_element<I, Container>
{};
} // namespace std
#endif // #ifndef SPROUT_PIT_TUPLE_HPP

View file

@ -7,10 +7,6 @@
#include <sprout/index_tuple.hpp>
#include <sprout/string/char_traits.hpp>
#include <sprout/string/string.hpp>
//#include <sprout/operation/fixed/push_back.hpp>
//#include <sprout/operation/fixed/push_front.hpp>
//#include <sprout/operation/fixed/append_back.hpp>
//#include <sprout/operation/fixed/append_front.hpp>
namespace sprout {
namespace detail {

View file

@ -2,6 +2,7 @@
#define SPROUT_STRING_HASH_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/string/string.hpp>
#include <sprout/functional/hash/hash.hpp>
@ -10,7 +11,7 @@ namespace sprout {
// hash_value
//
template<typename T, std::size_t N, typename Traits>
SPROUT_CONSTEXPR std::size_t hash_value(sprout::basic_string<T, N, Traits> const& v) {
inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::basic_string<T, N, Traits> const& v) {
return sprout::hash_range(v.begin(), v.end());
}
} // namespace sprout

View file

@ -1,872 +1,13 @@
#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/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/utility/forward.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
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;
}
protected:
holder_type array_;
impl_difference_type first_;
impl_difference_type last_;
public:
sub_array_impl() = default;
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]...}
, first_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), first))
, last_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), last))
{}
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))
, first_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), first))
, last_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), last))
{}
template<typename ContainerTag, sprout::index_t... Indexes>
SPROUT_CONSTEXPR sub_array_impl(
ContainerTag,
param_type arr,
sprout::index_tuple<Indexes...>,
impl_difference_type first,
impl_difference_type 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]...}
, first_(first)
, last_(last)
{}
template<typename ContainerTag, sprout::index_t... Indexes>
SPROUT_CONSTEXPR sub_array_impl(
ContainerTag,
param_type arr,
sprout::index_tuple<Indexes...>,
impl_difference_type first,
impl_difference_type last,
typename std::enable_if<!std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
)
: array_(to_holder<Container>(arr))
, first_(first)
, last_(last)
{}
};
} // 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:
SPROUT_STATIC_CONSTEXPR size_type static_size = facade_type::static_size;
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:
sub_array() = default;
SPROUT_CONSTEXPR sub_array(param_type arr, const_iterator first, const_iterator last)
: impl_type(
array_tag(),
arr,
sprout::index_range<0, static_size>::make(),
first,
last
)
{}
SPROUT_CONSTEXPR sub_array(param_type arr, difference_type first, difference_type last)
: impl_type(
array_tag(),
arr,
sprout::index_range<0, static_size>::make(),
first,
last
)
{}
SPROUT_CONSTEXPR sub_array(sub_array<Container> const& other, const_iterator first, const_iterator last)
: impl_type(
array_tag(),
impl_type::template to_param<Container>(other.array_),
sprout::index_range<0, static_size>::make(),
NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::begin(other.get_array()), first),
NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::begin(other.get_array()), last)
)
{}
SPROUT_CONSTEXPR sub_array(sub_array<Container> const& other, difference_type first, difference_type last)
: impl_type(
array_tag(),
impl_type::template to_param<Container>(other.array_),
sprout::index_range<0, static_size>::make(),
first + other.first_,
last + other.first_
)
{}
void fill(const_reference value) {
std::fill_n(begin(), size(), value);
}
template<typename Container2>
void swap(sub_array<Container2>& other) {
using std::swap;
swap(other.array_, array_);
swap(other.first_, first_);
swap(other.last_, last_);
}
// iterators:
iterator begin() {
return sprout::next(sprout::begin(get_array()), first_);
}
SPROUT_CONSTEXPR const_iterator begin() const {
return sprout::next(sprout::begin(get_array()), first_);
}
iterator end() {
return sprout::next(sprout::begin(get_array()), last_);
}
SPROUT_CONSTEXPR const_iterator end() const {
return sprout::next(sprout::begin(get_array()), last_);
}
SPROUT_CONSTEXPR const_iterator cbegin() const {
return sprout::next(sprout::begin(get_array()), first_);
}
SPROUT_CONSTEXPR const_iterator cend() const {
return sprout::next(sprout::begin(get_array()), last_);
}
// 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 first_ == last_;
}
// element access:
reference operator[](size_type i) {
return *sprout::next(sprout::begin(get_array()), first_ + i);
}
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
return *sprout::next(sprout::begin(get_array()), first_ + i);
}
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))
;
}
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))
;
}
reference front() {
return *sprout::next(sprout::begin(get_array()), first_);
}
SPROUT_CONSTEXPR const_reference front() const {
return *sprout::next(sprout::begin(get_array()), first_);
}
reference back() {
return *sprout::next(sprout::begin(get_array()), last_ - 1);
}
SPROUT_CONSTEXPR const_reference back() const {
return *sprout::next(sprout::begin(get_array()), last_ - 1);
}
pointer data() {
return get_array().data() + first_;
}
SPROUT_CONSTEXPR const_pointer data() const {
return get_array().data() + first_;
}
// others:
template<typename Container2>
sub_array<Container>& operator=(sub_array<Container2> const& rhs) {
array_ = rhs.array_;
first_ = rhs.first_;
last_ = rhs.last_;
return *this;
}
template<typename Container2>
sub_array<Container>& operator=(sub_array<Container2>&& rhs) {
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_internal() {
return impl_type::template to_param<Container>(array_);
}
SPROUT_CONSTEXPR const_param_type get_internal() 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_);
}
};
template<typename Container>
SPROUT_CONSTEXPR_OR_CONST typename sprout::sub_array<Container>::size_type sprout::sub_array<Container>::static_size;
//
// swap
//
template<typename Container>
inline void swap(sprout::sub_array<Container>& lhs, sprout::sub_array<Container>& rhs) {
lhs.swap(rhs);
}
//
// operator==
// operator!=
// operator<
// operator>
// operator<=
// operator>=
//
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator==(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::equal(sprout::begin(lhs), sprout::end(lhs), sprout::begin(rhs));
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator!=(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return !(lhs == rhs);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator<(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(
sprout::begin(lhs), sprout::end(lhs),
sprout::begin(rhs), sprout::end(rhs)
);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator>(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return rhs < lhs;
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator<=(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return !(rhs < lhs);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator>=(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return !(lhs < rhs);
}
//
// container_construct_traits
//
template<typename Container>
struct container_construct_traits<sprout::sub_array<Container> > {
private:
typedef typename sprout::sub_array<Container>::internal_type internal_type;
typedef typename sprout::container_construct_traits<internal_type>::copied_type internal_copied_type;
public:
typedef sprout::sub_array<internal_copied_type> copied_type;
private:
static SPROUT_CONSTEXPR copied_type make_impl(internal_copied_type const& internal_copied) {
return copied_type(internal_copied, sprout::begin(internal_copied), sprout::end(internal_copied));
}
template<typename Cont>
static SPROUT_CONSTEXPR copied_type remake_impl(
Cont&& cont,
typename sprout::container_traits<sprout::sub_array<Container> >::difference_type size,
internal_copied_type const& internal_copied
)
{
return copied_type(
internal_copied,
sprout::next(sprout::begin(internal_copied), sprout::internal_begin_offset(cont)),
sprout::next(sprout::begin(internal_copied), sprout::internal_begin_offset(cont) + size)
);
}
public:
template<typename Cont>
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) {
return copied_type(
sprout::deep_copy(sprout::get_internal(cont)),
sprout::internal_begin_offset(cont),
sprout::internal_end_offset(cont)
);
}
template<typename... Args>
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
return make_impl(
sprout::make<internal_type>(sprout::forward<Args>(args)...)
);
}
template<typename Cont, typename... Args>
static SPROUT_CONSTEXPR copied_type remake(
Cont&& cont,
typename sprout::container_traits<sprout::sub_array<Container> >::difference_type size,
Args&&... args
)
{
return remake_impl(
sprout::forward<Cont>(cont),
size,
sprout::make<internal_type>(sprout::forward<Args>(args)...)
);
}
};
//
// container_transform_traits
//
template<typename Container>
struct container_transform_traits<sprout::sub_array<Container> > {
public:
template<typename sprout::container_traits<sprout::sub_array<Container> >::size_type Size>
struct rebind_size {
public:
typedef sprout::sub_array<
typename sprout::container_transform_traits<
typename std::remove_reference<Container>::type
>::template rebind_size<Size>::type
> type;
};
};
//
// sub_container_traits
//
template<typename Container>
struct sub_container_traits<sprout::sub_array<Container> > {
private:
static typename sprout::sub_array<Container>::param_type
call(sprout::sub_array<Container>& cont) {
return cont.get_internal();
}
static SPROUT_CONSTEXPR typename sprout::sub_array<Container>::const_param_type
call(sprout::sub_array<Container> const& cont) {
return cont.get_internal();
}
public:
template<typename Cont>
struct internal {
public:
typedef decltype(call(std::declval<Cont&&>())) type;
};
public:
template<typename Cont>
static SPROUT_CONSTEXPR typename internal<Cont>::type get_internal(Cont&& cont) {
return call(sprout::forward<Cont>(cont));
}
};
//
// is_sub_array
//
template<typename T>
struct is_sub_array
: public std::false_type
{};
template<typename T>
struct is_sub_array<T const>
: public sprout::is_sub_array<T>
{};
template<typename T>
struct is_sub_array<T const volatile>
: public sprout::is_sub_array<T>
{};
template<typename Container>
struct is_sub_array<sprout::sub_array<Container> >
: public std::true_type
{};
//
// sub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::container_traits<sprout::sub_array<Container&> >::const_iterator first,
typename sprout::container_traits<sprout::sub_array<Container&> >::const_iterator last
)
{
return sprout::sub_array<Container&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::container_traits<sprout::sub_array<Container&> >::difference_type first,
typename sprout::container_traits<sprout::sub_array<Container&> >::difference_type last
)
{
return sprout::sub_array<Container&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::container_traits<sprout::sub_array<Container&> >::const_iterator first
)
{
return sprout::sub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::container_traits<sprout::sub_array<Container&> >::difference_type first
)
{
return sprout::sub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr
)
{
return sprout::sub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator first,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator last
)
{
return sprout::sub_array<Container const&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type first,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type last
)
{
return sprout::sub_array<Container const&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator first
)
{
return sprout::sub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type first
)
{
return sprout::sub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr
)
{
return sprout::sub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first,
typename sprout::container_traits<Container>::const_iterator last
)
{
return Container(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first,
typename sprout::container_traits<Container>::difference_type last
)
{
return Container(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first
)
{
return sprout::sub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first
)
{
return sprout::sub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr
)
{
return sprout::sub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// csub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator first,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator last
)
{
return sprout::sub_array<Container const&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type first,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type last
)
{
return sprout::sub_array<Container const&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator first
)
{
return sprout::csub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type first
)
{
return sprout::csub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr
)
{
return sprout::csub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// csub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first,
typename sprout::container_traits<Container>::const_iterator last
)
{
return sprout::sub_array<typename Container::internal_type const&>(arr.get_array(), first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first,
typename sprout::container_traits<Container>::difference_type last
)
{
return sprout::sub_array<typename Container::internal_type const&>(
arr.get_array(),
sprout::next(sprout::begin(arr), first),
sprout::next(sprout::begin(arr), last)
);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first
)
{
return sprout::csub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first
)
{
return sprout::csub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr
)
{
return sprout::csub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub_copy
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first,
typename sprout::container_traits<Container>::const_iterator last
)
{
return sprout::sub_array<Container>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first,
typename sprout::container_traits<Container>::difference_type last
)
{
return sprout::sub_array<Container>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first
)
{
return sprout::sub_copy(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first
)
{
return sprout::sub_copy(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr
)
{
return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub_copy
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first,
typename sprout::container_traits<Container>::const_iterator last
)
{
return sprout::sub_array<typename Container::internal_type>(arr.get_array(), first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first,
typename sprout::container_traits<Container>::difference_type last
)
{
return sprout::sub_array<typename Container::internal_type>(
arr.get_array(),
sprout::next(sprout::begin(arr), first),
sprout::next(sprout::begin(arr), last)
);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first
)
{
return sprout::sub_copy(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first
)
{
return sprout::sub_copy(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr
)
{
return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr));
}
} // namespace sprout
namespace std {
//
// tuple_size
//
template<typename Container>
struct tuple_size<sprout::sub_array<Container> >
: public std::tuple_size<typename std::remove_reference<Container>::type>
{};
//
// tuple_element
//
template<std::size_t I, typename Container>
struct tuple_element<I, sprout::sub_array<Container> >
: public std::tuple_element<I, typename std::remove_reference<Container>::type>
{};
} // namespace std
#include <sprout/tuple/sub_array.hpp>
#include <sprout/sub_array/sub_array.hpp>
#include <sprout/sub_array/comparison.hpp>
#include <sprout/sub_array/hash.hpp>
#include <sprout/sub_array/tuple.hpp>
#include <sprout/sub_array/container.hpp>
#include <sprout/sub_array/sub.hpp>
#include <sprout/sub_array/type_traits.hpp>
#endif // #ifndef SPROUT_SUB_ARRAY_HPP

View file

@ -0,0 +1,53 @@
#ifndef SPROUT_SUB_ARRAY_COMPARISON_HPP
#define SPROUT_SUB_ARRAY_COMPARISON_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/sub_array/sub_array.hpp>
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT
namespace sprout {
//
// operator==
// operator!=
// operator<
// operator>
// operator<=
// operator>=
//
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator==(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::equal(sprout::begin(lhs), sprout::end(lhs), sprout::begin(rhs));
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator!=(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return !(lhs == rhs);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator<(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(
sprout::begin(lhs), sprout::end(lhs),
sprout::begin(rhs), sprout::end(rhs)
);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator>(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return rhs < lhs;
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator<=(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return !(rhs < lhs);
}
template<typename Container>
inline SPROUT_CONSTEXPR bool
operator>=(sprout::sub_array<Container> const& lhs, sprout::sub_array<Container> const& rhs) {
return !(lhs < rhs);
}
} // namespace sprout
#endif // #ifndef SPROUT_SUB_ARRAY_COMPARISON_HPP

View file

@ -0,0 +1,116 @@
#ifndef SPROUT_SUB_ARRAY_CONTAINER_HPP
#define SPROUT_SUB_ARRAY_CONTAINER_HPP
#include <utility>
#include <type_traits>
#include <sprout/utility/forward.hpp>
#include <sprout/sub_array/sub_array.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
namespace sprout {
//
// container_construct_traits
//
template<typename Container>
struct container_construct_traits<sprout::sub_array<Container> > {
private:
typedef typename sprout::sub_array<Container>::internal_type internal_type;
typedef typename sprout::container_construct_traits<internal_type>::copied_type internal_copied_type;
public:
typedef sprout::sub_array<internal_copied_type> copied_type;
private:
static SPROUT_CONSTEXPR copied_type make_impl(internal_copied_type const& internal_copied) {
return copied_type(internal_copied, sprout::begin(internal_copied), sprout::end(internal_copied));
}
template<typename Cont>
static SPROUT_CONSTEXPR copied_type remake_impl(
Cont&& cont,
typename sprout::container_traits<sprout::sub_array<Container> >::difference_type size,
internal_copied_type const& internal_copied
)
{
return copied_type(
internal_copied,
sprout::next(sprout::begin(internal_copied), sprout::internal_begin_offset(cont)),
sprout::next(sprout::begin(internal_copied), sprout::internal_begin_offset(cont) + size)
);
}
public:
template<typename Cont>
static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) {
return copied_type(
sprout::deep_copy(sprout::get_internal(cont)),
sprout::internal_begin_offset(cont),
sprout::internal_end_offset(cont)
);
}
template<typename... Args>
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
return make_impl(
sprout::make<internal_type>(sprout::forward<Args>(args)...)
);
}
template<typename Cont, typename... Args>
static SPROUT_CONSTEXPR copied_type remake(
Cont&& cont,
typename sprout::container_traits<sprout::sub_array<Container> >::difference_type size,
Args&&... args
)
{
return remake_impl(
sprout::forward<Cont>(cont),
size,
sprout::make<internal_type>(sprout::forward<Args>(args)...)
);
}
};
//
// container_transform_traits
//
template<typename Container>
struct container_transform_traits<sprout::sub_array<Container> > {
public:
template<typename sprout::container_traits<sprout::sub_array<Container> >::size_type Size>
struct rebind_size {
public:
typedef sprout::sub_array<
typename sprout::container_transform_traits<
typename std::remove_reference<Container>::type
>::template rebind_size<Size>::type
> type;
};
};
//
// sub_container_traits
//
template<typename Container>
struct sub_container_traits<sprout::sub_array<Container> > {
private:
static typename sprout::sub_array<Container>::param_type
call(sprout::sub_array<Container>& cont) {
return cont.get_internal();
}
static SPROUT_CONSTEXPR typename sprout::sub_array<Container>::const_param_type
call(sprout::sub_array<Container> const& cont) {
return cont.get_internal();
}
public:
template<typename Cont>
struct internal {
public:
typedef decltype(call(std::declval<Cont&&>())) type;
};
public:
template<typename Cont>
static SPROUT_CONSTEXPR typename internal<Cont>::type get_internal(Cont&& cont) {
return call(sprout::forward<Cont>(cont));
}
};
} // namespace sprout
#endif // #ifndef SPROUT_SUB_ARRAY_CONTAINER_HPP

View file

@ -1,10 +1,9 @@
#ifndef SPROUT_FUNCTIONAL_HASH_SUB_ARRAY_HPP
#define SPROUT_FUNCTIONAL_HASH_SUB_ARRAY_HPP
#ifndef SPROUT_SUB_ARRAY_HASH_HPP
#define SPROUT_SUB_ARRAY_HASH_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/functional/hash/hash.hpp>
#include <sprout/sub_array.hpp>
#include <sprout/sub_array/sub_array.hpp>
namespace sprout {
template<typename Container>
@ -13,4 +12,4 @@ namespace sprout {
}
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_SUB_ARRAY_HPP
#endif // #ifndef SPROUT_SUB_ARRAY_HASH_HPP

334
sprout/sub_array/sub.hpp Normal file
View file

@ -0,0 +1,334 @@
#ifndef SPROUT_SUB_ARRAY_SUB_HPP
#define SPROUT_SUB_ARRAY_SUB_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/sub_array/sub_array.hpp>
#include <sprout/sub_array/container.hpp>
#include <sprout/sub_array/type_traits.hpp>
namespace sprout {
//
// sub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::container_traits<sprout::sub_array<Container&> >::const_iterator first,
typename sprout::container_traits<sprout::sub_array<Container&> >::const_iterator last
)
{
return sprout::sub_array<Container&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::container_traits<sprout::sub_array<Container&> >::difference_type first,
typename sprout::container_traits<sprout::sub_array<Container&> >::difference_type last
)
{
return sprout::sub_array<Container&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::container_traits<sprout::sub_array<Container&> >::const_iterator first
)
{
return sprout::sub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr,
typename sprout::container_traits<sprout::sub_array<Container&> >::difference_type first
)
{
return sprout::sub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container&> >::type sub(
Container& arr
)
{
return sprout::sub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator first,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator last
)
{
return sprout::sub_array<Container const&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type first,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type last
)
{
return sprout::sub_array<Container const&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator first
)
{
return sprout::sub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type first
)
{
return sprout::sub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type sub(
Container const& arr
)
{
return sprout::sub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first,
typename sprout::container_traits<Container>::const_iterator last
)
{
return Container(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first,
typename sprout::container_traits<Container>::difference_type last
)
{
return Container(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first
)
{
return sprout::sub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first
)
{
return sprout::sub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, Container>::type sub(
Container const& arr
)
{
return sprout::sub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// csub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator first,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator last
)
{
return sprout::sub_array<Container const&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type first,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type last
)
{
return sprout::sub_array<Container const&>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::const_iterator first
)
{
return sprout::csub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr,
typename sprout::container_traits<sprout::sub_array<Container const&> >::difference_type first
)
{
return sprout::csub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container const&> >::type csub(
Container const& arr
)
{
return sprout::csub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// csub
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first,
typename sprout::container_traits<Container>::const_iterator last
)
{
return sprout::sub_array<typename Container::internal_type const&>(arr.get_array(), first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first,
typename sprout::container_traits<Container>::difference_type last
)
{
return sprout::sub_array<typename Container::internal_type const&>(
arr.get_array(),
sprout::next(sprout::begin(arr), first),
sprout::next(sprout::begin(arr), last)
);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first
)
{
return sprout::csub(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first
)
{
return sprout::csub(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type const&> >::type csub(
Container const& arr
)
{
return sprout::csub(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub_copy
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first,
typename sprout::container_traits<Container>::const_iterator last
)
{
return sprout::sub_array<Container>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first,
typename sprout::container_traits<Container>::difference_type last
)
{
return sprout::sub_array<Container>(arr, first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first
)
{
return sprout::sub_copy(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first
)
{
return sprout::sub_copy(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<!sprout::is_sub_array<Container>::value, sprout::sub_array<Container> >::type sub_copy(
Container const& arr
)
{
return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr));
}
//
// sub_copy
//
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first,
typename sprout::container_traits<Container>::const_iterator last
)
{
return sprout::sub_array<typename Container::internal_type>(arr.get_array(), first, last);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first,
typename sprout::container_traits<Container>::difference_type last
)
{
return sprout::sub_array<typename Container::internal_type>(
arr.get_array(),
sprout::next(sprout::begin(arr), first),
sprout::next(sprout::begin(arr), last)
);
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::const_iterator first
)
{
return sprout::sub_copy(arr, first, sprout::end(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr,
typename sprout::container_traits<Container>::difference_type first
)
{
return sprout::sub_copy(arr, first, sprout::size(arr));
}
template<typename Container>
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::is_sub_array<Container>::value, sprout::sub_array<typename Container::internal_type> >::type sub_copy(
Container const& arr
)
{
return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr));
}
} // namespace sprout
#endif // #ifndef SPROUT_SUB_ARRAY_SUB_HPP

View file

@ -0,0 +1,368 @@
#ifndef SPROUT_SUB_ARRAY_SUB_ARRAY_HPP
#define SPROUT_SUB_ARRAY_SUB_ARRAY_HPP
#include <algorithm>
#include <utility>
#include <stdexcept>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/index_tuple.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
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;
}
protected:
holder_type array_;
impl_difference_type first_;
impl_difference_type last_;
public:
sub_array_impl() = default;
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]...}
, first_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), first))
, last_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), last))
{}
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))
, first_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), first))
, last_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), last))
{}
template<typename ContainerTag, sprout::index_t... Indexes>
SPROUT_CONSTEXPR sub_array_impl(
ContainerTag,
param_type arr,
sprout::index_tuple<Indexes...>,
impl_difference_type first,
impl_difference_type 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]...}
, first_(first)
, last_(last)
{}
template<typename ContainerTag, sprout::index_t... Indexes>
SPROUT_CONSTEXPR sub_array_impl(
ContainerTag,
param_type arr,
sprout::index_tuple<Indexes...>,
impl_difference_type first,
impl_difference_type last,
typename std::enable_if<!std::is_same<ContainerTag, sprout::detail::is_non_reference_array_tag>::value>::type* = 0
)
: array_(to_holder<Container>(arr))
, first_(first)
, last_(last)
{}
};
} // 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:
SPROUT_STATIC_CONSTEXPR size_type static_size = facade_type::static_size;
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:
sub_array() = default;
SPROUT_CONSTEXPR sub_array(param_type arr, const_iterator first, const_iterator last)
: impl_type(
array_tag(),
arr,
sprout::index_range<0, static_size>::make(),
first,
last
)
{}
SPROUT_CONSTEXPR sub_array(param_type arr, difference_type first, difference_type last)
: impl_type(
array_tag(),
arr,
sprout::index_range<0, static_size>::make(),
first,
last
)
{}
SPROUT_CONSTEXPR sub_array(sub_array<Container> const& other, const_iterator first, const_iterator last)
: impl_type(
array_tag(),
impl_type::template to_param<Container>(other.array_),
sprout::index_range<0, static_size>::make(),
NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::begin(other.get_array()), first),
NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::begin(other.get_array()), last)
)
{}
SPROUT_CONSTEXPR sub_array(sub_array<Container> const& other, difference_type first, difference_type last)
: impl_type(
array_tag(),
impl_type::template to_param<Container>(other.array_),
sprout::index_range<0, static_size>::make(),
first + other.first_,
last + other.first_
)
{}
void fill(const_reference value) {
std::fill_n(begin(), size(), value);
}
template<typename Container2>
void swap(sub_array<Container2>& other) {
using std::swap;
swap(other.array_, array_);
swap(other.first_, first_);
swap(other.last_, last_);
}
// iterators:
iterator begin() {
return sprout::next(sprout::begin(get_array()), first_);
}
SPROUT_CONSTEXPR const_iterator begin() const {
return sprout::next(sprout::begin(get_array()), first_);
}
iterator end() {
return sprout::next(sprout::begin(get_array()), last_);
}
SPROUT_CONSTEXPR const_iterator end() const {
return sprout::next(sprout::begin(get_array()), last_);
}
SPROUT_CONSTEXPR const_iterator cbegin() const {
return sprout::next(sprout::begin(get_array()), first_);
}
SPROUT_CONSTEXPR const_iterator cend() const {
return sprout::next(sprout::begin(get_array()), last_);
}
// 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 first_ == last_;
}
// element access:
reference operator[](size_type i) {
return *sprout::next(sprout::begin(get_array()), first_ + i);
}
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
return *sprout::next(sprout::begin(get_array()), first_ + i);
}
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))
;
}
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))
;
}
reference front() {
return *sprout::next(sprout::begin(get_array()), first_);
}
SPROUT_CONSTEXPR const_reference front() const {
return *sprout::next(sprout::begin(get_array()), first_);
}
reference back() {
return *sprout::next(sprout::begin(get_array()), last_ - 1);
}
SPROUT_CONSTEXPR const_reference back() const {
return *sprout::next(sprout::begin(get_array()), last_ - 1);
}
pointer data() {
return get_array().data() + first_;
}
SPROUT_CONSTEXPR const_pointer data() const {
return get_array().data() + first_;
}
// others:
template<typename Container2>
sub_array<Container>& operator=(sub_array<Container2> const& rhs) {
array_ = rhs.array_;
first_ = rhs.first_;
last_ = rhs.last_;
return *this;
}
template<typename Container2>
sub_array<Container>& operator=(sub_array<Container2>&& rhs) {
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_internal() {
return impl_type::template to_param<Container>(array_);
}
SPROUT_CONSTEXPR const_param_type get_internal() 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_);
}
};
template<typename Container>
SPROUT_CONSTEXPR_OR_CONST typename sprout::sub_array<Container>::size_type sprout::sub_array<Container>::static_size;
//
// swap
//
template<typename Container>
inline void swap(sprout::sub_array<Container>& lhs, sprout::sub_array<Container>& rhs) {
lhs.swap(rhs);
}
} // namespace sprout
#endif // #ifndef SPROUT_SUB_ARRAY_SUB_ARRAY_HPP

View file

@ -0,0 +1,66 @@
#ifndef SPROUT_SUB_ARRAY_TUPLE_HPP
#define SPROUT_SUB_ARRAY_TUPLE_HPP
#include <cstddef>
#include <type_traits>
#include <tuple>
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/operation.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/sub_array/sub_array.hpp>
#include <sprout/sub_array/container.hpp>
namespace sprout {
namespace tuples {
//
// get
//
template<std::size_t I, typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<sprout::sub_array<Container> >::value_type&
get(sprout::sub_array<Container>& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I)))
{
static_assert(I < sprout::container_traits<sprout::sub_array<Container> >::static_size, "get: index out of range");
return *sprout::next(sprout::internal_begin(t), I);
}
template<std::size_t I, typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<sprout::sub_array<Container> >::value_type const&
get(sprout::sub_array<Container> const& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I)))
{
static_assert(I < sprout::container_traits<sprout::sub_array<Container> >::static_size, "get: index out of range");
return *sprout::next(sprout::internal_begin(t), I);
}
template<std::size_t I, typename Container>
inline SPROUT_CONSTEXPR typename sprout::container_traits<sprout::sub_array<Container> >::value_type&&
get(sprout::sub_array<Container>&& t)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get<I>(t))))
{
return sprout::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
namespace std {
//
// tuple_size
//
template<typename Container>
struct tuple_size<sprout::sub_array<Container> >
: public std::tuple_size<typename std::remove_reference<Container>::type>
{};
//
// tuple_element
//
template<std::size_t I, typename Container>
struct tuple_element<I, sprout::sub_array<Container> >
: public std::tuple_element<I, typename std::remove_reference<Container>::type>
{};
} // namespace std
#endif // #ifndef SPROUT_SUB_ARRAY_TUPLE_HPP

View file

@ -0,0 +1,30 @@
#ifndef SPROUT_SUB_ARRAY_TYPE_TRAITS_HPP
#define SPROUT_SUB_ARRAY_TYPE_TRAITS_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/sub_array/sub_array.hpp>
namespace sprout {
//
// is_sub_array
//
template<typename T>
struct is_sub_array
: public std::false_type
{};
template<typename T>
struct is_sub_array<T const>
: public sprout::is_sub_array<T>
{};
template<typename T>
struct is_sub_array<T const volatile>
: public sprout::is_sub_array<T>
{};
template<typename Container>
struct is_sub_array<sprout::sub_array<Container> >
: public std::true_type
{};
} // namespace sprout
#endif // #ifndef SPROUT_SUB_ARRAY_TYPE_TRAITS_HPP

View file

@ -1,7 +0,0 @@
#ifndef SPROUT_TUPLE_ARRAY_HPP
#define SPROUT_TUPLE_ARRAY_HPP
#include <sprout/config.hpp>
#include <sprout/array.hpp>
#endif // #ifndef SPROUT_TUPLE_ARRAY_HPP

View file

@ -1,7 +0,0 @@
#ifndef SPROUT_TUPLE_STRING_HPP
#define SPROUT_TUPLE_STRING_HPP
#include <sprout/config.hpp>
#include <sprout/string/tuple.hpp>
#endif // #ifndef SPROUT_TUPLE_STRING_HPP

View file

@ -5,6 +5,7 @@
#include <sprout/uuid/uuid.hpp>
#include <sprout/uuid/uuid_io.hpp>
#include <sprout/uuid/uuid_hash.hpp>
#include <sprout/uuid/uuid_tuple.hpp>
#include <sprout/uuid/uuid_generators.hpp>
#include <sprout/uuid/udl.hpp>

View file

@ -259,28 +259,4 @@ namespace sprout {
using sprout::uuids::uuid;
} // namespace sprout
namespace std {
//
// tuple_size
//
template<>
struct tuple_size<sprout::uuids::uuid> {
public:
typedef std::integral_constant<std::size_t, 16> type;
SPROUT_STATIC_CONSTEXPR std::size_t value = type::value;
};
//
// tuple_element
//
template<std::size_t I>
struct tuple_element<I, sprout::uuids::uuid> {
public:
static_assert(I < 16, "tuple_element<>: index out of range");
typedef sprout::uuids::uuid::value_type type;
};
} // namespace std
#include <sprout/tuple/uuid.hpp>
#endif // #ifndef SPROUT_UUID_UUID_HPP

View file

@ -1,7 +1,15 @@
#ifndef SPROUT_UUID_UUID_HASH_HPP
#define SPROUT_UUID_UUID_HASH_HPP
#include <cstddef>
#include <sprout/config.hpp>
#include <sprout/functional/hash/uuid.hpp>
#include <sprout/functional/hash/hash.hpp>
#include <sprout/uuid/uuid.hpp>
namespace sprout {
SPROUT_CONSTEXPR std::size_t hash_value(sprout::uuids::uuid const& v) {
return sprout::hash_range(v.begin(), v.end());
}
} // namespace sprout
#endif // #ifndef SPROUT_UUID_UUID_HASH_HPP

View file

@ -1,7 +1,8 @@
#ifndef SPROUT_TUPLE_UUID_HPP
#define SPROUT_TUPLE_UUID_HPP
#ifndef SPROUT_UUID_UUID_TUPLE_HPP
#define SPROUT_UUID_UUID_TUPLE_HPP
#include <cstddef>
#include <tuple>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/move.hpp>
@ -34,4 +35,26 @@ namespace sprout {
using sprout::tuples::get;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_UUID_HPP
namespace std {
//
// tuple_size
//
template<>
struct tuple_size<sprout::uuids::uuid> {
public:
typedef std::integral_constant<std::size_t, 16> type;
SPROUT_STATIC_CONSTEXPR std::size_t value = type::value;
};
//
// tuple_element
//
template<std::size_t I>
struct tuple_element<I, sprout::uuids::uuid> {
public:
static_assert(I < 16, "tuple_element<>: index out of range");
typedef sprout::uuids::uuid::value_type type;
};
} // namespace std
#endif // #ifndef SPROUT_UUID_UUID_TUPLE_HPP