Skip to content

Commit 0b892fe

Browse files
committed
optional_demo
1 parent 787b561 commit 0b892fe

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cpp/17.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,15 @@ void variant_demo()
537537
assert(visit(inc, (variant<int>)1) == 2);
538538
}
539539

540+
void optional_demo()
541+
{
542+
optional<int> i = make_optional(1);
543+
assert(i.has_value());
544+
assert(i.value() == 1);
545+
i = nullopt;
546+
assert(i.value_or(2) == 2);
547+
}
548+
540549
void clamp_demo()
541550
{
542551
static_assert(__cpp_lib_clamp);
@@ -601,6 +610,7 @@ int main()
601610
threads_17();
602611
map_demo();
603612
variant_demo();
613+
optional_demo();
604614
clamp_demo();
605615
dynamic_memory_17();
606616
string_view_demo();

0 commit comments

Comments
 (0)