From Jason Turner

[alg.clamp]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpod65x893/{from.md → to.md} +14 -6
tmp/tmpod65x893/{from.md → to.md} RENAMED
@@ -3,19 +3,27 @@
3
  ``` cpp
4
  template<class T>
5
  constexpr const T& clamp(const T& v, const T& lo, const T& hi);
6
  template<class T, class Compare>
7
  constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
 
 
 
 
8
  ```
9
 
10
- *Requires:* The value of `lo` shall be no greater than `hi`. For the
11
- first form, type `T` shall be `LessThanComparable`
12
- (Table  [[tab:lessthancomparable]]).
13
 
14
- *Returns:* `lo` if `v` is less than `lo`, `hi` if `hi` is less than `v`,
15
- otherwise `v`.
 
 
 
 
16
 
17
  [*Note 1*: If NaN is avoided, `T` can be a floating-point
18
  type. — *end note*]
19
 
20
- *Complexity:* At most two comparisons.
 
21
 
 
3
  ``` cpp
4
  template<class T>
5
  constexpr const T& clamp(const T& v, const T& lo, const T& hi);
6
  template<class T, class Compare>
7
  constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);
8
+ template<class T, class Proj = identity,
9
+ indirect_strict_weak_order<projected<const T*, Proj>> Comp = ranges::less>
10
+ constexpr const T&
11
+ ranges::clamp(const T& v, const T& lo, const T& hi, Comp comp = {}, Proj proj = {});
12
  ```
13
 
14
+ Let `comp` be `less{}` for the overloads with no parameter `comp`, and
15
+ let `proj` be `identity{}` for the overloads with no parameter `proj`.
 
16
 
17
+ *Preconditions:* `bool(comp(proj(hi), proj(lo)))` is `false`. For the
18
+ first form, type `T` meets the *Cpp17LessThanComparable* requirements
19
+ ([[cpp17.lessthancomparable]]).
20
+
21
+ *Returns:* `lo` if `bool(comp(proj(v), proj(lo)))` is `true`, `hi` if
22
+ `bool(comp(proj(hi), proj(v)))` is `true`, otherwise `v`.
23
 
24
  [*Note 1*: If NaN is avoided, `T` can be a floating-point
25
  type. — *end note*]
26
 
27
+ *Complexity:* At most two comparisons and three applications of the
28
+ projection.
29