Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions reference/algorithm/minmax.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ namespace std {
- 2値比較バージョンは1操作。
- `initializer_list`バージョンは高々`(3/2) * t.size()`回の述語適用。

## 備考
- (1), (2) : 引数に右辺値を与えた場合、`minmax`の呼び出しを含む式の評価が終わった時点で、返された参照はダングリングすることに注意:
```cpp example
#include <cassert>
#include <algorithm>

int main()
{
int x = 10;
auto result1 = std::minmax(x, 11); // typeof(result1) == std::pair<const int&, const int&>
assert(result1.first == 10); // ok: result1.first は xを参照している
assert(result1.second == 11); // 不定: result1.secondは 消失した右辺値を参照している

std::pair<int, int> result2 = std::minmax(x, 11);
assert(result2.first == 10); // ok: result2.first は xのコピーを持っている
assert(result2.second == 11); // ok: result2.second は 右辺値11のコピーを持っている
}
```

## 例
```cpp example
Expand Down