From ba6482d1ec5b3f4d7382a89bf66b5e79f58dfaeb Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Wed, 4 Apr 2012 17:48:02 +0900 Subject: [PATCH] porting cel/range/algoritm.hpp --- sprout/container/empty.hpp | 5 +- sprout/iterator/distance.hpp | 18 +-- sprout/iterator/next.hpp | 60 ++++---- sprout/iterator/prev.hpp | 60 ++++---- sprout/numeric/accumulate.hpp | 6 +- sprout/numeric/inner_product.hpp | 4 +- sprout/range/algorithm/adjacent_find.hpp | 67 +++++++++ sprout/range/algorithm/all_of.hpp | 20 +++ sprout/range/algorithm/any_of.hpp | 20 +++ sprout/range/algorithm/binary_search.hpp | 25 ++++ sprout/range/algorithm/count.hpp | 22 +++ sprout/range/algorithm/count_if.hpp | 22 +++ sprout/range/algorithm/equal.hpp | 25 ++++ sprout/range/algorithm/equal_range.hpp | 50 +++++++ sprout/range/algorithm/find.hpp | 43 ++++++ sprout/range/algorithm/find_end.hpp | 75 ++++++++++ sprout/range/algorithm/find_first_of.hpp | 75 ++++++++++ sprout/range/algorithm/find_if.hpp | 43 ++++++ sprout/range/algorithm/find_if_not.hpp | 43 ++++++ sprout/range/algorithm/includes.hpp | 25 ++++ sprout/range/algorithm/is_heap.hpp | 25 ++++ sprout/range/algorithm/is_heap_until.hpp | 67 +++++++++ sprout/range/algorithm/is_partitioned.hpp | 20 +++ sprout/range/algorithm/is_permutation.hpp | 25 ++++ sprout/range/algorithm/is_sorted.hpp | 25 ++++ sprout/range/algorithm/is_sorted_until.hpp | 67 +++++++++ .../algorithm/lexicographical_compare.hpp | 25 ++++ sprout/range/algorithm/lower_bound.hpp | 71 ++++++++++ sprout/range/algorithm/max_element.hpp | 67 +++++++++ sprout/range/algorithm/min_element.hpp | 67 +++++++++ sprout/range/algorithm/minmax_element.hpp | 106 ++++++++++++++ sprout/range/algorithm/mismatch.hpp | 45 ++++++ sprout/range/algorithm/non_modifying.hpp | 65 ++++----- sprout/range/algorithm/none_of.hpp | 20 +++ sprout/range/algorithm/partition_point.hpp | 30 ++++ sprout/range/algorithm/search.hpp | 75 ++++++++++ sprout/range/algorithm/search_n.hpp | 75 ++++++++++ sprout/range/algorithm/upper_bound.hpp | 71 ++++++++++ sprout/range/lvref_iterator.hpp | 24 ++++ sprout/range/lvref_range.hpp | 21 +++ sprout/range/numeric/accumulate.hpp | 20 +++ sprout/range/numeric/inner_product.hpp | 32 +++++ sprout/range/numeric/non_modifying.hpp | 4 +- sprout/range/range_container.hpp | 134 ++++++++++++++++++ sprout/range/range_return.hpp | 70 +++++++++ sprout/sub_array.hpp | 2 +- sprout/utility/as_const.hpp | 20 +++ sprout/utility/as_lvref.hpp | 29 ++++ sprout/utility/forward.hpp | 4 +- sprout/utility/move.hpp | 2 +- sprout/utility/operation_ext.hpp | 8 ++ 51 files changed, 1908 insertions(+), 116 deletions(-) create mode 100644 sprout/range/algorithm/adjacent_find.hpp create mode 100644 sprout/range/algorithm/all_of.hpp create mode 100644 sprout/range/algorithm/any_of.hpp create mode 100644 sprout/range/algorithm/binary_search.hpp create mode 100644 sprout/range/algorithm/count.hpp create mode 100644 sprout/range/algorithm/count_if.hpp create mode 100644 sprout/range/algorithm/equal.hpp create mode 100644 sprout/range/algorithm/equal_range.hpp create mode 100644 sprout/range/algorithm/find.hpp create mode 100644 sprout/range/algorithm/find_end.hpp create mode 100644 sprout/range/algorithm/find_first_of.hpp create mode 100644 sprout/range/algorithm/find_if.hpp create mode 100644 sprout/range/algorithm/find_if_not.hpp create mode 100644 sprout/range/algorithm/includes.hpp create mode 100644 sprout/range/algorithm/is_heap.hpp create mode 100644 sprout/range/algorithm/is_heap_until.hpp create mode 100644 sprout/range/algorithm/is_partitioned.hpp create mode 100644 sprout/range/algorithm/is_permutation.hpp create mode 100644 sprout/range/algorithm/is_sorted.hpp create mode 100644 sprout/range/algorithm/is_sorted_until.hpp create mode 100644 sprout/range/algorithm/lexicographical_compare.hpp create mode 100644 sprout/range/algorithm/lower_bound.hpp create mode 100644 sprout/range/algorithm/max_element.hpp create mode 100644 sprout/range/algorithm/min_element.hpp create mode 100644 sprout/range/algorithm/minmax_element.hpp create mode 100644 sprout/range/algorithm/mismatch.hpp create mode 100644 sprout/range/algorithm/none_of.hpp create mode 100644 sprout/range/algorithm/partition_point.hpp create mode 100644 sprout/range/algorithm/search.hpp create mode 100644 sprout/range/algorithm/search_n.hpp create mode 100644 sprout/range/algorithm/upper_bound.hpp create mode 100644 sprout/range/lvref_iterator.hpp create mode 100644 sprout/range/lvref_range.hpp create mode 100644 sprout/range/numeric/accumulate.hpp create mode 100644 sprout/range/numeric/inner_product.hpp create mode 100644 sprout/range/range_container.hpp create mode 100644 sprout/range/range_return.hpp create mode 100644 sprout/utility/as_const.hpp create mode 100644 sprout/utility/as_lvref.hpp create mode 100644 sprout/utility/operation_ext.hpp diff --git a/sprout/container/empty.hpp b/sprout/container/empty.hpp index 6c4f2085..f890bf6d 100644 --- a/sprout/container/empty.hpp +++ b/sprout/container/empty.hpp @@ -2,7 +2,8 @@ #define SPROUT_CONTAINER_EMPTY_HPP #include -#include +#include +#include namespace sprout { // @@ -10,7 +11,7 @@ namespace sprout { // template SPROUT_CONSTEXPR inline bool empty(Container const& cont) { - return sprout::size(cont) == 0; + return sprout::begin(cont) == sprout::end(cont); } } // namespace sprout diff --git a/sprout/iterator/distance.hpp b/sprout/iterator/distance.hpp index 31e94511..1eb79140 100644 --- a/sprout/iterator/distance.hpp +++ b/sprout/iterator/distance.hpp @@ -9,16 +9,16 @@ namespace sprout { namespace detail { // Copyright (C) 2011 RiSK (sscrisk) - template - SPROUT_CONSTEXPR typename std::iterator_traits::difference_type - distance(Iterator first, Iterator last) { + template + SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + distance(InputIterator first, InputIterator last) { return first == last ? 0 : 1 + sprout::detail::distance(sprout::next(first), last) ; } - template - SPROUT_CONSTEXPR typename std::iterator_traits::difference_type - distance_impl(Iterator first, Iterator last) { + template + SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + distance_impl(InputIterator first, InputIterator last) { using sprout::detail::distance; return distance(first, last); } @@ -26,9 +26,9 @@ namespace sprout { // // distance // - template - SPROUT_CONSTEXPR typename std::iterator_traits::difference_type - distance(Iterator first, Iterator last) { + template + SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + distance(InputIterator first, InputIterator last) { return sprout::detail::distance_impl(first, last); } } // namespace sprout diff --git a/sprout/iterator/next.hpp b/sprout/iterator/next.hpp index 9699a409..f38bc9bf 100644 --- a/sprout/iterator/next.hpp +++ b/sprout/iterator/next.hpp @@ -8,70 +8,70 @@ namespace sprout { namespace detail { - template + template SPROUT_CONSTEXPR typename std::enable_if< - std::is_literal_type::type>::value, - typename std::decay::type + std::is_literal_type::type>::value, + typename std::decay::type >::type next_impl( - Iterator&& it, + RandomAccessIterator&& it, std::random_access_iterator_tag* ) { - return sprout::forward(it) + 1; + return sprout::forward(it) + 1; } - template - SPROUT_CONSTEXPR typename std::decay::type next_impl( - Iterator&& it, + template + SPROUT_CONSTEXPR typename std::decay::type next_impl( + ForwardIterator&& it, void* ) { using std::next; - return next(sprout::forward(it)); + return next(sprout::forward(it)); } - template + template SPROUT_CONSTEXPR typename std::enable_if< - std::is_literal_type::type>::value, - typename std::decay::type + std::is_literal_type::type>::value, + typename std::decay::type >::type next_impl( - Iterator&& it, - typename std::iterator_traits::type>::difference_type n, + RandomAccessIterator&& it, + typename std::iterator_traits::type>::difference_type n, std::random_access_iterator_tag* ) { - return sprout::forward(it) + n; + return sprout::forward(it) + n; } - template - SPROUT_CONSTEXPR typename std::decay::type next_impl( - Iterator it, - typename std::iterator_traits::type>::difference_type n, + template + SPROUT_CONSTEXPR typename std::decay::type next_impl( + ForwardIterator it, + typename std::iterator_traits::type>::difference_type n, void* ) { using std::next; - return next(sprout::forward(it), n); + return next(sprout::forward(it), n); } } // namespace detail // // next // - template - SPROUT_CONSTEXPR typename std::decay::type next(Iterator&& it) { - typedef typename std::iterator_traits::type>::iterator_category* category; + template + SPROUT_CONSTEXPR typename std::decay::type next(ForwardIterator&& it) { + typedef typename std::iterator_traits::type>::iterator_category* category; return sprout::detail::next_impl( - sprout::forward(it), + sprout::forward(it), category() ); } - template - SPROUT_CONSTEXPR typename std::decay::type next( - Iterator&& it, - typename std::iterator_traits::type>::difference_type n + template + SPROUT_CONSTEXPR typename std::decay::type next( + ForwardIterator&& it, + typename std::iterator_traits::type>::difference_type n ) { - typedef typename std::iterator_traits::type>::iterator_category* category; + typedef typename std::iterator_traits::type>::iterator_category* category; return sprout::detail::next_impl( - sprout::forward(it), + sprout::forward(it), n, category() ); diff --git a/sprout/iterator/prev.hpp b/sprout/iterator/prev.hpp index 1eb9c099..3cb8913c 100644 --- a/sprout/iterator/prev.hpp +++ b/sprout/iterator/prev.hpp @@ -8,70 +8,70 @@ namespace sprout { namespace detail { - template + template SPROUT_CONSTEXPR typename std::enable_if< - std::is_literal_type::type>::value, - typename std::decay::type + std::is_literal_type::type>::value, + typename std::decay::type >::type prev_impl( - Iterator&& it, + RandomAccessIterator&& it, std::random_access_iterator_tag* ) { - return sprout::forward(it) - 1; + return sprout::forward(it) - 1; } - template - SPROUT_CONSTEXPR typename std::decay::type prev_impl( - Iterator&& it, + template + SPROUT_CONSTEXPR typename std::decay::type prev_impl( + BidirectionalIterator&& it, void* ) { using std::prev; - return prev(sprout::forward(it)); + return prev(sprout::forward(it)); } - template + template SPROUT_CONSTEXPR typename std::enable_if< - std::is_literal_type::type>::value, - typename std::decay::type + std::is_literal_type::type>::value, + typename std::decay::type >::type prev_impl( - Iterator&& it, - typename std::iterator_traits::type>::difference_type n, + RandomAccessIterator&& it, + typename std::iterator_traits::type>::difference_type n, std::random_access_iterator_tag* ) { - return sprout::forward(it) - n; + return sprout::forward(it) - n; } - template - SPROUT_CONSTEXPR typename std::decay::type prev_impl( - Iterator it, - typename std::iterator_traits::type>::difference_type n, + template + SPROUT_CONSTEXPR typename std::decay::type prev_impl( + BidirectionalIterator it, + typename std::iterator_traits::type>::difference_type n, void* ) { using std::prev; - return prev(sprout::forward(it), n); + return prev(sprout::forward(it), n); } } // namespace detail // // prev // - template - SPROUT_CONSTEXPR typename std::decay::type prev(Iterator&& it) { - typedef typename std::iterator_traits::type>::iterator_category* category; + template + SPROUT_CONSTEXPR typename std::decay::type prev(BidirectionalIterator&& it) { + typedef typename std::iterator_traits::type>::iterator_category* category; return sprout::detail::prev_impl( - sprout::forward(it), + sprout::forward(it), category() ); } - template - SPROUT_CONSTEXPR typename std::decay::type prev( - Iterator&& it, - typename std::iterator_traits::type>::difference_type n + template + SPROUT_CONSTEXPR typename std::decay::type prev( + BidirectionalIterator&& it, + typename std::iterator_traits::type>::difference_type n ) { - typedef typename std::iterator_traits::type>::iterator_category* category; + typedef typename std::iterator_traits::type>::iterator_category* category; return sprout::detail::prev_impl( - sprout::forward(it), + sprout::forward(it), n, category() ); diff --git a/sprout/numeric/accumulate.hpp b/sprout/numeric/accumulate.hpp index 3a0f5bb7..acacf497 100644 --- a/sprout/numeric/accumulate.hpp +++ b/sprout/numeric/accumulate.hpp @@ -9,14 +9,14 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 26.7.2 Accumulate - template + template SPROUT_CONSTEXPR T accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) { return first == last ? init - : sprout::accumulate(first + 1, last, binary_op(init, *first), binary_op) + : sprout::accumulate(sprout::next(first), last, binary_op(init, *first), binary_op) ; } - template + template SPROUT_CONSTEXPR T accumulate(InputIterator first, InputIterator last, T init) { return sprout::accumulate(first, last, init, NS_SSCRISK_CEL_OR_SPROUT::plus::value_type>()); } diff --git a/sprout/numeric/inner_product.hpp b/sprout/numeric/inner_product.hpp index 6368e0bb..db9a364c 100644 --- a/sprout/numeric/inner_product.hpp +++ b/sprout/numeric/inner_product.hpp @@ -10,7 +10,7 @@ namespace sprout { // Copyright (C) 2011 RiSK (sscrisk) // 26.7.3 Inner product - template + template SPROUT_CONSTEXPR T inner_product( InputIterator1 first1, InputIterator1 last1, @@ -32,7 +32,7 @@ namespace sprout { ; } - template + template SPROUT_CONSTEXPR T inner_product( InputIterator1 first1, InputIterator1 last1, diff --git a/sprout/range/algorithm/adjacent_find.hpp b/sprout/range/algorithm/adjacent_find.hpp new file mode 100644 index 00000000..6caf6ebe --- /dev/null +++ b/sprout/range/algorithm/adjacent_find.hpp @@ -0,0 +1,67 @@ +#ifndef SPROUT_RANGE_ALGORITHM_ADJACENT_FIND_HPP +#define SPROUT_RANGE_ALGORITHM_ADJACENT_FIND_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.8 Adjacent find + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + adjacent_find(Range&& range) { + return sprout::range::range_return::pack( + sprout::adjacent_find( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + adjacent_find(Range&& range, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::adjacent_find( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + pred + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + adjacent_find(Range&& range) { + return sprout::range::range_return::pack( + sprout::adjacent_find( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + adjacent_find(Range&& range, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::adjacent_find( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + pred + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_ADJACENT_FIND_HPP diff --git a/sprout/range/algorithm/all_of.hpp b/sprout/range/algorithm/all_of.hpp new file mode 100644 index 00000000..35c08a68 --- /dev/null +++ b/sprout/range/algorithm/all_of.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_RANGE_ALGORITHM_ALL_OF_HPP +#define SPROUT_RANGE_ALGORITHM_ALL_OF_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.1 All of + template + SPROUT_CONSTEXPR bool all_of(Range const& range, Predicate pred) { + return sprout::all_of(sprout::begin(range), sprout::end(range), pred); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_ALL_OF_HPP diff --git a/sprout/range/algorithm/any_of.hpp b/sprout/range/algorithm/any_of.hpp new file mode 100644 index 00000000..70eb9be4 --- /dev/null +++ b/sprout/range/algorithm/any_of.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_RANGE_ALGORITHM_ANY_OF_HPP +#define SPROUT_RANGE_ALGORITHM_ANY_OF_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.2 Any of + template + SPROUT_CONSTEXPR bool any_of(Range const& range, Predicate pred) { + return sprout::any_of(sprout::begin(range), sprout::end(range), pred); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_ANY_OF_HPP diff --git a/sprout/range/algorithm/binary_search.hpp b/sprout/range/algorithm/binary_search.hpp new file mode 100644 index 00000000..c3b4fd59 --- /dev/null +++ b/sprout/range/algorithm/binary_search.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_RANGE_ALGORITHM_BINARY_SEARCH_HPP +#define SPROUT_RANGE_ALGORITHM_BINARY_SEARCH_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.3.4 binary_search + template + SPROUT_CONSTEXPR bool binary_search(Range const& range, T const& value) { + return sprout::binary_search(sprout::begin(range), sprout::end(range), value); + } + + template + SPROUT_CONSTEXPR bool binary_search(Range const& range, T const& value, Compare comp) { + return sprout::binary_search(sprout::begin(range), sprout::end(range), value, comp); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_BINARY_SEARCH_HPP diff --git a/sprout/range/algorithm/count.hpp b/sprout/range/algorithm/count.hpp new file mode 100644 index 00000000..8c780e80 --- /dev/null +++ b/sprout/range/algorithm/count.hpp @@ -0,0 +1,22 @@ +#ifndef SPROUT_RANGE_ALGORITHM_COUNT_HPP +#define SPROUT_RANGE_ALGORITHM_COUNT_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.9 Count + template + SPROUT_CONSTEXPR typename sprout::container_traits::difference_type + count(Range const& range, T const& value) { + return sprout::count(sprout::begin(range), sprout::end(range), value); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_COUNT_HPP diff --git a/sprout/range/algorithm/count_if.hpp b/sprout/range/algorithm/count_if.hpp new file mode 100644 index 00000000..34ff8ff7 --- /dev/null +++ b/sprout/range/algorithm/count_if.hpp @@ -0,0 +1,22 @@ +#ifndef SPROUT_RANGE_ALGORITHM_COUNT_IF_HPP +#define SPROUT_RANGE_ALGORITHM_COUNT_IF_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.9 Count + template + SPROUT_CONSTEXPR typename sprout::container_traits::difference_type + count_if(Range const& range, Predicate pred) { + return sprout::count_if(sprout::begin(range), sprout::end(range), pred); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_COUNT_IF_HPP diff --git a/sprout/range/algorithm/equal.hpp b/sprout/range/algorithm/equal.hpp new file mode 100644 index 00000000..c648d60b --- /dev/null +++ b/sprout/range/algorithm/equal.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_RANGE_ALGORITHM_EQUAL_HPP +#define SPROUT_RANGE_ALGORITHM_EQUAL_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.11 Equal + template + SPROUT_CONSTEXPR bool equal(Range1 const& range1, Range2 const& range2) { + return sprout::equal(sprout::begin(range1), sprout::end(range1), sprout::begin(range2)); + } + + template + SPROUT_CONSTEXPR bool equal(Range1 const& range1, Range2 const& range2, BinaryPredicate pred) { + return sprout::equal(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), pred); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_EQUAL_HPP diff --git a/sprout/range/algorithm/equal_range.hpp b/sprout/range/algorithm/equal_range.hpp new file mode 100644 index 00000000..4ceee4ca --- /dev/null +++ b/sprout/range/algorithm/equal_range.hpp @@ -0,0 +1,50 @@ +#ifndef SPROUT_RANGE_ALGORITHM_EQUAL_RANGE_HPP +#define SPROUT_RANGE_ALGORITHM_EQUAL_RANGE_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace detail { + template + SPROUT_CONSTEXPR typename sprout::range::lvref_range::type + pair_to_range(Pair const& pair) { + return {pair.first, pair.second}; + } + } // namespace detail + + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.3.3 equal_range + template + SPROUT_CONSTEXPR typename sprout::range::lvref_range::type + equal_range(Range&& range, T const& value) { + return sprout::range::detail::pair_to_range( + sprout::equal_range( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value + ) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::lvref_range::type + equal_range(Range&& range, T const& value, Compare comp) { + return sprout::range::detail::pair_to_range( + sprout::equal_range( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value, + comp + ) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_EQUAL_RANGE_HPP diff --git a/sprout/range/algorithm/find.hpp b/sprout/range/algorithm/find.hpp new file mode 100644 index 00000000..c35f8867 --- /dev/null +++ b/sprout/range/algorithm/find.hpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_RANGE_ALGORITHM_FIND_HPP +#define SPROUT_RANGE_ALGORITHM_FIND_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.5 Find + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find(Range&& range, T const& value) { + return sprout::range::range_return::pack( + sprout::find( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find(Range&& range, T const& value) { + return sprout::range::range_return::pack( + sprout::find( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_FIND_HPP diff --git a/sprout/range/algorithm/find_end.hpp b/sprout/range/algorithm/find_end.hpp new file mode 100644 index 00000000..2e14fc3b --- /dev/null +++ b/sprout/range/algorithm/find_end.hpp @@ -0,0 +1,75 @@ +#ifndef SPROUT_RANGE_ALGORITHM_FIND_END_HPP +#define SPROUT_RANGE_ALGORITHM_FIND_END_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.6 Find end + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_end(Range1&& range1, Range2&& range2) { + return sprout::range::range_return::pack( + sprout::find_end( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)) + ), + sprout::forward(range1) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_end(Range1&& range1, Range2&& range2, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::find_end( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)), + pred + ), + sprout::forward(range1) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_end(Range1&& range1, Range2&& range2) { + return sprout::range::range_return::pack( + sprout::find_end( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)) + ), + sprout::forward(range1) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_end(Range1&& range1, Range2&& range2, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::find_end( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)), + pred + ), + sprout::forward(range1) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_FIND_END_HPP diff --git a/sprout/range/algorithm/find_first_of.hpp b/sprout/range/algorithm/find_first_of.hpp new file mode 100644 index 00000000..5a425ac1 --- /dev/null +++ b/sprout/range/algorithm/find_first_of.hpp @@ -0,0 +1,75 @@ +#ifndef SPROUT_RANGE_ALGORITHM_FIND_FIRST_OF_HPP +#define SPROUT_RANGE_ALGORITHM_FIND_FIRST_OF_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.7 Find first + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_first_of(Range1&& range1, Range2&& range2) { + return sprout::range::range_return::pack( + sprout::find_first_of( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)) + ), + sprout::forward(range1) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_first_of(Range1&& range1, Range2&& range2, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::find_first_of( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)), + pred + ), + sprout::forward(range1) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_first_of(Range1&& range1, Range2&& range2) { + return sprout::range::range_return::pack( + sprout::find_first_of( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)) + ), + sprout::forward(range1) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_first_of(Range1&& range1, Range2&& range2, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::find_first_of( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)), + pred + ), + sprout::forward(range1) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_FIND_FIRST_OF_HPP diff --git a/sprout/range/algorithm/find_if.hpp b/sprout/range/algorithm/find_if.hpp new file mode 100644 index 00000000..01e21c90 --- /dev/null +++ b/sprout/range/algorithm/find_if.hpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_RANGE_ALGORITHM_FIND_IF_HPP +#define SPROUT_RANGE_ALGORITHM_FIND_IF_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.5 Find + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_if(Range&& range, Predicate pred) { + return sprout::range::range_return::pack( + sprout::find_if( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + pred + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_if(Range&& range, Predicate pred) { + return sprout::range::range_return::pack( + sprout::find_if( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + pred + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_FIND_IF_HPP diff --git a/sprout/range/algorithm/find_if_not.hpp b/sprout/range/algorithm/find_if_not.hpp new file mode 100644 index 00000000..1cac4324 --- /dev/null +++ b/sprout/range/algorithm/find_if_not.hpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_RANGE_ALGORITHM_FIND_IF_NOT_HPP +#define SPROUT_RANGE_ALGORITHM_FIND_IF_NOT_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.5 Find + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_if_not(Range&& range, Predicate pred) { + return sprout::range::range_return::pack( + sprout::find_if_not( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + pred + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + find_if_not(Range&& range, Predicate pred) { + return sprout::range::range_return::pack( + sprout::find_if_not( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + pred + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_FIND_IF_NOT_HPP diff --git a/sprout/range/algorithm/includes.hpp b/sprout/range/algorithm/includes.hpp new file mode 100644 index 00000000..72476945 --- /dev/null +++ b/sprout/range/algorithm/includes.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_RANGE_ALGORITHM_INCLUDES_HPP +#define SPROUT_RANGE_ALGORITHM_INCLUDES_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.5.1 includes + template + SPROUT_CONSTEXPR bool includes(Range1 const& range1, Range2 const& range2) { + return sprout::includes(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2)); + } + + template + SPROUT_CONSTEXPR bool includes(Range1 const& range1, Range2 const& range2, Compare comp) { + return sprout::includes(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2), comp); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_INCLUDES_HPP diff --git a/sprout/range/algorithm/is_heap.hpp b/sprout/range/algorithm/is_heap.hpp new file mode 100644 index 00000000..8da386fc --- /dev/null +++ b/sprout/range/algorithm/is_heap.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_HEAP_HPP +#define SPROUT_RANGE_ALGORITHM_IS_HEAP_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.6.5 is_heap + template + SPROUT_CONSTEXPR bool is_heap(Range const& range) { + return sprout::is_heap(sprout::begin(range), sprout::end(range)); + } + + template + SPROUT_CONSTEXPR bool is_heap(Range const& range, Compare comp) { + return sprout::is_heap(sprout::begin(range), sprout::end(range), comp); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_HEAP_HPP diff --git a/sprout/range/algorithm/is_heap_until.hpp b/sprout/range/algorithm/is_heap_until.hpp new file mode 100644 index 00000000..369d1fb8 --- /dev/null +++ b/sprout/range/algorithm/is_heap_until.hpp @@ -0,0 +1,67 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_HEAP_UNTIL_HPP +#define SPROUT_RANGE_ALGORITHM_IS_HEAP_UNTIL_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.6.5 is_heap + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + is_heap_until(Range&& range) { + return sprout::range::range_return::pack( + sprout::is_heap_until( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + is_heap_until(Range&& range, Compare comp) { + return sprout::range::range_return::pack( + sprout::is_heap_until( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + is_heap_until(Range&& range) { + return sprout::range::range_return::pack( + sprout::is_heap_until( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + is_heap_until(Range&& range, Compare comp) { + return sprout::range::range_return::pack( + sprout::is_heap_until( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_HEAP_UNTIL_HPP diff --git a/sprout/range/algorithm/is_partitioned.hpp b/sprout/range/algorithm/is_partitioned.hpp new file mode 100644 index 00000000..9c870267 --- /dev/null +++ b/sprout/range/algorithm/is_partitioned.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_PARTITIONED_HPP +#define SPROUT_RANGE_ALGORITHM_IS_PARTITIONED_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.3.13 partitions + template + SPROUT_CONSTEXPR bool is_partitioned(Range const& range, Predicate pred) { + return sprout::is_partitioned(sprout::begin(range), sprout::end(range), pred); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_PARTITIONED_HPP diff --git a/sprout/range/algorithm/is_permutation.hpp b/sprout/range/algorithm/is_permutation.hpp new file mode 100644 index 00000000..eb87d31f --- /dev/null +++ b/sprout/range/algorithm/is_permutation.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_PERMUTATION_HPP +#define SPROUT_RANGE_ALGORITHM_IS_PERMUTATION_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.12 Is permutation + template + SPROUT_CONSTEXPR bool is_permutation(Range1 const& range1, Range2 const& range2) { + return sprout::is_permutation(sprout::begin(range1), sprout::end(range1), sprout::begin(range2)); + } + + template + SPROUT_CONSTEXPR bool is_permutation(Range1 const& range1, Range2 const& range2, BinaryPredicate pred) { + return sprout::is_permutation(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), pred); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_PERMUTATION_HPP diff --git a/sprout/range/algorithm/is_sorted.hpp b/sprout/range/algorithm/is_sorted.hpp new file mode 100644 index 00000000..2f12cb55 --- /dev/null +++ b/sprout/range/algorithm/is_sorted.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_SORTED_HPP +#define SPROUT_RANGE_ALGORITHM_IS_SORTED_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.1.5 is_sorted + template + SPROUT_CONSTEXPR bool is_sorted(Range const& range) { + return sprout::is_sorted(sprout::begin(range), sprout::end(range)); + } + + template + SPROUT_CONSTEXPR bool is_sorted(Range const& range, Compare comp) { + return sprout::is_sorted(sprout::begin(range), sprout::end(range), comp); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_SORTED_HPP diff --git a/sprout/range/algorithm/is_sorted_until.hpp b/sprout/range/algorithm/is_sorted_until.hpp new file mode 100644 index 00000000..0833f795 --- /dev/null +++ b/sprout/range/algorithm/is_sorted_until.hpp @@ -0,0 +1,67 @@ +#ifndef SPROUT_RANGE_ALGORITHM_IS_SORTED_UNTIL_HPP +#define SPROUT_RANGE_ALGORITHM_IS_SORTED_UNTIL_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.1.5 is_sorted + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + is_sorted_until(Range&& range) { + return sprout::range::range_return::pack( + sprout::is_sorted_until( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + is_sorted_until(Range&& range, Compare comp) { + return sprout::range::range_return::pack( + sprout::is_sorted_until( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + is_sorted_until(Range&& range) { + return sprout::range::range_return::pack( + sprout::is_sorted_until( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + is_sorted_until(Range&& range, Compare comp) { + return sprout::range::range_return::pack( + sprout::is_sorted_until( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_IS_SORTED_UNTIL_HPP diff --git a/sprout/range/algorithm/lexicographical_compare.hpp b/sprout/range/algorithm/lexicographical_compare.hpp new file mode 100644 index 00000000..845bea92 --- /dev/null +++ b/sprout/range/algorithm/lexicographical_compare.hpp @@ -0,0 +1,25 @@ +#ifndef SPROUT_RANGE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP +#define SPROUT_RANGE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.8 Lexicographical comparison + template + SPROUT_CONSTEXPR bool lexicographical_compare(Range1 const& range1, Range2 const& range2) { + return sprout::lexicographical_compare(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2)); + } + + template + SPROUT_CONSTEXPR bool lexicographical_compare(Range1 const& range1, Range2 const& range2, Compare comp) { + return sprout::lexicographical_compare(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2), comp); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP diff --git a/sprout/range/algorithm/lower_bound.hpp b/sprout/range/algorithm/lower_bound.hpp new file mode 100644 index 00000000..70cbf5bf --- /dev/null +++ b/sprout/range/algorithm/lower_bound.hpp @@ -0,0 +1,71 @@ +#ifndef SPROUT_RANGE_ALGORITHM_LOWER_BOUND_HPP +#define SPROUT_RANGE_ALGORITHM_LOWER_BOUND_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.3.1 lower_bound + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + lower_bound(Range&& range, T const& value) { + return sprout::range::range_return::pack( + sprout::lower_bound( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + lower_bound(Range&& range, T const& value, Compare comp) { + return sprout::range::range_return::pack( + sprout::lower_bound( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value, + comp + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + lower_bound(Range&& range, T const& value) { + return sprout::range::range_return::pack( + sprout::lower_bound( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + lower_bound(Range&& range, T const& value, Compare comp) { + return sprout::range::range_return::pack( + sprout::lower_bound( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value, + comp + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_LOWER_BOUND_HPP diff --git a/sprout/range/algorithm/max_element.hpp b/sprout/range/algorithm/max_element.hpp new file mode 100644 index 00000000..93479653 --- /dev/null +++ b/sprout/range/algorithm/max_element.hpp @@ -0,0 +1,67 @@ +#ifndef SPROUT_RANGE_ALGORITHM_MAX_ELEMENT_HPP +#define SPROUT_RANGE_ALGORITHM_MAX_ELEMENT_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.7 Minimum and maximum + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + max_element(Range&& range) { + return sprout::range::range_return::pack( + sprout::max_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + max_element(Range&& range, Compare comp) { + return sprout::range::range_return::pack( + sprout::max_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + max_element(Range&& range) { + return sprout::range::range_return::pack( + sprout::max_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + max_element(Range&& range, Compare comp) { + return sprout::range::range_return::pack( + sprout::max_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_MAX_ELEMENT_HPP diff --git a/sprout/range/algorithm/min_element.hpp b/sprout/range/algorithm/min_element.hpp new file mode 100644 index 00000000..d9c257de --- /dev/null +++ b/sprout/range/algorithm/min_element.hpp @@ -0,0 +1,67 @@ +#ifndef SPROUT_RANGE_ALGORITHM_MIN_ELEMENT_HPP +#define SPROUT_RANGE_ALGORITHM_MIN_ELEMENT_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.7 Minimum and maximum + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + min_element(Range&& range) { + return sprout::range::range_return::pack( + sprout::min_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + min_element(Range&& range, Compare comp) { + return sprout::range::range_return::pack( + sprout::min_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + min_element(Range&& range) { + return sprout::range::range_return::pack( + sprout::min_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + min_element(Range&& range, Compare comp) { + return sprout::range::range_return::pack( + sprout::min_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_MIN_ELEMENT_HPP diff --git a/sprout/range/algorithm/minmax_element.hpp b/sprout/range/algorithm/minmax_element.hpp new file mode 100644 index 00000000..206be72c --- /dev/null +++ b/sprout/range/algorithm/minmax_element.hpp @@ -0,0 +1,106 @@ +#ifndef SPROUT_RANGE_ALGORITHM_MINMAX_ELEMENT_HPP +#define SPROUT_RANGE_ALGORITHM_MINMAX_ELEMENT_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + namespace detail { + template + SPROUT_CONSTEXPR sprout::pair< + typename sprout::range::range_return::type, + typename sprout::range::range_return::type + > + pack_pair(Pair const& pair, Range&& range) { + return { + sprout::range::range_return::pack(pair.first, sprout::forward(range)), + sprout::range::range_return::pack(pair.second, sprout::forward(range)) + }; + } + + template + SPROUT_CONSTEXPR sprout::pair< + typename sprout::range::range_return::type, + typename sprout::range::range_return::type + > + pack_pair(Pair const& pair, Range&& range) { + return { + sprout::range::range_return::pack(pair.first, sprout::forward(range)), + sprout::range::range_return::pack(pair.second, sprout::forward(range)) + }; + } + } // namespace detail + + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.7 Minimum and maximum + template + SPROUT_CONSTEXPR sprout::pair< + typename sprout::range::range_return::type, + typename sprout::range::range_return::type + > + minmax_element(Range&& range) { + return sprout::range::detail::pack_pair( + sprout::minmax_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR sprout::pair< + typename sprout::range::range_return::type, + typename sprout::range::range_return::type + > + minmax_element(Range&& range, Compare comp) { + return sprout::range::detail::pack_pair( + sprout::minmax_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR sprout::pair< + typename sprout::range::range_return::type, + typename sprout::range::range_return::type + > + minmax_element(Range&& range) { + return sprout::range::detail::pack_pair( + sprout::minmax_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)) + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR sprout::pair< + typename sprout::range::range_return::type, + typename sprout::range::range_return::type + > + minmax_element(Range&& range, Compare comp) { + return sprout::range::detail::pack_pair( + sprout::minmax_element( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + comp + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_MINMAX_ELEMENT_HPP diff --git a/sprout/range/algorithm/mismatch.hpp b/sprout/range/algorithm/mismatch.hpp new file mode 100644 index 00000000..96b9dc13 --- /dev/null +++ b/sprout/range/algorithm/mismatch.hpp @@ -0,0 +1,45 @@ +#ifndef SPROUT_RANGE_ALGORITHM_MISMATCH_HPP +#define SPROUT_RANGE_ALGORITHM_MISMATCH_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.10 Mismatch + template + SPROUT_CONSTEXPR sprout::pair< + typename sprout::range::lvref_iterator::type, + typename sprout::range::lvref_iterator::type + > + mismatch(Range1&& range1, Range2&& range2) { + return sprout::mismatch( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)) + ); + } + + template + SPROUT_CONSTEXPR sprout::pair< + typename sprout::range::lvref_iterator::type, + typename sprout::range::lvref_iterator::type + > + mismatch(Range1&& range1, Range2&& range2, BinaryPredicate pred) { + return sprout::mismatch( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + pred + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_MISMATCH_HPP diff --git a/sprout/range/algorithm/non_modifying.hpp b/sprout/range/algorithm/non_modifying.hpp index 78686a71..bb9f6330 100644 --- a/sprout/range/algorithm/non_modifying.hpp +++ b/sprout/range/algorithm/non_modifying.hpp @@ -2,39 +2,36 @@ #define SPROUT_RANGE_ALGORITHM_NON_MODIFYIING_HPP #include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif // #ifndef SPROUT_RANGE_ALGORITHM_NON_MODIFYIING_HPP diff --git a/sprout/range/algorithm/none_of.hpp b/sprout/range/algorithm/none_of.hpp new file mode 100644 index 00000000..f06831bb --- /dev/null +++ b/sprout/range/algorithm/none_of.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_RANGE_ALGORITHM_NONE_OF_HPP +#define SPROUT_RANGE_ALGORITHM_NONE_OF_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.3 None of + template + SPROUT_CONSTEXPR bool none_of(Range const& range, Predicate pred) { + return sprout::none_of(sprout::begin(range), sprout::end(range), pred); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_NONE_OF_HPP diff --git a/sprout/range/algorithm/partition_point.hpp b/sprout/range/algorithm/partition_point.hpp new file mode 100644 index 00000000..ce7b86ee --- /dev/null +++ b/sprout/range/algorithm/partition_point.hpp @@ -0,0 +1,30 @@ +#ifndef SPROUT_RANGE_ALGORITHM_PARTITION_POINT_HPP +#define SPROUT_RANGE_ALGORITHM_PARTITION_POINT_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.3.13 partitions + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + partition_point(Range&& range, Predicate pred) { + return sprout::range::range_return::pack( + sprout::partition_point( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + pred + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_PARTITION_POINT_HPP diff --git a/sprout/range/algorithm/search.hpp b/sprout/range/algorithm/search.hpp new file mode 100644 index 00000000..dab263d0 --- /dev/null +++ b/sprout/range/algorithm/search.hpp @@ -0,0 +1,75 @@ +#ifndef SPROUT_RANGE_ALGORITHM_SEARCH_HPP +#define SPROUT_RANGE_ALGORITHM_SEARCH_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.13 Search + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + search(Range1&& range1, Range2&& range2) { + return sprout::range::range_return::pack( + sprout::search( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)) + ), + sprout::forward(range1) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + search(Range1&& range1, Range2&& range2, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::search( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)), + pred + ), + sprout::forward(range1) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + search(Range1&& range1, Range2&& range2) { + return sprout::range::range_return::pack( + sprout::search( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)) + ), + sprout::forward(range1) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + search(Range1&& range1, Range2&& range2, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::search( + sprout::begin(sprout::forward(range1)), + sprout::end(sprout::forward(range1)), + sprout::begin(sprout::forward(range2)), + sprout::end(sprout::forward(range2)), + pred + ), + sprout::forward(range1) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_SEARCH_HPP diff --git a/sprout/range/algorithm/search_n.hpp b/sprout/range/algorithm/search_n.hpp new file mode 100644 index 00000000..a3975c4c --- /dev/null +++ b/sprout/range/algorithm/search_n.hpp @@ -0,0 +1,75 @@ +#ifndef SPROUT_RANGE_ALGORITHM_SEARCH_N_HPP +#define SPROUT_RANGE_ALGORITHM_SEARCH_N_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.2.13 Search + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + search_n(Range&& range, Size count, T const& value) { + return sprout::range::range_return::pack( + sprout::search_n( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + count, + value + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + search_n(Range&& range, Size count, T const& value, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::search_n( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + count, + value, + pred + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + search_n(Range&& range, Size count, T const& value) { + return sprout::range::range_return::pack( + sprout::search_n( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + count, + value + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + search_n(Range&& range, Size count, T const& value, BinaryPredicate pred) { + return sprout::range::range_return::pack( + sprout::search_n( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + count, + value, + pred + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_SEARCH_N_HPP diff --git a/sprout/range/algorithm/upper_bound.hpp b/sprout/range/algorithm/upper_bound.hpp new file mode 100644 index 00000000..85e28cff --- /dev/null +++ b/sprout/range/algorithm/upper_bound.hpp @@ -0,0 +1,71 @@ +#ifndef SPROUT_RANGE_ALGORITHM_UPPER_BOUND_HPP +#define SPROUT_RANGE_ALGORITHM_UPPER_BOUND_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // Copyright (C) 2011 RiSK (sscrisk) + + // 25.4.3.2 upper_bound + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + upper_bound(Range&& range, T const& value) { + return sprout::range::range_return::pack( + sprout::upper_bound( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + upper_bound(Range&& range, T const& value, Compare comp) { + return sprout::range::range_return::pack( + sprout::upper_bound( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value, + comp + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + upper_bound(Range&& range, T const& value) { + return sprout::range::range_return::pack( + sprout::upper_bound( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value + ), + sprout::forward(range) + ); + } + + template + SPROUT_CONSTEXPR typename sprout::range::range_return::type + upper_bound(Range&& range, T const& value, Compare comp) { + return sprout::range::range_return::pack( + sprout::upper_bound( + sprout::begin(sprout::forward(range)), + sprout::end(sprout::forward(range)), + value, + comp + ), + sprout::forward(range) + ); + } + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_ALGORITHM_UPPER_BOUND_HPP diff --git a/sprout/range/lvref_iterator.hpp b/sprout/range/lvref_iterator.hpp new file mode 100644 index 00000000..ce09aec6 --- /dev/null +++ b/sprout/range/lvref_iterator.hpp @@ -0,0 +1,24 @@ +#ifndef SPROUT_RANGE_LVREF_ITERATOR_HPP +#define SPROUT_RANGE_LVREF_ITERATOR_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace range { + // + // lvref_iterator + // + template + struct lvref_iterator { + public: + typedef typename sprout::container_traits< + typename std::remove_reference::type>::type + >::iterator type; + }; + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_LVREF_ITERATOR_HPP diff --git a/sprout/range/lvref_range.hpp b/sprout/range/lvref_range.hpp new file mode 100644 index 00000000..ec7b3302 --- /dev/null +++ b/sprout/range/lvref_range.hpp @@ -0,0 +1,21 @@ +#ifndef SPROUT_RANGE_LVREF_RANGE_HPP +#define SPROUT_RANGE_LVREF_RANGE_HPP + +#include +#include +#include + +namespace sprout { + namespace range { + // + // lvref_range + // + template + struct lvref_range { + public: + typedef sprout::range::range_container::type> type; + }; + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_LVREF_RANGE_HPP diff --git a/sprout/range/numeric/accumulate.hpp b/sprout/range/numeric/accumulate.hpp new file mode 100644 index 00000000..2b0b21a5 --- /dev/null +++ b/sprout/range/numeric/accumulate.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_RANGE_NUMERIC_ACCUMLATE_HPP +#define SPROUT_RANGE_NUMERIC_ACCUMLATE_HPP + +#include +#include + +namespace sprout { + // 26.7.2 Accumulate + template + SPROUT_CONSTEXPR T accumulate(Range const& range, T init, BinaryOperation binary_op) { + return sprout::accumulate(sprout::begin(range), sprout::end(range), init, binary_op); + } + + template + SPROUT_CONSTEXPR T accumulate(Range const& range, T init) { + return sprout::accumulate(sprout::begin(range), sprout::end(range), init); + } +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_ACCUMLATE_HPP diff --git a/sprout/range/numeric/inner_product.hpp b/sprout/range/numeric/inner_product.hpp new file mode 100644 index 00000000..59c3ece5 --- /dev/null +++ b/sprout/range/numeric/inner_product.hpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_RANGE_NUMERIC_INNER_PRODUCT_HPP +#define SPROUT_RANGE_NUMERIC_INNER_PRODUCT_HPP + +#include +#include + +namespace sprout { + // 26.7.3 Inner product + template + SPROUT_CONSTEXPR T inner_product( + Range1 const& range1, + Range2 const& range2, + T init, + BinaryOperation1 binary_op1, + BinaryOperation2 binary_op2 + ) + { + return sprout::inner_product(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), init, binary_op1, binary_op2); + } + + template + SPROUT_CONSTEXPR T inner_product( + Range1 const& range1, + Range2 const& range2, + T init + ) + { + return sprout::inner_product(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), init); + } +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_NUMERIC_INNER_PRODUCT_HPP diff --git a/sprout/range/numeric/non_modifying.hpp b/sprout/range/numeric/non_modifying.hpp index 0bd1f10e..e3f632e4 100644 --- a/sprout/range/numeric/non_modifying.hpp +++ b/sprout/range/numeric/non_modifying.hpp @@ -2,7 +2,7 @@ #define SPROUT_RANGE_NUMERIC_NON_MODIFYIING_HPP #include -//#include -//#include +#include +#include #endif // #ifndef SPROUT_RANGE_NUMERIC_NON_MODIFYIING_HPP diff --git a/sprout/range/range_container.hpp b/sprout/range/range_container.hpp new file mode 100644 index 00000000..286e48c5 --- /dev/null +++ b/sprout/range/range_container.hpp @@ -0,0 +1,134 @@ +#ifndef SPROUT_RANGE_RANGE_CONTAINER_HPP +#define SPROUT_RANGE_RANGE_CONTAINER_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // + // range_container + // + template + struct range_container + : public sprout::container_traits + { + public: + typedef Iterator iterator; + typedef iterator const_iterator; + typedef typename std::iterator_traits::value_type value_type; + typedef typename std::iterator_traits::reference reference; + typedef typename std::remove_reference::type const& const_reference; + typedef typename std::iterator_traits::difference_type difference_type; + typedef typename std::make_unsigned::type size_type; + typedef typename std::iterator_traits::pointer pointer; + typedef typename std::remove_pointer::type const* const_pointer; + private: + iterator first_; + iterator last_; + public: + // construct/copy/destroy: + range_container() = default; + SPROUT_CONSTEXPR range_container(iterator first, iterator last) + : first_(first) + , last_(last) + {} + + template + void swap(range_container& other) { + using std::swap; + swap(other.first_, first_); + swap(other.last_, last_); + } + // iterators: + SPROUT_CONSTEXPR iterator begin() const { + return first_; + } + SPROUT_CONSTEXPR iterator end() const { + return last_; + } + // capacity: + SPROUT_CONSTEXPR size_type size() const { + return sprout::distance(first_, last_); + } + SPROUT_CONSTEXPR bool empty() const { + return first_ == last_; + } + // element access: + SPROUT_CONSTEXPR reference operator[](size_type i) const { + return *sprout::next(first_, i); + } + SPROUT_CONSTEXPR reference at(size_type i) const { + return i < size() ? *sprout::next(first_, i) + : (throw std::out_of_range("sprout::range::range_container<>: index out of range"), *sprout::next(first_, i)) + ; + } + SPROUT_CONSTEXPR reference front() const { + return *first_; + } + SPROUT_CONSTEXPR reference back() const { + return *sprout::next(first_, size() - 1); + } + // others: + template + range_container& operator=(range_container const& rhs) { + first_ = rhs.first_; + last_ = rhs.last_; + return *this; + } + template + range_container& operator=(range_container&& rhs) { + first_ = std::move(rhs.first_); + last_ = std::move(rhs.last_); + return *this; + } + }; + + // + // swap + // + template + inline void swap(sprout::range::range_container& lhs, sprout::range::range_container& rhs) { + lhs.swap(rhs); + } + + namespace detail { + template + struct is_range_container_impl + : public std::false_type + {}; + template + struct is_range_container_impl< + T, + typename std::enable_if< + std::is_same< + T, + sprout::range::range_container + >::value + >::type + > + : public std::true_type + {}; + } // namespace detail + // + // is_range_container + // + template + struct is_range_container + : public sprout::range::detail::is_range_container_impl + {}; + } // namespace range + + // + // container_traits + // + template + struct container_traits > + : public sprout::detail::container_traits_default_types > + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_RANGE_CONTAINER_HPP diff --git a/sprout/range/range_return.hpp b/sprout/range/range_return.hpp new file mode 100644 index 00000000..b1fea3ea --- /dev/null +++ b/sprout/range/range_return.hpp @@ -0,0 +1,70 @@ +#ifndef SPROUT_RANGE_RANGE_RETURN_HPP +#define SPROUT_RANGE_RANGE_RETURN_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace range { + // + // range_return_value + // + enum range_return_value { + return_found, + return_found_end, + return_begin_found + }; + + // + // range_return + // + template + struct range_return; + + template + struct range_return { + public: + typedef typename sprout::range::lvref_iterator::type type; + public: + static SPROUT_CONSTEXPR type pack( + typename sprout::container_traits::iterator found, + Range&& range + ) + { + return found; + } + }; + template + struct range_return { + public: + typedef typename sprout::range::lvref_range::type type; + public: + static SPROUT_CONSTEXPR type pack( + typename sprout::container_traits::iterator found, + Range&& range + ) + { + return type(found, sprout::end(sprout::forward(range))); + } + }; + template + struct range_return { + public: + typedef typename sprout::range::lvref_range::type type; + public: + static SPROUT_CONSTEXPR type pack( + typename sprout::container_traits::iterator found, + Range&& range + ) + { + return type(sprout::begin(sprout::forward(range)), found); + } + }; + } // namespace range +} // namespace sprout + +#endif // #ifndef SPROUT_RANGE_RANGE_RETURN_HPP diff --git a/sprout/sub_array.hpp b/sprout/sub_array.hpp index 83f5f9eb..19f92d4f 100644 --- a/sprout/sub_array.hpp +++ b/sprout/sub_array.hpp @@ -295,7 +295,7 @@ namespace sprout { return size(); } SPROUT_CONSTEXPR bool empty() const { - return size() == 0; + return first_ == last_; } // element access: reference operator[](size_type i) { diff --git a/sprout/utility/as_const.hpp b/sprout/utility/as_const.hpp new file mode 100644 index 00000000..80bd470e --- /dev/null +++ b/sprout/utility/as_const.hpp @@ -0,0 +1,20 @@ +#ifndef SPROUT_UTILITY_AS_CONST_HPP +#define SPROUT_UTILITY_AS_CONST_HPP + +#include + +namespace sprout { + // + // as_const + // + template + inline T const& as_const(T& t) { + return t; + } + template + inline SPROUT_CONSTEXPR T const& as_const(T const& t) { + return t; + } +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_AS_CONST_HPP diff --git a/sprout/utility/as_lvref.hpp b/sprout/utility/as_lvref.hpp new file mode 100644 index 00000000..e2bada45 --- /dev/null +++ b/sprout/utility/as_lvref.hpp @@ -0,0 +1,29 @@ +#ifndef SPROUT_UTILITY_AS_LVREF_HPP +#define SPROUT_UTILITY_AS_LVREF_HPP + +#include + +namespace sprout { + // + // as_lvref + // + template + inline T& as_lvref(T& t) { + return t; + } + template + inline SPROUT_CONSTEXPR T const& as_lvref(T const& t) { + return t; + } + + // + // lvref + // + template + struct lvref { + public: + typedef decltype(sprout::as_lvref(std::declval())) type; + }; +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_AS_LVREF_HPP diff --git a/sprout/utility/forward.hpp b/sprout/utility/forward.hpp index 3a9e87bf..f18e6f6a 100644 --- a/sprout/utility/forward.hpp +++ b/sprout/utility/forward.hpp @@ -9,11 +9,11 @@ namespace sprout { // forward // template - SPROUT_CONSTEXPR T&& forward(typename std::remove_reference::type& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR T&& forward(typename std::remove_reference::type& t) SPROUT_NOEXCEPT { return static_cast(t); } template - SPROUT_CONSTEXPR T&& forward(typename std::remove_reference::type&& t) SPROUT_NOEXCEPT = delete; + inline SPROUT_CONSTEXPR T&& forward(typename std::remove_reference::type&& t) SPROUT_NOEXCEPT = delete; } // namespace sprout #endif // #ifndef SPROUT_UTILITY_FORWARD_HPP diff --git a/sprout/utility/move.hpp b/sprout/utility/move.hpp index d965fb7a..022c7da2 100644 --- a/sprout/utility/move.hpp +++ b/sprout/utility/move.hpp @@ -9,7 +9,7 @@ namespace sprout { // move // template - SPROUT_CONSTEXPR typename std::remove_reference::type&& move(T&& t) SPROUT_NOEXCEPT { + inline SPROUT_CONSTEXPR typename std::remove_reference::type&& move(T&& t) SPROUT_NOEXCEPT { return static_cast::type&&>(t); } } // namespace sprout diff --git a/sprout/utility/operation_ext.hpp b/sprout/utility/operation_ext.hpp new file mode 100644 index 00000000..037c2cc1 --- /dev/null +++ b/sprout/utility/operation_ext.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_UTILITY_OPERATION_EXT_HPP +#define SPROUT_UTILITY_OPERATION_EXT_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_UTILITY_OPERATION_EXT_HPP