mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-04 14:14:09 +00:00
add doc: min, max, minmax
This commit is contained in:
parent
22cff01bf8
commit
e036b54fcb
15 changed files with 1211 additions and 5 deletions
|
@ -39,6 +39,9 @@ Sprout.Algorithm
|
|||
binary_search
|
||||
is_heap
|
||||
is_heap_until
|
||||
min
|
||||
max
|
||||
minmax
|
||||
|
||||
.. _sprout-algorithm-non_modifying:
|
||||
*******************************************************************************
|
||||
|
|
85
source/libs/sprout/algorithm/max.rst
Normal file
85
source/libs/sprout/algorithm/max.rst
Normal file
|
@ -0,0 +1,85 @@
|
|||
.. _sprout-algorithm-max:
|
||||
###############################################################################
|
||||
max
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T const&
|
||||
max(T const& a, T const& b);
|
||||
|
||||
template<typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR T const&
|
||||
max(T const& a, T const& b, Compare comp);
|
||||
|
||||
Requires
|
||||
========================================
|
||||
|
||||
| Type T is LessThanComparable.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The larger value.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| Returns the first argument when the arguments are equivalent.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/max.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{-1, 1}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::max(input[0], input[1]);
|
||||
static_assert(result == 1, "max value is 1.");
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
max(std::initializer_list<T> t, Compare comp);
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
max(std::initializer_list<T> t);
|
||||
|
||||
Requires
|
||||
========================================
|
||||
|
||||
| T is LessThanComparable and CopyConstructible and ``t.size() > 0``.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The largest value in the initializer_list.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| Returns a copy of the leftmost argument when several arguments are equivalent to the largest.
|
||||
| If an implementation not support C++14 initializer_list (SPROUT_NO_CXX14_INITIALIZER_LIST defined), then this function is not specified constexpr.
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/max.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
85
source/libs/sprout/algorithm/min.rst
Normal file
85
source/libs/sprout/algorithm/min.rst
Normal file
|
@ -0,0 +1,85 @@
|
|||
.. _sprout-algorithm-min:
|
||||
###############################################################################
|
||||
min
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T const&
|
||||
min(T const& a, T const& b);
|
||||
|
||||
template<typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR T const&
|
||||
min(T const& a, T const& b, Compare comp);
|
||||
|
||||
Requires
|
||||
========================================
|
||||
|
||||
| Type T is LessThanComparable.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The smaller value.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| Returns the first argument when the arguments are equivalent.
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/min.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{-1, 1}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::min(input[0], input[1]);
|
||||
static_assert(result == -1, "min value is -1.");
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
min(std::initializer_list<T> t, Compare comp);
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
min(std::initializer_list<T> t);
|
||||
|
||||
Requires
|
||||
========================================
|
||||
|
||||
| T is LessThanComparable and CopyConstructible and ``t.size() > 0``.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| The smallest value in the initializer_list.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| Returns a copy of the leftmost argument when several arguments are equivalent to the smallest.
|
||||
| If an implementation not support C++14 initializer_list (SPROUT_NO_CXX14_INITIALIZER_LIST defined), then this function is not specified constexpr.
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/min.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
96
source/libs/sprout/algorithm/minmax.rst
Normal file
96
source/libs/sprout/algorithm/minmax.rst
Normal file
|
@ -0,0 +1,96 @@
|
|||
.. _sprout-algorithm-minmax:
|
||||
###############################################################################
|
||||
minmax
|
||||
###############################################################################
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T const&, T const&>
|
||||
minmax(T const& a, T const& b);
|
||||
|
||||
template<typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T const&, T const&>
|
||||
minmax(T const& a, T const& b, Compare comp);
|
||||
|
||||
Requires
|
||||
========================================
|
||||
|
||||
| Type T shall be LessThanComparable.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| ``pair<T, T>(x, y)``, where x has the smallest and y has the largest value in the initializer list.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| Returns ``pair<const T&, const T&>(a, b)`` when the arguments are equivalent.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
Examples
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
#include <sprout/algorithm/minmax.hpp>
|
||||
#include <sprout/array.hpp>
|
||||
using namespace sprout;
|
||||
|
||||
SPROUT_STATIC_CONSTEXPR auto input = array<int, 10>{{-1, 1}};
|
||||
SPROUT_STATIC_CONSTEXPR auto result = sprout::minmax(input[0], input[1]);
|
||||
static_assert(result.first == -1, "min value is -1.");
|
||||
static_assert(result.second == 1, "max value is 1.");
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| Exactly one comparison.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Interface
|
||||
========================================
|
||||
.. sourcecode:: c++
|
||||
|
||||
template<typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T, T>
|
||||
minmax(std::initializer_list<T> t, Compare comp);
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T, T>
|
||||
minmax(std::initializer_list<T> t);
|
||||
|
||||
Requires
|
||||
========================================
|
||||
|
||||
| T is LessThanComparable and CopyConstructible and ``t.size() > 0``.
|
||||
|
||||
Returns
|
||||
========================================
|
||||
|
||||
| ``pair<T, T>(x, y)``, where x has the smallest and y has the largest value in the initializer list.
|
||||
|
||||
Remarks
|
||||
========================================
|
||||
|
||||
| x is a copy of the leftmost argument when several arguments are equivalent to the smallest.
|
||||
| y is a copy of the rightmost argument when several arguments are equivalent to the largest.
|
||||
| If an implementation not support C++14 initializer_list (SPROUT_NO_CXX14_INITIALIZER_LIST defined), then this function is not specified constexpr.
|
||||
|
||||
Complexity
|
||||
========================================
|
||||
|
||||
| At most ``(3/2) * t.size()`` applications of the corresponding predicate.
|
||||
| Recursive function invocations in *O(logN)* (logarithmic) depth.
|
||||
|
||||
Header
|
||||
========================================
|
||||
|
||||
| ``sprout/algorithm/minmax.hpp``
|
||||
| Convenience header: ``sprout/algorithm.hpp``
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue