From ee8c952d05a9ef4e936d5a61aed32d1aa645f721 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Fri, 22 Jun 2012 19:14:21 +0900 Subject: [PATCH] modify: tuple and hash support(class adapt) implemented in each class headers. --- sprout/array.hpp | 337 +------ sprout/array/array.hpp | 214 +++++ sprout/array/comparison.hpp | 44 + sprout/array/hash.hpp | 16 + sprout/array/make_array.hpp | 35 + sprout/array/tuple.hpp | 57 ++ sprout/array/type_traits.hpp | 31 + sprout/functional/hash/array.hpp | 16 - sprout/functional/hash/bitset.hpp | 8 - sprout/functional/hash/hash.hpp | 16 +- sprout/functional/hash/string.hpp | 8 - sprout/functional/hash/uuid.hpp | 15 - sprout/pit.hpp | 250 +---- sprout/pit/blank.hpp | 25 + sprout/pit/comparison.hpp | 42 + sprout/pit/container.hpp | 54 ++ .../{functional/hash/pit.hpp => pit/hash.hpp} | 9 +- sprout/pit/pit.hpp | 138 +++ sprout/{tuple/pit.hpp => pit/tuple.hpp} | 28 +- sprout/string/concat.hpp | 4 - sprout/string/hash.hpp | 3 +- sprout/sub_array.hpp | 873 +----------------- sprout/sub_array/comparison.hpp | 53 ++ sprout/sub_array/container.hpp | 116 +++ .../hash/sub_array.hpp => sub_array/hash.hpp} | 9 +- sprout/sub_array/sub.hpp | 334 +++++++ sprout/sub_array/sub_array.hpp | 368 ++++++++ sprout/sub_array/tuple.hpp | 66 ++ sprout/sub_array/type_traits.hpp | 30 + sprout/tuple/array.hpp | 7 - sprout/tuple/string.hpp | 7 - sprout/uuid.hpp | 1 + sprout/uuid/uuid.hpp | 24 - sprout/uuid/uuid_hash.hpp | 10 +- .../{tuple/uuid.hpp => uuid/uuid_tuple.hpp} | 29 +- 35 files changed, 1720 insertions(+), 1557 deletions(-) create mode 100644 sprout/array/array.hpp create mode 100644 sprout/array/comparison.hpp create mode 100644 sprout/array/hash.hpp create mode 100644 sprout/array/make_array.hpp create mode 100644 sprout/array/tuple.hpp create mode 100644 sprout/array/type_traits.hpp delete mode 100644 sprout/functional/hash/array.hpp delete mode 100644 sprout/functional/hash/bitset.hpp delete mode 100644 sprout/functional/hash/string.hpp delete mode 100644 sprout/functional/hash/uuid.hpp create mode 100644 sprout/pit/blank.hpp create mode 100644 sprout/pit/comparison.hpp create mode 100644 sprout/pit/container.hpp rename sprout/{functional/hash/pit.hpp => pit/hash.hpp} (60%) create mode 100644 sprout/pit/pit.hpp rename sprout/{tuple/pit.hpp => pit/tuple.hpp} (68%) create mode 100644 sprout/sub_array/comparison.hpp create mode 100644 sprout/sub_array/container.hpp rename sprout/{functional/hash/sub_array.hpp => sub_array/hash.hpp} (56%) create mode 100644 sprout/sub_array/sub.hpp create mode 100644 sprout/sub_array/sub_array.hpp create mode 100644 sprout/sub_array/tuple.hpp create mode 100644 sprout/sub_array/type_traits.hpp delete mode 100644 sprout/tuple/array.hpp delete mode 100644 sprout/tuple/string.hpp rename sprout/{tuple/uuid.hpp => uuid/uuid_tuple.hpp} (57%) diff --git a/sprout/array.hpp b/sprout/array.hpp index 77a13bc4..3492f4d8 100644 --- a/sprout/array.hpp +++ b/sprout/array.hpp @@ -1,337 +1,12 @@ #ifndef SPROUT_ARRAY_HPP #define SPROUT_ARRAY_HPP -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT -#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION -# include -#endif - -namespace sprout { - // - // array - // - template - class array { - public: - typedef T value_type; -#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION - typedef sprout::index_iterator iterator; - typedef sprout::index_iterator 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 reverse_iterator; - typedef sprout::reverse_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& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) { - 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 - array& operator=(array const& rhs) { - std::copy(rhs.begin(), rhs.end(), begin()); - return *this; - } - template - array& operator=(array&& 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 - SPROUT_CONSTEXPR_OR_CONST typename sprout::array::size_type sprout::array::static_size; - - // - // operator== - // operator!= - // operator< - // operator> - // operator<= - // operator>= - // - template - inline SPROUT_CONSTEXPR bool operator==(sprout::array const& lhs, sprout::array const& rhs) { - return NS_SSCRISK_CEL_OR_SPROUT::equal(lhs.begin(), lhs.end(), rhs.begin()); - } - template - inline SPROUT_CONSTEXPR bool operator!=(sprout::array const& lhs, sprout::array const& rhs) { - return !(lhs == rhs); - } - template - inline SPROUT_CONSTEXPR bool operator<(sprout::array const& lhs, sprout::array const& rhs) { - return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); - } - template - inline SPROUT_CONSTEXPR bool operator>(sprout::array const& lhs, sprout::array const& rhs) { - return rhs < lhs; - } - template - inline SPROUT_CONSTEXPR bool operator<=(sprout::array const& lhs, sprout::array const& rhs) { - return !(rhs < lhs); - } - template - inline SPROUT_CONSTEXPR bool operator>=(sprout::array const& lhs, sprout::array const& rhs) { - return !(lhs < rhs); - } - - // - // swap - // - template - inline void swap(sprout::array& lhs, sprout::array& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { - lhs.swap(rhs); - } - - // - // make_array - // - template - inline SPROUT_CONSTEXPR sprout::array make_array(Types&&... args) { - return sprout::array{{sprout::forward(args)...}}; - } - - // - // make_common_array - // - template - inline SPROUT_CONSTEXPR sprout::array< - typename std::decay::type...>::type>::type, - sizeof...(Types) - > make_common_array(Types&&... args) { - return sprout::array< - typename std::decay::type...>::type>::type, - sizeof...(Types) - >{{sprout::forward(args)...}}; - } - - namespace detail { - template - inline SPROUT_CONSTEXPR sprout::array to_array_impl( - T const (& arr)[N], - sprout::index_tuple - ) - { - return sprout::array{{arr[Indexes]...}}; - } - } // namespace detail - // - // to_array - // - template - inline SPROUT_CONSTEXPR sprout::array to_array(T const (& arr)[N]) { - return sprout::detail::to_array_impl(arr, sprout::index_range<0, N>::make()); - } - - // - // is_array - // - template - struct is_array - : public std::false_type - {}; - template - struct is_array - : public sprout::is_array - {}; - template - struct is_array - : public sprout::is_array - {}; - template - struct is_array > - : public std::true_type - {}; - - namespace tuples { - // - // get - // - template - inline SPROUT_CONSTEXPR T& - get(sprout::array& t) SPROUT_NOEXCEPT { - static_assert(I < N, "get: index out of range"); - return t[I]; - } - template - inline SPROUT_CONSTEXPR T const& - get(sprout::array const& t) SPROUT_NOEXCEPT { - static_assert(I < N, "get: index out of range"); - return t[I]; - } - template - inline SPROUT_CONSTEXPR T&& - get(sprout::array&& t) SPROUT_NOEXCEPT { - return sprout::move(sprout::tuples::get(t)); - } - } // namespace tuples - - using sprout::tuples::get; -} // namespace sprout - -namespace std { - // - // tuple_size - // - template - struct tuple_size > - : public std::integral_constant - {}; - - // - // tuple_element - // - template - struct tuple_element > { - public: - static_assert(I < N, "tuple_element<>: index out of range"); - typedef T type; - }; -} // namespace std +#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_ARRAY_HPP diff --git a/sprout/array/array.hpp b/sprout/array/array.hpp new file mode 100644 index 00000000..ff88e349 --- /dev/null +++ b/sprout/array/array.hpp @@ -0,0 +1,214 @@ +#ifndef SPROUT_ARRAY_ARRAY_HPP +#define SPROUT_ARRAY_ARRAY_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT +#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION +# include +#endif + +namespace sprout { + // + // array + // + template + class array { + public: + typedef T value_type; +#if SPROUT_USE_INDEX_ITERATOR_IMPLEMENTATION + typedef sprout::index_iterator iterator; + typedef sprout::index_iterator 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 reverse_iterator; + typedef sprout::reverse_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& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) { + 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 + array& operator=(array const& rhs) { + std::copy(rhs.begin(), rhs.end(), begin()); + return *this; + } + template + array& operator=(array&& 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 + SPROUT_CONSTEXPR_OR_CONST typename sprout::array::size_type sprout::array::static_size; + + // + // swap + // + template + inline void swap(sprout::array& lhs, sprout::array& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + lhs.swap(rhs); + } + + namespace detail { + template + inline SPROUT_CONSTEXPR sprout::array to_array_impl( + T const (& arr)[N], + sprout::index_tuple + ) + { + return sprout::array{{arr[Indexes]...}}; + } + } // namespace detail + // + // to_array + // + template + inline SPROUT_CONSTEXPR sprout::array 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 diff --git a/sprout/array/comparison.hpp b/sprout/array/comparison.hpp new file mode 100644 index 00000000..cf70cfe2 --- /dev/null +++ b/sprout/array/comparison.hpp @@ -0,0 +1,44 @@ +#ifndef SPROUT_ARRAY_COMPARISON_HPP +#define SPROUT_ARRAY_COMPARISON_HPP + +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + // + // operator== + // operator!= + // operator< + // operator> + // operator<= + // operator>= + // + template + inline SPROUT_CONSTEXPR bool operator==(sprout::array const& lhs, sprout::array const& rhs) { + return NS_SSCRISK_CEL_OR_SPROUT::equal(lhs.begin(), lhs.end(), rhs.begin()); + } + template + inline SPROUT_CONSTEXPR bool operator!=(sprout::array const& lhs, sprout::array const& rhs) { + return !(lhs == rhs); + } + template + inline SPROUT_CONSTEXPR bool operator<(sprout::array const& lhs, sprout::array const& rhs) { + return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); + } + template + inline SPROUT_CONSTEXPR bool operator>(sprout::array const& lhs, sprout::array const& rhs) { + return rhs < lhs; + } + template + inline SPROUT_CONSTEXPR bool operator<=(sprout::array const& lhs, sprout::array const& rhs) { + return !(rhs < lhs); + } + template + inline SPROUT_CONSTEXPR bool operator>=(sprout::array const& lhs, sprout::array const& rhs) { + return !(lhs < rhs); + } +} // namespace sprout + +#endif // #ifndef SPROUT_ARRAY_COMPARISON_HPP diff --git a/sprout/array/hash.hpp b/sprout/array/hash.hpp new file mode 100644 index 00000000..c81f620c --- /dev/null +++ b/sprout/array/hash.hpp @@ -0,0 +1,16 @@ +#ifndef SPROUT_ARRAY_HASH_HPP +#define SPROUT_ARRAY_HASH_HPP + +#include +#include +#include +#include + +namespace sprout { + template + inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::array const& v) { + return sprout::hash_range(v.begin(), v.end()); + } +} // namespace sprout + +#endif // #ifndef SPROUT_ARRAY_HASH_HPP diff --git a/sprout/array/make_array.hpp b/sprout/array/make_array.hpp new file mode 100644 index 00000000..c990b4f3 --- /dev/null +++ b/sprout/array/make_array.hpp @@ -0,0 +1,35 @@ +#ifndef SPROUT_ARRAY_MAKE_ARRAY_HPP +#define SPROUT_ARRAY_MAKE_ARRAY_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + // + // make_array + // + template + inline SPROUT_CONSTEXPR sprout::array make_array(Types&&... args) { + return sprout::array{{sprout::forward(args)...}}; + } + + // + // make_common_array + // + template + inline SPROUT_CONSTEXPR sprout::array< + typename std::decay::type...>::type>::type, + sizeof...(Types) + > make_common_array(Types&&... args) { + return sprout::array< + typename std::decay::type...>::type>::type, + sizeof...(Types) + >{{sprout::forward(args)...}}; + } +} // namespace sprout + +#endif // #ifndef SPROUT_ARRAY_MAKE_ARRAY_HPP diff --git a/sprout/array/tuple.hpp b/sprout/array/tuple.hpp new file mode 100644 index 00000000..2c80f9f0 --- /dev/null +++ b/sprout/array/tuple.hpp @@ -0,0 +1,57 @@ +#ifndef SPROUT_ARRAY_TUPLE_HPP +#define SPROUT_ARRAY_TUPLE_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // get + // + template + inline SPROUT_CONSTEXPR T& + get(sprout::array& t) SPROUT_NOEXCEPT { + static_assert(I < N, "get: index out of range"); + return t[I]; + } + template + inline SPROUT_CONSTEXPR T const& + get(sprout::array const& t) SPROUT_NOEXCEPT { + static_assert(I < N, "get: index out of range"); + return t[I]; + } + template + inline SPROUT_CONSTEXPR T&& + get(sprout::array&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); + } + } // namespace tuples + + using sprout::tuples::get; +} // namespace sprout + +namespace std { + // + // tuple_size + // + template + struct tuple_size > + : public std::integral_constant + {}; + + // + // tuple_element + // + template + struct tuple_element > { + public: + static_assert(I < N, "tuple_element<>: index out of range"); + typedef T type; + }; +} // namespace std + +#endif // #ifndef SPROUT_ARRAY_TUPLE_HPP diff --git a/sprout/array/type_traits.hpp b/sprout/array/type_traits.hpp new file mode 100644 index 00000000..4819828c --- /dev/null +++ b/sprout/array/type_traits.hpp @@ -0,0 +1,31 @@ +#ifndef SPROUT_ARRAY_TYPE_TRAITS_HPP +#define SPROUT_ARRAY_TYPE_TRAITS_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // is_array + // + template + struct is_array + : public std::false_type + {}; + template + struct is_array + : public sprout::is_array + {}; + template + struct is_array + : public sprout::is_array + {}; + template + struct is_array > + : public std::true_type + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_ARRAY_TYPE_TRAITS_HPP diff --git a/sprout/functional/hash/array.hpp b/sprout/functional/hash/array.hpp deleted file mode 100644 index 65d9cac3..00000000 --- a/sprout/functional/hash/array.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SPROUT_FUNCTIONAL_HASH_ARRAY_HPP -#define SPROUT_FUNCTIONAL_HASH_ARRAY_HPP - -#include -#include -#include -#include - -namespace sprout { - template - SPROUT_CONSTEXPR std::size_t hash_value(sprout::array const& v) { - return sprout::hash_range(v.begin(), v.end()); - } -} // namespace sprout - -#endif // #ifndef SPROUT_FUNCTIONAL_HASH_ARRAY_HPP diff --git a/sprout/functional/hash/bitset.hpp b/sprout/functional/hash/bitset.hpp deleted file mode 100644 index c340424e..00000000 --- a/sprout/functional/hash/bitset.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef SPROUT_FUNCTIONAL_HASH_BITSET_HPP -#define SPROUT_FUNCTIONAL_HASH_BITSET_HPP - -#include -#include -#include - -#endif // #ifndef SPROUT_FUNCTIONAL_HASH_BITSET_HPP diff --git a/sprout/functional/hash/hash.hpp b/sprout/functional/hash/hash.hpp index d4d52c73..0fa76763 100644 --- a/sprout/functional/hash/hash.hpp +++ b/sprout/functional/hash/hash.hpp @@ -35,9 +35,9 @@ namespace sprout { typename T, typename sprout::enabler_if::type>::value>::type > - SPROUT_CONSTEXPR std::size_t hash_value(T&& v); + inline SPROUT_CONSTEXPR std::size_t hash_value(T&& v); template - 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 @@ -153,11 +153,11 @@ namespace sprout { typename T, typename sprout::enabler_if::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 - 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 - 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 - 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 - 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 - 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 diff --git a/sprout/functional/hash/string.hpp b/sprout/functional/hash/string.hpp deleted file mode 100644 index 81cd2ff9..00000000 --- a/sprout/functional/hash/string.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef SPROUT_FUNCTIONAL_HASH_STRING_HPP -#define SPROUT_FUNCTIONAL_HASH_STRING_HPP - -#include -#include -#include - -#endif // #ifndef SPROUT_FUNCTIONAL_HASH_STRING_HPP diff --git a/sprout/functional/hash/uuid.hpp b/sprout/functional/hash/uuid.hpp deleted file mode 100644 index 5b70ce27..00000000 --- a/sprout/functional/hash/uuid.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SPROUT_FUNCTIONAL_HASH_UUID_HPP -#define SPROUT_FUNCTIONAL_HASH_UUID_HPP - -#include -#include -#include -#include - -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 diff --git a/sprout/pit.hpp b/sprout/pit.hpp index 44759b25..e5bcbe98 100644 --- a/sprout/pit.hpp +++ b/sprout/pit.hpp @@ -1,250 +1,12 @@ #ifndef SPROUT_PIT_HPP #define SPROUT_PIT_HPP -#include -#include -#include #include -#include -#include -#include -#include -#include -#include - -namespace sprout { - // - // pit - // - template - class pit { - public: - typedef Container container_type; - typedef typename sprout::container_traits::value_type value_type; - typedef typename sprout::container_traits::reference reference; - typedef typename sprout::container_traits::const_reference const_reference; - typedef typename sprout::value_iterator iterator; - typedef typename sprout::value_iterator const_iterator; - typedef typename sprout::container_traits::size_type size_type; - typedef typename sprout::container_traits::difference_type difference_type; - typedef typename sprout::container_traits::pointer pointer; - typedef typename sprout::container_traits::const_pointer const_pointer; - typedef typename sprout::reverse_iterator reverse_iterator; - typedef typename sprout::reverse_iterator const_reverse_iterator; - public: - SPROUT_STATIC_CONSTEXPR size_type static_size = sprout::container_traits::static_size; - public: - value_type elem; - public: - pit() = default; - void swap(pit& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) { - 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 - SPROUT_CONSTEXPR_OR_CONST typename sprout::pit::size_type sprout::pit::static_size; - - // - // operator== - // operator!= - // operator< - // operator> - // operator<= - // operator>= - // - template - inline SPROUT_CONSTEXPR bool operator==(sprout::pit const& lhs, sprout::pit const& rhs) { - return lhs.front() == rhs.front(); - } - template - inline SPROUT_CONSTEXPR bool operator!=(sprout::pit const& lhs, sprout::pit const& rhs) { - return !(lhs == rhs); - } - template - inline SPROUT_CONSTEXPR bool operator<(sprout::pit const& lhs, sprout::pit const& rhs) { - return lhs.front() < rhs.front(); - } - template - inline SPROUT_CONSTEXPR bool operator>(sprout::pit const& lhs, sprout::pit const& rhs) { - return rhs < lhs; - } - template - inline SPROUT_CONSTEXPR bool operator<=(sprout::pit const& lhs, sprout::pit const& rhs) { - return !(rhs < lhs); - } - template - inline SPROUT_CONSTEXPR bool operator>=(sprout::pit const& lhs, sprout::pit const& rhs) { - return !(lhs < rhs); - } - - // - // swap - // - template - inline void swap(sprout::pit& lhs, sprout::pit& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { - lhs.swap(rhs); - } - - // - // container_construct_traits - // - template - struct container_construct_traits > { - public: - typedef typename sprout::container_construct_traits::copied_type copied_type; - public: - template - static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { - return copied_type(); - } - template - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { - return sprout::make(sprout::forward(args)...); - } - template - static SPROUT_CONSTEXPR copied_type remake( - Cont&& cont, - typename sprout::container_traits >::difference_type size, - Args&&... args - ) - { - return sprout::remake(sprout::forward(cont), size, sprout::forward(args)...); - } - }; - - // - // container_transform_traits - // - template - struct container_transform_traits > { - public: - template >::size_type Size> - struct rebind_size { - public: - typedef sprout::pit< - typename sprout::container_transform_traits::template rebind_size::type - > type; - }; - }; - - // - // blank - // - struct blank {}; - - // - // blank_pit - // - template - inline SPROUT_CONSTEXPR sprout::pit > - blank_pit() { - return sprout::pit >(); - } -} // namespace sprout - -namespace std { - // - // tuple_size - // - template - struct tuple_size > - : public std::tuple_size - {}; - - // - // tuple_element - // - template - struct tuple_element > - : public std::tuple_element - {}; -} // namespace std - -#include +#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_PIT_HPP diff --git a/sprout/pit/blank.hpp b/sprout/pit/blank.hpp new file mode 100644 index 00000000..18c8334c --- /dev/null +++ b/sprout/pit/blank.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_PIT_BLANK_HPP +#define SPROUT_PIT_BLANK_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // blank + // + struct blank {}; + + // + // blank_pit + // + template + inline SPROUT_CONSTEXPR sprout::pit > + blank_pit() { + return sprout::pit >(); + } +} // namespace sprout + +#endif // #ifndef SPROUT_PIT_BLANK_HPP diff --git a/sprout/pit/comparison.hpp b/sprout/pit/comparison.hpp new file mode 100644 index 00000000..bd1425b1 --- /dev/null +++ b/sprout/pit/comparison.hpp @@ -0,0 +1,42 @@ +#ifndef SPROUT_PIT_COMPARISON_HPP +#define SPROUT_PIT_COMPARISON_HPP + +#include +#include + +namespace sprout { + // + // operator== + // operator!= + // operator< + // operator> + // operator<= + // operator>= + // + template + inline SPROUT_CONSTEXPR bool operator==(sprout::pit const& lhs, sprout::pit const& rhs) { + return lhs.front() == rhs.front(); + } + template + inline SPROUT_CONSTEXPR bool operator!=(sprout::pit const& lhs, sprout::pit const& rhs) { + return !(lhs == rhs); + } + template + inline SPROUT_CONSTEXPR bool operator<(sprout::pit const& lhs, sprout::pit const& rhs) { + return lhs.front() < rhs.front(); + } + template + inline SPROUT_CONSTEXPR bool operator>(sprout::pit const& lhs, sprout::pit const& rhs) { + return rhs < lhs; + } + template + inline SPROUT_CONSTEXPR bool operator<=(sprout::pit const& lhs, sprout::pit const& rhs) { + return !(rhs < lhs); + } + template + inline SPROUT_CONSTEXPR bool operator>=(sprout::pit const& lhs, sprout::pit const& rhs) { + return !(lhs < rhs); + } +} // namespace sprout + +#endif // #ifndef SPROUT_PIT_COMPARISON_HPP diff --git a/sprout/pit/container.hpp b/sprout/pit/container.hpp new file mode 100644 index 00000000..5bfac75b --- /dev/null +++ b/sprout/pit/container.hpp @@ -0,0 +1,54 @@ +#ifndef SPROUT_PIT_CONTAINER_HPP +#define SPROUT_PIT_CONTAINER_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // container_construct_traits + // + template + struct container_construct_traits > { + public: + typedef typename sprout::container_construct_traits::copied_type copied_type; + public: + template + static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { + return copied_type(); + } + template + static SPROUT_CONSTEXPR copied_type make(Args&&... args) { + return sprout::make(sprout::forward(args)...); + } + template + static SPROUT_CONSTEXPR copied_type remake( + Cont&& cont, + typename sprout::container_traits >::difference_type size, + Args&&... args + ) + { + return sprout::remake(sprout::forward(cont), size, sprout::forward(args)...); + } + }; + + // + // container_transform_traits + // + template + struct container_transform_traits > { + public: + template >::size_type Size> + struct rebind_size { + public: + typedef sprout::pit< + typename sprout::container_transform_traits::template rebind_size::type + > type; + }; + }; +} // namespace sprout + +#endif // #ifndef SPROUT_PIT_CONTAINER_HPP diff --git a/sprout/functional/hash/pit.hpp b/sprout/pit/hash.hpp similarity index 60% rename from sprout/functional/hash/pit.hpp rename to sprout/pit/hash.hpp index b37e6e49..ebf46dd1 100644 --- a/sprout/functional/hash/pit.hpp +++ b/sprout/pit/hash.hpp @@ -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 #include #include -#include +#include namespace sprout { template @@ -12,4 +13,4 @@ namespace sprout { } } // namespace sprout -#endif // #ifndef SPROUT_FUNCTIONAL_HASH_PIT_HPP +#endif // #ifndef SPROUT_PIT_HASH_HPP diff --git a/sprout/pit/pit.hpp b/sprout/pit/pit.hpp new file mode 100644 index 00000000..3dddbc4d --- /dev/null +++ b/sprout/pit/pit.hpp @@ -0,0 +1,138 @@ +#ifndef SPROUT_PIT_PIT_HPP +#define SPROUT_PIT_PIT_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + // + // pit + // + template + class pit { + public: + typedef Container container_type; + typedef typename sprout::container_traits::value_type value_type; + typedef typename sprout::container_traits::reference reference; + typedef typename sprout::container_traits::const_reference const_reference; + typedef typename sprout::value_iterator iterator; + typedef typename sprout::value_iterator const_iterator; + typedef typename sprout::container_traits::size_type size_type; + typedef typename sprout::container_traits::difference_type difference_type; + typedef typename sprout::container_traits::pointer pointer; + typedef typename sprout::container_traits::const_pointer const_pointer; + typedef typename sprout::reverse_iterator reverse_iterator; + typedef typename sprout::reverse_iterator const_reverse_iterator; + public: + SPROUT_STATIC_CONSTEXPR size_type static_size = sprout::container_traits::static_size; + public: + value_type elem; + public: + pit() = default; + void swap(pit& other) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::swap(std::declval(), std::declval()))) { + 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 + SPROUT_CONSTEXPR_OR_CONST typename sprout::pit::size_type sprout::pit::static_size; + + // + // swap + // + template + inline void swap(sprout::pit& lhs, sprout::pit& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { + lhs.swap(rhs); + } +} // namespace sprout + +#endif // #ifndef SPROUT_PIT_PIT_HPP diff --git a/sprout/tuple/pit.hpp b/sprout/pit/tuple.hpp similarity index 68% rename from sprout/tuple/pit.hpp rename to sprout/pit/tuple.hpp index 12f84e50..10b7ba4d 100644 --- a/sprout/tuple/pit.hpp +++ b/sprout/pit/tuple.hpp @@ -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 +#include #include -#include +#include #include -#include 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 + struct tuple_size > + : public std::tuple_size + {}; + + // + // tuple_element + // + template + struct tuple_element > + : public std::tuple_element + {}; +} // namespace std + +#endif // #ifndef SPROUT_PIT_TUPLE_HPP diff --git a/sprout/string/concat.hpp b/sprout/string/concat.hpp index 3b19d15f..a6591d23 100644 --- a/sprout/string/concat.hpp +++ b/sprout/string/concat.hpp @@ -7,10 +7,6 @@ #include #include #include -//#include -//#include -//#include -//#include namespace sprout { namespace detail { diff --git a/sprout/string/hash.hpp b/sprout/string/hash.hpp index 4d61a5e1..ab7747a3 100644 --- a/sprout/string/hash.hpp +++ b/sprout/string/hash.hpp @@ -2,6 +2,7 @@ #define SPROUT_STRING_HASH_HPP #include +#include #include #include @@ -10,7 +11,7 @@ namespace sprout { // hash_value // template - SPROUT_CONSTEXPR std::size_t hash_value(sprout::basic_string const& v) { + inline SPROUT_CONSTEXPR std::size_t hash_value(sprout::basic_string const& v) { return sprout::hash_range(v.begin(), v.end()); } } // namespace sprout diff --git a/sprout/sub_array.hpp b/sprout/sub_array.hpp index 05a54c43..236b2f64 100644 --- a/sprout/sub_array.hpp +++ b/sprout/sub_array.hpp @@ -1,872 +1,13 @@ #ifndef SPROUT_SUB_ARRAY_HPP #define SPROUT_SUB_ARRAY_HPP -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#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 - class sub_array_impl { - protected: - typedef Container container_type; - typedef typename std::remove_reference::type internal_type; - protected: - SPROUT_STATIC_CONSTEXPR bool is_reference = std::is_reference::value; - SPROUT_STATIC_CONSTEXPR bool is_const = std::is_const::value; - protected: - typedef typename sprout::container_traits::const_iterator impl_const_iterator; - typedef typename sprout::container_traits::difference_type impl_difference_type; - protected: - typedef typename std::conditional< - is_reference, - internal_type*, - typename std::remove_const::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::value, - sprout::detail::is_non_reference_array_tag, - sprout::detail::is_not_non_reference_array_tag - >::type array_tag; - protected: - template - static SPROUT_CONSTEXPR typename std::enable_if< - std::is_reference::value, - holder_type - >::type to_holder(param_type arr) { - return &arr; - } - template - static SPROUT_CONSTEXPR typename std::enable_if< - !std::is_reference::value, - holder_type const& - >::type to_holder(param_type arr) { - return arr; - } - template - static SPROUT_CONSTEXPR typename std::enable_if< - std::is_reference::value, - param_type - >::type to_param(holder_type arr) { - return *arr; - } - template - static SPROUT_CONSTEXPR typename std::enable_if< - !std::is_reference::value, - param_type - >::type to_param(holder_type& arr) { - return arr; - } - template - static SPROUT_CONSTEXPR typename std::enable_if< - !std::is_reference::value, - param_type - >::type to_param(holder_type const& arr) { - return arr; - } - template - static SPROUT_CONSTEXPR typename std::enable_if< - std::is_reference::value, - const_param_type - >::type to_const_param(holder_type arr) { - return *arr; - } - template - static SPROUT_CONSTEXPR typename std::enable_if< - !std::is_reference::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 - SPROUT_CONSTEXPR sub_array_impl( - ContainerTag, - param_type arr, - sprout::index_tuple, - impl_const_iterator first, - impl_const_iterator last, - typename std::enable_if::value>::type* = 0 - ) - : array_{to_holder(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 - SPROUT_CONSTEXPR sub_array_impl( - ContainerTag, - param_type arr, - sprout::index_tuple, - impl_const_iterator first, - impl_const_iterator last, - typename std::enable_if::value>::type* = 0 - ) - : array_(to_holder(arr)) - , first_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), first)) - , last_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), last)) - {} - template - SPROUT_CONSTEXPR sub_array_impl( - ContainerTag, - param_type arr, - sprout::index_tuple, - impl_difference_type first, - impl_difference_type last, - typename std::enable_if::value>::type* = 0 - ) - : array_{to_holder(arr)[Indexes]...} - , first_(first) - , last_(last) - {} - template - SPROUT_CONSTEXPR sub_array_impl( - ContainerTag, - param_type arr, - sprout::index_tuple, - impl_difference_type first, - impl_difference_type last, - typename std::enable_if::value>::type* = 0 - ) - : array_(to_holder(arr)) - , first_(first) - , last_(last) - {} - }; - } // namespace detail - - // - // sub_array - // - template - class sub_array - : private sprout::detail::sub_array_impl - , public sprout::container_traits_facade::type> - { - private: - typedef sprout::detail::sub_array_impl impl_type; - typedef sprout::container_traits_facade::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 const& other, const_iterator first, const_iterator last) - : impl_type( - array_tag(), - impl_type::template to_param(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 const& other, difference_type first, difference_type last) - : impl_type( - array_tag(), - impl_type::template to_param(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 - void swap(sub_array& 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 - sub_array& operator=(sub_array const& rhs) { - array_ = rhs.array_; - first_ = rhs.first_; - last_ = rhs.last_; - return *this; - } - template - sub_array& operator=(sub_array&& 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(array_); - } - SPROUT_CONSTEXPR const_param_type get_internal() const { - return impl_type::template to_const_param(array_); - } - param_type get_array() { - return impl_type::template to_param(array_); - } - SPROUT_CONSTEXPR const_param_type get_array() const { - return impl_type::template to_const_param(array_); - } - }; - template - SPROUT_CONSTEXPR_OR_CONST typename sprout::sub_array::size_type sprout::sub_array::static_size; - - // - // swap - // - template - inline void swap(sprout::sub_array& lhs, sprout::sub_array& rhs) { - lhs.swap(rhs); - } - - // - // operator== - // operator!= - // operator< - // operator> - // operator<= - // operator>= - // - template - inline SPROUT_CONSTEXPR bool - operator==(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { - return NS_SSCRISK_CEL_OR_SPROUT::equal(sprout::begin(lhs), sprout::end(lhs), sprout::begin(rhs)); - } - template - inline SPROUT_CONSTEXPR bool - operator!=(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { - return !(lhs == rhs); - } - template - inline SPROUT_CONSTEXPR bool - operator<(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { - return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare( - sprout::begin(lhs), sprout::end(lhs), - sprout::begin(rhs), sprout::end(rhs) - ); - } - template - inline SPROUT_CONSTEXPR bool - operator>(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { - return rhs < lhs; - } - template - inline SPROUT_CONSTEXPR bool - operator<=(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { - return !(rhs < lhs); - } - template - inline SPROUT_CONSTEXPR bool - operator>=(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { - return !(lhs < rhs); - } - - // - // container_construct_traits - // - template - struct container_construct_traits > { - private: - typedef typename sprout::sub_array::internal_type internal_type; - typedef typename sprout::container_construct_traits::copied_type internal_copied_type; - public: - typedef sprout::sub_array 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 - static SPROUT_CONSTEXPR copied_type remake_impl( - Cont&& cont, - typename sprout::container_traits >::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 - 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 - static SPROUT_CONSTEXPR copied_type make(Args&&... args) { - return make_impl( - sprout::make(sprout::forward(args)...) - ); - } - template - static SPROUT_CONSTEXPR copied_type remake( - Cont&& cont, - typename sprout::container_traits >::difference_type size, - Args&&... args - ) - { - return remake_impl( - sprout::forward(cont), - size, - sprout::make(sprout::forward(args)...) - ); - } - }; - - // - // container_transform_traits - // - template - struct container_transform_traits > { - public: - template >::size_type Size> - struct rebind_size { - public: - typedef sprout::sub_array< - typename sprout::container_transform_traits< - typename std::remove_reference::type - >::template rebind_size::type - > type; - }; - }; - - // - // sub_container_traits - // - template - struct sub_container_traits > { - private: - static typename sprout::sub_array::param_type - call(sprout::sub_array& cont) { - return cont.get_internal(); - } - static SPROUT_CONSTEXPR typename sprout::sub_array::const_param_type - call(sprout::sub_array const& cont) { - return cont.get_internal(); - } - public: - template - struct internal { - public: - typedef decltype(call(std::declval())) type; - }; - public: - template - static SPROUT_CONSTEXPR typename internal::type get_internal(Cont&& cont) { - return call(sprout::forward(cont)); - } - }; - - // - // is_sub_array - // - template - struct is_sub_array - : public std::false_type - {}; - template - struct is_sub_array - : public sprout::is_sub_array - {}; - template - struct is_sub_array - : public sprout::is_sub_array - {}; - template - struct is_sub_array > - : public std::true_type - {}; - - // - // sub - // - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container& arr, - typename sprout::container_traits >::const_iterator first, - typename sprout::container_traits >::const_iterator last - ) - { - return sprout::sub_array(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container& arr, - typename sprout::container_traits >::difference_type first, - typename sprout::container_traits >::difference_type last - ) - { - return sprout::sub_array(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container& arr, - typename sprout::container_traits >::const_iterator first - ) - { - return sprout::sub(arr, first, sprout::end(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container& arr, - typename sprout::container_traits >::difference_type first - ) - { - return sprout::sub(arr, first, sprout::size(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container& arr - ) - { - return sprout::sub(arr, sprout::begin(arr), sprout::end(arr)); - } - // - // sub - // - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container const& arr, - typename sprout::container_traits >::const_iterator first, - typename sprout::container_traits >::const_iterator last - ) - { - return sprout::sub_array(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container const& arr, - typename sprout::container_traits >::difference_type first, - typename sprout::container_traits >::difference_type last - ) - { - return sprout::sub_array(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container const& arr, - typename sprout::container_traits >::const_iterator first - ) - { - return sprout::sub(arr, first, sprout::end(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container const& arr, - typename sprout::container_traits >::difference_type first - ) - { - return sprout::sub(arr, first, sprout::size(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( - Container const& arr - ) - { - return sprout::sub(arr, sprout::begin(arr), sprout::end(arr)); - } - // - // sub - // - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( - Container const& arr, - typename sprout::container_traits::const_iterator first, - typename sprout::container_traits::const_iterator last - ) - { - return Container(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( - Container const& arr, - typename sprout::container_traits::difference_type first, - typename sprout::container_traits::difference_type last - ) - { - return Container(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( - Container const& arr, - typename sprout::container_traits::const_iterator first - ) - { - return sprout::sub(arr, first, sprout::end(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( - Container const& arr, - typename sprout::container_traits::difference_type first - ) - { - return sprout::sub(arr, first, sprout::size(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( - Container const& arr - ) - { - return sprout::sub(arr, sprout::begin(arr), sprout::end(arr)); - } - - // - // csub - // - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr, - typename sprout::container_traits >::const_iterator first, - typename sprout::container_traits >::const_iterator last - ) - { - return sprout::sub_array(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr, - typename sprout::container_traits >::difference_type first, - typename sprout::container_traits >::difference_type last - ) - { - return sprout::sub_array(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr, - typename sprout::container_traits >::const_iterator first - ) - { - return sprout::csub(arr, first, sprout::end(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr, - typename sprout::container_traits >::difference_type first - ) - { - return sprout::csub(arr, first, sprout::size(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr - ) - { - return sprout::csub(arr, sprout::begin(arr), sprout::end(arr)); - } - // - // csub - // - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr, - typename sprout::container_traits::const_iterator first, - typename sprout::container_traits::const_iterator last - ) - { - return sprout::sub_array(arr.get_array(), first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr, - typename sprout::container_traits::difference_type first, - typename sprout::container_traits::difference_type last - ) - { - return sprout::sub_array( - arr.get_array(), - sprout::next(sprout::begin(arr), first), - sprout::next(sprout::begin(arr), last) - ); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr, - typename sprout::container_traits::const_iterator first - ) - { - return sprout::csub(arr, first, sprout::end(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr, - typename sprout::container_traits::difference_type first - ) - { - return sprout::csub(arr, first, sprout::size(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( - Container const& arr - ) - { - return sprout::csub(arr, sprout::begin(arr), sprout::end(arr)); - } - - // - // sub_copy - // - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr, - typename sprout::container_traits::const_iterator first, - typename sprout::container_traits::const_iterator last - ) - { - return sprout::sub_array(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr, - typename sprout::container_traits::difference_type first, - typename sprout::container_traits::difference_type last - ) - { - return sprout::sub_array(arr, first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr, - typename sprout::container_traits::const_iterator first - ) - { - return sprout::sub_copy(arr, first, sprout::end(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr, - typename sprout::container_traits::difference_type first - ) - { - return sprout::sub_copy(arr, first, sprout::size(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr - ) - { - return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr)); - } - // - // sub_copy - // - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr, - typename sprout::container_traits::const_iterator first, - typename sprout::container_traits::const_iterator last - ) - { - return sprout::sub_array(arr.get_array(), first, last); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr, - typename sprout::container_traits::difference_type first, - typename sprout::container_traits::difference_type last - ) - { - return sprout::sub_array( - arr.get_array(), - sprout::next(sprout::begin(arr), first), - sprout::next(sprout::begin(arr), last) - ); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr, - typename sprout::container_traits::const_iterator first - ) - { - return sprout::sub_copy(arr, first, sprout::end(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr, - typename sprout::container_traits::difference_type first - ) - { - return sprout::sub_copy(arr, first, sprout::size(arr)); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( - Container const& arr - ) - { - return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr)); - } -} // namespace sprout - -namespace std { - // - // tuple_size - // - template - struct tuple_size > - : public std::tuple_size::type> - {}; - - // - // tuple_element - // - template - struct tuple_element > - : public std::tuple_element::type> - {}; -} // namespace std - -#include +#include +#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_SUB_ARRAY_HPP diff --git a/sprout/sub_array/comparison.hpp b/sprout/sub_array/comparison.hpp new file mode 100644 index 00000000..37729390 --- /dev/null +++ b/sprout/sub_array/comparison.hpp @@ -0,0 +1,53 @@ +#ifndef SPROUT_SUB_ARRAY_COMPARISON_HPP +#define SPROUT_SUB_ARRAY_COMPARISON_HPP + +#include +#include +#include +#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT + +namespace sprout { + // + // operator== + // operator!= + // operator< + // operator> + // operator<= + // operator>= + // + template + inline SPROUT_CONSTEXPR bool + operator==(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { + return NS_SSCRISK_CEL_OR_SPROUT::equal(sprout::begin(lhs), sprout::end(lhs), sprout::begin(rhs)); + } + template + inline SPROUT_CONSTEXPR bool + operator!=(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { + return !(lhs == rhs); + } + template + inline SPROUT_CONSTEXPR bool + operator<(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { + return NS_SSCRISK_CEL_OR_SPROUT::lexicographical_compare( + sprout::begin(lhs), sprout::end(lhs), + sprout::begin(rhs), sprout::end(rhs) + ); + } + template + inline SPROUT_CONSTEXPR bool + operator>(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { + return rhs < lhs; + } + template + inline SPROUT_CONSTEXPR bool + operator<=(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { + return !(rhs < lhs); + } + template + inline SPROUT_CONSTEXPR bool + operator>=(sprout::sub_array const& lhs, sprout::sub_array const& rhs) { + return !(lhs < rhs); + } +} // namespace sprout + +#endif // #ifndef SPROUT_SUB_ARRAY_COMPARISON_HPP diff --git a/sprout/sub_array/container.hpp b/sprout/sub_array/container.hpp new file mode 100644 index 00000000..538bafc9 --- /dev/null +++ b/sprout/sub_array/container.hpp @@ -0,0 +1,116 @@ +#ifndef SPROUT_SUB_ARRAY_CONTAINER_HPP +#define SPROUT_SUB_ARRAY_CONTAINER_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + + // + // container_construct_traits + // + template + struct container_construct_traits > { + private: + typedef typename sprout::sub_array::internal_type internal_type; + typedef typename sprout::container_construct_traits::copied_type internal_copied_type; + public: + typedef sprout::sub_array 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 + static SPROUT_CONSTEXPR copied_type remake_impl( + Cont&& cont, + typename sprout::container_traits >::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 + 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 + static SPROUT_CONSTEXPR copied_type make(Args&&... args) { + return make_impl( + sprout::make(sprout::forward(args)...) + ); + } + template + static SPROUT_CONSTEXPR copied_type remake( + Cont&& cont, + typename sprout::container_traits >::difference_type size, + Args&&... args + ) + { + return remake_impl( + sprout::forward(cont), + size, + sprout::make(sprout::forward(args)...) + ); + } + }; + + // + // container_transform_traits + // + template + struct container_transform_traits > { + public: + template >::size_type Size> + struct rebind_size { + public: + typedef sprout::sub_array< + typename sprout::container_transform_traits< + typename std::remove_reference::type + >::template rebind_size::type + > type; + }; + }; + + // + // sub_container_traits + // + template + struct sub_container_traits > { + private: + static typename sprout::sub_array::param_type + call(sprout::sub_array& cont) { + return cont.get_internal(); + } + static SPROUT_CONSTEXPR typename sprout::sub_array::const_param_type + call(sprout::sub_array const& cont) { + return cont.get_internal(); + } + public: + template + struct internal { + public: + typedef decltype(call(std::declval())) type; + }; + public: + template + static SPROUT_CONSTEXPR typename internal::type get_internal(Cont&& cont) { + return call(sprout::forward(cont)); + } + }; +} // namespace sprout + +#endif // #ifndef SPROUT_SUB_ARRAY_CONTAINER_HPP diff --git a/sprout/functional/hash/sub_array.hpp b/sprout/sub_array/hash.hpp similarity index 56% rename from sprout/functional/hash/sub_array.hpp rename to sprout/sub_array/hash.hpp index 8a883261..cdf161a0 100644 --- a/sprout/functional/hash/sub_array.hpp +++ b/sprout/sub_array/hash.hpp @@ -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 #include #include -#include +#include namespace sprout { template @@ -13,4 +12,4 @@ namespace sprout { } } // namespace sprout -#endif // #ifndef SPROUT_FUNCTIONAL_HASH_SUB_ARRAY_HPP +#endif // #ifndef SPROUT_SUB_ARRAY_HASH_HPP diff --git a/sprout/sub_array/sub.hpp b/sprout/sub_array/sub.hpp new file mode 100644 index 00000000..a9441dfc --- /dev/null +++ b/sprout/sub_array/sub.hpp @@ -0,0 +1,334 @@ +#ifndef SPROUT_SUB_ARRAY_SUB_HPP +#define SPROUT_SUB_ARRAY_SUB_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + + // + // sub + // + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container& arr, + typename sprout::container_traits >::const_iterator first, + typename sprout::container_traits >::const_iterator last + ) + { + return sprout::sub_array(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container& arr, + typename sprout::container_traits >::difference_type first, + typename sprout::container_traits >::difference_type last + ) + { + return sprout::sub_array(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container& arr, + typename sprout::container_traits >::const_iterator first + ) + { + return sprout::sub(arr, first, sprout::end(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container& arr, + typename sprout::container_traits >::difference_type first + ) + { + return sprout::sub(arr, first, sprout::size(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container& arr + ) + { + return sprout::sub(arr, sprout::begin(arr), sprout::end(arr)); + } + // + // sub + // + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container const& arr, + typename sprout::container_traits >::const_iterator first, + typename sprout::container_traits >::const_iterator last + ) + { + return sprout::sub_array(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container const& arr, + typename sprout::container_traits >::difference_type first, + typename sprout::container_traits >::difference_type last + ) + { + return sprout::sub_array(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container const& arr, + typename sprout::container_traits >::const_iterator first + ) + { + return sprout::sub(arr, first, sprout::end(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container const& arr, + typename sprout::container_traits >::difference_type first + ) + { + return sprout::sub(arr, first, sprout::size(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub( + Container const& arr + ) + { + return sprout::sub(arr, sprout::begin(arr), sprout::end(arr)); + } + // + // sub + // + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + Container const& arr, + typename sprout::container_traits::const_iterator first, + typename sprout::container_traits::const_iterator last + ) + { + return Container(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + Container const& arr, + typename sprout::container_traits::difference_type first, + typename sprout::container_traits::difference_type last + ) + { + return Container(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + Container const& arr, + typename sprout::container_traits::const_iterator first + ) + { + return sprout::sub(arr, first, sprout::end(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + Container const& arr, + typename sprout::container_traits::difference_type first + ) + { + return sprout::sub(arr, first, sprout::size(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, Container>::type sub( + Container const& arr + ) + { + return sprout::sub(arr, sprout::begin(arr), sprout::end(arr)); + } + + // + // csub + // + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr, + typename sprout::container_traits >::const_iterator first, + typename sprout::container_traits >::const_iterator last + ) + { + return sprout::sub_array(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr, + typename sprout::container_traits >::difference_type first, + typename sprout::container_traits >::difference_type last + ) + { + return sprout::sub_array(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr, + typename sprout::container_traits >::const_iterator first + ) + { + return sprout::csub(arr, first, sprout::end(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr, + typename sprout::container_traits >::difference_type first + ) + { + return sprout::csub(arr, first, sprout::size(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr + ) + { + return sprout::csub(arr, sprout::begin(arr), sprout::end(arr)); + } + // + // csub + // + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr, + typename sprout::container_traits::const_iterator first, + typename sprout::container_traits::const_iterator last + ) + { + return sprout::sub_array(arr.get_array(), first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr, + typename sprout::container_traits::difference_type first, + typename sprout::container_traits::difference_type last + ) + { + return sprout::sub_array( + arr.get_array(), + sprout::next(sprout::begin(arr), first), + sprout::next(sprout::begin(arr), last) + ); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr, + typename sprout::container_traits::const_iterator first + ) + { + return sprout::csub(arr, first, sprout::end(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr, + typename sprout::container_traits::difference_type first + ) + { + return sprout::csub(arr, first, sprout::size(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type csub( + Container const& arr + ) + { + return sprout::csub(arr, sprout::begin(arr), sprout::end(arr)); + } + + // + // sub_copy + // + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + Container const& arr, + typename sprout::container_traits::const_iterator first, + typename sprout::container_traits::const_iterator last + ) + { + return sprout::sub_array(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + Container const& arr, + typename sprout::container_traits::difference_type first, + typename sprout::container_traits::difference_type last + ) + { + return sprout::sub_array(arr, first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + Container const& arr, + typename sprout::container_traits::const_iterator first + ) + { + return sprout::sub_copy(arr, first, sprout::end(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + Container const& arr, + typename sprout::container_traits::difference_type first + ) + { + return sprout::sub_copy(arr, first, sprout::size(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + Container const& arr + ) + { + return sprout::sub_copy(arr, sprout::begin(arr), sprout::end(arr)); + } + // + // sub_copy + // + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + Container const& arr, + typename sprout::container_traits::const_iterator first, + typename sprout::container_traits::const_iterator last + ) + { + return sprout::sub_array(arr.get_array(), first, last); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + Container const& arr, + typename sprout::container_traits::difference_type first, + typename sprout::container_traits::difference_type last + ) + { + return sprout::sub_array( + arr.get_array(), + sprout::next(sprout::begin(arr), first), + sprout::next(sprout::begin(arr), last) + ); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + Container const& arr, + typename sprout::container_traits::const_iterator first + ) + { + return sprout::sub_copy(arr, first, sprout::end(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::type sub_copy( + Container const& arr, + typename sprout::container_traits::difference_type first + ) + { + return sprout::sub_copy(arr, first, sprout::size(arr)); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if::value, sprout::sub_array >::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 diff --git a/sprout/sub_array/sub_array.hpp b/sprout/sub_array/sub_array.hpp new file mode 100644 index 00000000..7ea77a2d --- /dev/null +++ b/sprout/sub_array/sub_array.hpp @@ -0,0 +1,368 @@ +#ifndef SPROUT_SUB_ARRAY_SUB_ARRAY_HPP +#define SPROUT_SUB_ARRAY_SUB_ARRAY_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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 + class sub_array_impl { + protected: + typedef Container container_type; + typedef typename std::remove_reference::type internal_type; + protected: + SPROUT_STATIC_CONSTEXPR bool is_reference = std::is_reference::value; + SPROUT_STATIC_CONSTEXPR bool is_const = std::is_const::value; + protected: + typedef typename sprout::container_traits::const_iterator impl_const_iterator; + typedef typename sprout::container_traits::difference_type impl_difference_type; + protected: + typedef typename std::conditional< + is_reference, + internal_type*, + typename std::remove_const::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::value, + sprout::detail::is_non_reference_array_tag, + sprout::detail::is_not_non_reference_array_tag + >::type array_tag; + protected: + template + static SPROUT_CONSTEXPR typename std::enable_if< + std::is_reference::value, + holder_type + >::type to_holder(param_type arr) { + return &arr; + } + template + static SPROUT_CONSTEXPR typename std::enable_if< + !std::is_reference::value, + holder_type const& + >::type to_holder(param_type arr) { + return arr; + } + template + static SPROUT_CONSTEXPR typename std::enable_if< + std::is_reference::value, + param_type + >::type to_param(holder_type arr) { + return *arr; + } + template + static SPROUT_CONSTEXPR typename std::enable_if< + !std::is_reference::value, + param_type + >::type to_param(holder_type& arr) { + return arr; + } + template + static SPROUT_CONSTEXPR typename std::enable_if< + !std::is_reference::value, + param_type + >::type to_param(holder_type const& arr) { + return arr; + } + template + static SPROUT_CONSTEXPR typename std::enable_if< + std::is_reference::value, + const_param_type + >::type to_const_param(holder_type arr) { + return *arr; + } + template + static SPROUT_CONSTEXPR typename std::enable_if< + !std::is_reference::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 + SPROUT_CONSTEXPR sub_array_impl( + ContainerTag, + param_type arr, + sprout::index_tuple, + impl_const_iterator first, + impl_const_iterator last, + typename std::enable_if::value>::type* = 0 + ) + : array_{to_holder(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 + SPROUT_CONSTEXPR sub_array_impl( + ContainerTag, + param_type arr, + sprout::index_tuple, + impl_const_iterator first, + impl_const_iterator last, + typename std::enable_if::value>::type* = 0 + ) + : array_(to_holder(arr)) + , first_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), first)) + , last_(NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::cbegin(arr), last)) + {} + template + SPROUT_CONSTEXPR sub_array_impl( + ContainerTag, + param_type arr, + sprout::index_tuple, + impl_difference_type first, + impl_difference_type last, + typename std::enable_if::value>::type* = 0 + ) + : array_{to_holder(arr)[Indexes]...} + , first_(first) + , last_(last) + {} + template + SPROUT_CONSTEXPR sub_array_impl( + ContainerTag, + param_type arr, + sprout::index_tuple, + impl_difference_type first, + impl_difference_type last, + typename std::enable_if::value>::type* = 0 + ) + : array_(to_holder(arr)) + , first_(first) + , last_(last) + {} + }; + } // namespace detail + + // + // sub_array + // + template + class sub_array + : private sprout::detail::sub_array_impl + , public sprout::container_traits_facade::type> + { + private: + typedef sprout::detail::sub_array_impl impl_type; + typedef sprout::container_traits_facade::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 const& other, const_iterator first, const_iterator last) + : impl_type( + array_tag(), + impl_type::template to_param(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 const& other, difference_type first, difference_type last) + : impl_type( + array_tag(), + impl_type::template to_param(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 + void swap(sub_array& 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 + sub_array& operator=(sub_array const& rhs) { + array_ = rhs.array_; + first_ = rhs.first_; + last_ = rhs.last_; + return *this; + } + template + sub_array& operator=(sub_array&& 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(array_); + } + SPROUT_CONSTEXPR const_param_type get_internal() const { + return impl_type::template to_const_param(array_); + } + param_type get_array() { + return impl_type::template to_param(array_); + } + SPROUT_CONSTEXPR const_param_type get_array() const { + return impl_type::template to_const_param(array_); + } + }; + template + SPROUT_CONSTEXPR_OR_CONST typename sprout::sub_array::size_type sprout::sub_array::static_size; + + // + // swap + // + template + inline void swap(sprout::sub_array& lhs, sprout::sub_array& rhs) { + lhs.swap(rhs); + } +} // namespace sprout + +#endif // #ifndef SPROUT_SUB_ARRAY_SUB_ARRAY_HPP diff --git a/sprout/sub_array/tuple.hpp b/sprout/sub_array/tuple.hpp new file mode 100644 index 00000000..3034af1b --- /dev/null +++ b/sprout/sub_array/tuple.hpp @@ -0,0 +1,66 @@ +#ifndef SPROUT_SUB_ARRAY_TUPLE_HPP +#define SPROUT_SUB_ARRAY_TUPLE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // get + // + template + inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type& + get(sprout::sub_array& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) + { + static_assert(I < sprout::container_traits >::static_size, "get: index out of range"); + return *sprout::next(sprout::internal_begin(t), I); + } + template + inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type const& + get(sprout::sub_array const& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(*sprout::next(sprout::internal_begin(t), I))) + { + static_assert(I < sprout::container_traits >::static_size, "get: index out of range"); + return *sprout::next(sprout::internal_begin(t), I); + } + template + inline SPROUT_CONSTEXPR typename sprout::container_traits >::value_type&& + get(sprout::sub_array&& t) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::move(sprout::tuples::get(t)))) + { + return sprout::move(sprout::tuples::get(t)); + } + } // namespace tuples + + using sprout::tuples::get; +} // namespace sprout + +namespace std { + // + // tuple_size + // + template + struct tuple_size > + : public std::tuple_size::type> + {}; + + // + // tuple_element + // + template + struct tuple_element > + : public std::tuple_element::type> + {}; +} // namespace std + +#endif // #ifndef SPROUT_SUB_ARRAY_TUPLE_HPP diff --git a/sprout/sub_array/type_traits.hpp b/sprout/sub_array/type_traits.hpp new file mode 100644 index 00000000..3faf31d1 --- /dev/null +++ b/sprout/sub_array/type_traits.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_SUB_ARRAY_TYPE_TRAITS_HPP +#define SPROUT_SUB_ARRAY_TYPE_TRAITS_HPP + +#include +#include +#include + +namespace sprout { + // + // is_sub_array + // + template + struct is_sub_array + : public std::false_type + {}; + template + struct is_sub_array + : public sprout::is_sub_array + {}; + template + struct is_sub_array + : public sprout::is_sub_array + {}; + template + struct is_sub_array > + : public std::true_type + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_SUB_ARRAY_TYPE_TRAITS_HPP diff --git a/sprout/tuple/array.hpp b/sprout/tuple/array.hpp deleted file mode 100644 index 38209ef9..00000000 --- a/sprout/tuple/array.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef SPROUT_TUPLE_ARRAY_HPP -#define SPROUT_TUPLE_ARRAY_HPP - -#include -#include - -#endif // #ifndef SPROUT_TUPLE_ARRAY_HPP diff --git a/sprout/tuple/string.hpp b/sprout/tuple/string.hpp deleted file mode 100644 index feb014c2..00000000 --- a/sprout/tuple/string.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef SPROUT_TUPLE_STRING_HPP -#define SPROUT_TUPLE_STRING_HPP - -#include -#include - -#endif // #ifndef SPROUT_TUPLE_STRING_HPP diff --git a/sprout/uuid.hpp b/sprout/uuid.hpp index 14267ba3..b66a707d 100644 --- a/sprout/uuid.hpp +++ b/sprout/uuid.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include diff --git a/sprout/uuid/uuid.hpp b/sprout/uuid/uuid.hpp index 781d420d..aba93409 100644 --- a/sprout/uuid/uuid.hpp +++ b/sprout/uuid/uuid.hpp @@ -259,28 +259,4 @@ namespace sprout { using sprout::uuids::uuid; } // namespace sprout -namespace std { - // - // tuple_size - // - template<> - struct tuple_size { - public: - typedef std::integral_constant type; - SPROUT_STATIC_CONSTEXPR std::size_t value = type::value; - }; - - // - // tuple_element - // - template - struct tuple_element { - public: - static_assert(I < 16, "tuple_element<>: index out of range"); - typedef sprout::uuids::uuid::value_type type; - }; -} // namespace std - -#include - #endif // #ifndef SPROUT_UUID_UUID_HPP diff --git a/sprout/uuid/uuid_hash.hpp b/sprout/uuid/uuid_hash.hpp index e8c40c94..5423499d 100644 --- a/sprout/uuid/uuid_hash.hpp +++ b/sprout/uuid/uuid_hash.hpp @@ -1,7 +1,15 @@ #ifndef SPROUT_UUID_UUID_HASH_HPP #define SPROUT_UUID_UUID_HASH_HPP +#include #include -#include +#include +#include + +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 diff --git a/sprout/tuple/uuid.hpp b/sprout/uuid/uuid_tuple.hpp similarity index 57% rename from sprout/tuple/uuid.hpp rename to sprout/uuid/uuid_tuple.hpp index c12b59e5..7aee7043 100644 --- a/sprout/tuple/uuid.hpp +++ b/sprout/uuid/uuid_tuple.hpp @@ -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 +#include #include #include #include @@ -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 { + public: + typedef std::integral_constant type; + SPROUT_STATIC_CONSTEXPR std::size_t value = type::value; + }; + + // + // tuple_element + // + template + struct tuple_element { + 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