From Jason Turner

[string.compare]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp3zhxwvo7/{from.md → to.md} +40 -34
tmp/tmp3zhxwvo7/{from.md → to.md} RENAMED
@@ -1,95 +1,101 @@
1
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
2
 
3
  ``` cpp
4
- int compare(basic_string_view<charT, traits> sv) const noexcept;
 
5
  ```
6
 
7
- *Effects:* Determines the effective length `rlen` of the strings to
8
- compare as the smaller of `size()` and `sv.size()`. The function then
9
- compares the two strings by calling
10
- `traits::compare(data(), sv.data(), rlen)`.
11
 
12
- *Returns:* The nonzero result if the result of the comparison is
13
- nonzero. Otherwise, returns a value as indicated in
14
- Table  [[tab:strings.compare]].
15
 
16
- **Table: `compare()` results** <a id="tab:strings.compare">[tab:strings.compare]</a>
 
17
 
18
- | Condition | Return Value |
19
- | --------------------- | ------------ |
20
- | `size() < sv.size()` | `< 0` |
21
- | `size() == sv.size()` | ` 0` |
22
- | `size() > sv.size()` | `> 0` |
23
 
24
  ``` cpp
25
- int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
 
26
  ```
27
 
 
 
 
 
 
 
28
  *Effects:* Equivalent to:
29
 
30
  ``` cpp
31
- return basic_string_view<charT, traits>(data(), size()).substr(pos1, n1).compare(sv);
32
  ```
33
 
34
  ``` cpp
35
  template<class T>
36
- int compare(size_type pos1, size_type n1, const T& t,
37
  size_type pos2, size_type n2 = npos) const;
38
  ```
39
 
 
 
 
 
 
 
40
  *Effects:* Equivalent to:
41
 
42
  ``` cpp
43
- basic_string_view<charT, traits> sv = t;
44
- return basic_string_view<charT, traits>(
45
- data(), size()).substr(pos1, n1).compare(sv.substr(pos2, n2));
46
  ```
47
 
48
- *Remarks:* This function shall not participate in overload resolution
49
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
50
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
51
-
52
  ``` cpp
53
- int compare(const basic_string& str) const noexcept;
54
  ```
55
 
56
  *Effects:* Equivalent to:
57
  `return compare(basic_string_view<charT, traits>(str));`
58
 
59
  ``` cpp
60
- int compare(size_type pos1, size_type n1, const basic_string& str) const;
61
  ```
62
 
63
  *Effects:* Equivalent to:
64
  `return compare(pos1, n1, basic_string_view<charT, traits>(str));`
65
 
66
  ``` cpp
67
- int compare(size_type pos1, size_type n1,
68
- const basic_string& str,
69
  size_type pos2, size_type n2 = npos) const;
70
  ```
71
 
72
  *Effects:* Equivalent to:
73
 
74
  ``` cpp
75
  return compare(pos1, n1, basic_string_view<charT, traits>(str), pos2, n2);
76
  ```
77
 
78
  ``` cpp
79
- int compare(const charT* s) const;
80
  ```
81
 
82
- *Returns:* `compare(basic_string(s))`.
 
83
 
84
  ``` cpp
85
- int compare(size_type pos, size_type n1, const charT* s) const;
86
  ```
87
 
88
- *Returns:* `basic_string(*this, pos, n1).compare(basic_string(s))`.
 
89
 
90
  ``` cpp
91
- int compare(size_type pos, size_type n1, const charT* s, size_type n2) const;
92
  ```
93
 
94
- *Returns:* `basic_string(*this, pos, n1).compare(basic_string(s, n2))`.
 
95
 
 
1
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
2
 
3
  ``` cpp
4
+ template<class T>
5
+ constexpr int compare(const T& t) const noexcept(see below);
6
  ```
7
 
8
+ *Constraints:*
 
 
 
9
 
10
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
11
+ `true` and
12
+ - `is_convertible_v<const T&, const charT*>` is `false`.
13
 
14
+ *Effects:* Equivalent to:
15
+ `return basic_string_view<charT, traits>(*this).compare(t);`
16
 
17
+ *Remarks:* The expression inside `noexcept` is equivalent to
18
+ `is_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>`.
 
 
 
19
 
20
  ``` cpp
21
+ template<class T>
22
+ constexpr int compare(size_type pos1, size_type n1, const T& t) const;
23
  ```
24
 
25
+ *Constraints:*
26
+
27
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
28
+ `true` and
29
+ - `is_convertible_v<const T&, const charT*>` is `false`.
30
+
31
  *Effects:* Equivalent to:
32
 
33
  ``` cpp
34
+ return basic_string_view<charT, traits>(*this).substr(pos1, n1).compare(t);
35
  ```
36
 
37
  ``` cpp
38
  template<class T>
39
+ constexpr int compare(size_type pos1, size_type n1, const T& t,
40
  size_type pos2, size_type n2 = npos) const;
41
  ```
42
 
43
+ *Constraints:*
44
+
45
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
46
+ `true` and
47
+ - `is_convertible_v<const T&, const charT*>` is `false`.
48
+
49
  *Effects:* Equivalent to:
50
 
51
  ``` cpp
52
+ basic_string_view<charT, traits> s = *this, sv = t;
53
+ return s.substr(pos1, n1).compare(sv.substr(pos2, n2));
 
54
  ```
55
 
 
 
 
 
56
  ``` cpp
57
+ constexpr int compare(const basic_string& str) const noexcept;
58
  ```
59
 
60
  *Effects:* Equivalent to:
61
  `return compare(basic_string_view<charT, traits>(str));`
62
 
63
  ``` cpp
64
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const;
65
  ```
66
 
67
  *Effects:* Equivalent to:
68
  `return compare(pos1, n1, basic_string_view<charT, traits>(str));`
69
 
70
  ``` cpp
71
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str,
 
72
  size_type pos2, size_type n2 = npos) const;
73
  ```
74
 
75
  *Effects:* Equivalent to:
76
 
77
  ``` cpp
78
  return compare(pos1, n1, basic_string_view<charT, traits>(str), pos2, n2);
79
  ```
80
 
81
  ``` cpp
82
+ constexpr int compare(const charT* s) const;
83
  ```
84
 
85
+ *Effects:* Equivalent to:
86
+ `return compare(basic_string_view<charT, traits>(s));`
87
 
88
  ``` cpp
89
+ constexpr int compare(size_type pos, size_type n1, const charT* s) const;
90
  ```
91
 
92
+ *Effects:* Equivalent to:
93
+ `return compare(pos, n1, basic_string_view<charT, traits>(s));`
94
 
95
  ``` cpp
96
+ constexpr int compare(size_type pos, size_type n1, const charT* s, size_type n2) const;
97
  ```
98
 
99
+ *Effects:* Equivalent to:
100
+ `return compare(pos, n1, basic_string_view<charT, traits>(s, n2));`
101