mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-06 14:24:09 +00:00
add doc: lexicographical_compare, clamp
This commit is contained in:
parent
29babfce4e
commit
227a35c29c
38 changed files with 997 additions and 28 deletions
|
@ -14,7 +14,7 @@ Interface
|
|||
Returns
|
||||
========================================
|
||||
|
||||
| *true* if [first,last) is empty or if ``pred(*i)`` is true for every iterator i in the range [first,last), and *false* otherwise.
|
||||
| true if [first,last) is empty or if ``pred(*i)`` is true for every iterator i in the range [first,last), and false otherwise.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
|
|
|
@ -14,7 +14,7 @@ Interface
|
|||
Returns
|
||||
========================================
|
||||
|
||||
| *true* if [first,last) is empty or if ``*i == value`` is true for every iterator i in the range [first,last), and *false* otherwise.
|
||||
| true if [first,last) is empty or if ``*i == value`` is true for every iterator i in the range [first,last), and false otherwise.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
|
|
|
@ -14,7 +14,7 @@ Interface
|
|||
Returns
|
||||
========================================
|
||||
|
||||
| *false* if [first,last) is empty or if there is no iterator i in the range [first,last) such that ``pred(*i)`` is true, and *true* otherwise.
|
||||
| false if [first,last) is empty or if there is no iterator i in the range [first,last) such that ``pred(*i)`` is true, and true otherwise.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
|
|
|
@ -14,7 +14,7 @@ Interface
|
|||
Returns
|
||||
========================================
|
||||
|
||||
| *false* if [first,last) is empty or if there is no iterator i in the range [first,last) such that ``*i == value`` is true, and *true* otherwise.
|
||||
| false if [first,last) is empty or if there is no iterator i in the range [first,last) such that ``*i == value`` is true, and true otherwise.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
|
|
57
source/libs/sprout/algorithm/clamp.rst
Normal file
57
source/libs/sprout/algorithm/clamp.rst
Normal file
|
@ -0,0 +1,57 @@
|
|||
.. _sprout-algorithm-clamp:
|
||||
###############################################################################
|
||||
clamp
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T const&
|
||||
clamp(T const& value, typename sprout::identity<T>::type const& low, typename sprout::identity<T>::type const& high);
|
||||
|
||||
template<typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR T const&
|
||||
clamp(T const& value, typename sprout::identity<T>::type const& low, typename sprout::identity<T>::type const& high, Compare comp);
|
||||
|
||||
Requires
|
||||
========================================
|
||||
|
||||
| Type T is LessThanComparable.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| low if the following corresponding conditions hold: ``value < low``, ``comp(value, low)``.
|
||||
| high if the following corresponding conditions hold: ``high < value``, ``comp(high, value)``.
|
||||
| Otherwise, returns value.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| Using clamp with floating point numbers may give unexpected results if one of the values is NaN.
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| Exactly one or two comparisons.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/clamp.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{0, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::clamp(20, input[0], input[1]);
|
||||
static_assert(result == 10, "clamped value is 10.");
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/clamp.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
|
@ -45,6 +45,9 @@ Sprout.Algorithm
|
|||
min_element
|
||||
max_element
|
||||
minmax_element
|
||||
lexicographical_compare
|
||||
tristate_lexicographical_compare
|
||||
clamp
|
||||
|
||||
.. _sprout-algorithm-non_modifying:
|
||||
*******************************************************************************
|
||||
|
|
72
source/libs/sprout/algorithm/lexicographical_compare.rst
Normal file
72
source/libs/sprout/algorithm/lexicographical_compare.rst
Normal file
|
@ -0,0 +1,72 @@
|
|||
.. _sprout-algorithm-lexicographical_compare:
|
||||
###############################################################################
|
||||
lexicographical_compare
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
lexicographical_compare(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2
|
||||
);
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
lexicographical_compare(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| true if the sequence of elements defined by the range [first1,last1) is lexicographically less than the sequence of elements defined by the range [first2,last2) and false otherwise.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| If two sequences have the same number of elements and their corresponding elements are equivalent, then neither sequence is lexicographically less than the other.
|
||||
| If one sequence is a prefix of the other, then the shorter sequence is lexicographically less than the longer sequence.
|
||||
| Otherwise, the lexicographical comparison of the sequences yields the same result as the comparison of the first corresponding pair of elements that are not equivalent.
|
||||
|
||||
.. sourcecode:: c++
|
||||
|
||||
for (; first1 != last1 && first2 != last2; ++first1, ++first2) {
|
||||
if (*first1 < *first2) return true;
|
||||
if (*first2 < *first1) return false;
|
||||
}
|
||||
return first1 == last1 && first2 != last2;
|
||||
|
||||
| An empty sequence is lexicographically less than any non-empty sequence, but not less than any empty sequence.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/lexicographical_compare.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto input2 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 11, 12, 13}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::lexicographical_compare(begin(input1), end(input1), begin(input2), end(input2));
|
||||
static_assert(result, "input1 < input2 by lexicographical comparison.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| At most ``2*min((last1 - first1), (last2 - first2))`` applications of the corresponding comparison.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/lexicographical_compare.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
|
@ -14,7 +14,7 @@ Interface
|
|||
Returns
|
||||
========================================
|
||||
|
||||
| *true* if [first,last) is empty or if ``pred(*i)`` is false for every iterator i in the range [first,last), and *false* otherwise.
|
||||
| true if [first,last) is empty or if ``pred(*i)`` is false for every iterator i in the range [first,last), and false otherwise.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
|
|
|
@ -14,7 +14,7 @@ Interface
|
|||
Returns
|
||||
========================================
|
||||
|
||||
| *true* if [first,last) is empty or if ``*i == value`` is false for every iterator i in the range [first,last), and *false* otherwise.
|
||||
| true if [first,last) is empty or if ``*i == value`` is false for every iterator i in the range [first,last), and false otherwise.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
|
|
|
@ -14,7 +14,7 @@ Interface
|
|||
Returns
|
||||
========================================
|
||||
|
||||
| *true* if [first,last) is not empty and there is only one iterator i in the range [first,last) such that ``pred(*i)`` is true, and *false* otherwise.
|
||||
| true if [first,last) is not empty and there is only one iterator i in the range [first,last) such that ``pred(*i)`` is true, and false otherwise.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
|
|
|
@ -14,7 +14,7 @@ Interface
|
|||
Returns
|
||||
========================================
|
||||
|
||||
| *true* if [first,last) is not empty and there is only one iterator i in the range [first,last) such that ``*i == value`` is true, and *false* otherwise.
|
||||
| true if [first,last) is not empty and there is only one iterator i in the range [first,last) such that ``*i == value`` is true, and false otherwise.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
.. _sprout-algorithm-tristate_lexicographical_compare:
|
||||
###############################################################################
|
||||
tristate_lexicographical_compare
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
inline SPROUT_CONSTEXPR int
|
||||
tristate_lexicographical_compare(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2
|
||||
);
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename Compare>
|
||||
inline SPROUT_CONSTEXPR int
|
||||
tristate_lexicographical_compare(
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Compare comp
|
||||
);
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| A value less than zero if the sequence of elements defined by the range [first1,last1) is lexicographically less than the sequence of elements defined by the range [first2,last2) and false otherwise.
|
||||
| A value greater than zero if the sequence of elements defined by the range [first1,last1) is lexicographically greater than the sequence of elements defined by the range [first2,last2) and false otherwise.
|
||||
| Otherwise, returns a zero value.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| If two sequences have the same number of elements and their corresponding elements are equivalent, then neither sequence is lexicographically less than the other.
|
||||
| If one sequence is a prefix of the other, then the shorter sequence is lexicographically less than the longer sequence.
|
||||
| Otherwise, the lexicographical comparison of the sequences yields the same result as the comparison of the first corresponding pair of elements that are not equivalent.
|
||||
|
||||
| An empty sequence is lexicographically less than any non-empty sequence, but not less than any empty sequence.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/tristate_lexicographical_compare.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
#include <sprout/container.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input1 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
|
||||
SPROUT_STATIC_CONSTEXPR auto input2 = array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 11, 12, 13}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::tristate_lexicographical_compare(begin(input1), end(input1), begin(input2), end(input2));
|
||||
static_assert(result < 0, "input1 < input2 by lexicographical comparison.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| At most ``2*min((last1 - first1), (last2 - first2)) + O(1)`` applications of the corresponding comparison.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/tristate_lexicographical_compare.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue