Skip to content

Commit 2f5d328

Browse files
committed
Add as() functions to std::optional
1 parent 1d6e7d0 commit 2f5d328

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

include/cpp2util.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,17 @@ auto optional_as(T&& t) -> auto {
675675
}
676676
}
677677

678+
template< typename O, typename T >
679+
auto as(T&& t) -> auto
680+
requires (
681+
requires {O::value_type;}
682+
&& std::is_same_v<std::optional<typename O::value_type>,O>
683+
)
684+
{
685+
using C = typename O::value_type;
686+
return cpp2::optional_as<C>(std::forward<T>(t));
687+
}
688+
678689
//-------------------------------------------------------------------------------------------------------------
679690
// std::variant is and as
680691
//

0 commit comments

Comments
 (0)