-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrange_loop.cpp
31 lines (25 loc) · 1006 Bytes
/
range_loop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// examples/range_loop.cpp -*-C++-*-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <beman/optional26/optional.hpp>
#include <iostream>
int main() {
// Example from P3168R2: basic range loop over C++26 optional.
beman::optional26::optional<int> empty_opt{};
for ([[maybe_unused]] const auto& i : empty_opt) {
// Should not see this in console.
std::cout << "\"for each loop\" over C++26 optional: empty_opt\n";
}
beman::optional26::optional<int> opt{26};
for (const auto& i : opt) {
// Should see this in console.
std::cout << "\"for each loop\" over C++26 optional: opt = " << i << "\n";
}
return 0;
}
// # build example:
// $ cmake --workflow --preset gcc-14
//
// # run example:
// $ .build/gcc-14/examples/RelWithDebInfo/range_loop
// # note: 1st log (empty_opt) is missing from console!
// "for each loop" over C++26 optional: opt = 26 # 2nd log (non empty opt)