Skip to content

Commit 145bc7e

Browse files
committed
Add as(strict) casts
1 parent 2f5d328 commit 145bc7e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/cpp2util.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,22 @@ auto as(T&& t) -> auto
686686
return cpp2::optional_as<C>(std::forward<T>(t));
687687
}
688688

689+
template< typename T >
690+
struct strict {
691+
using type = T;
692+
};
693+
694+
template< typename S, typename T >
695+
auto as(T&& t) -> auto
696+
requires (
697+
requires {S::type;}
698+
&& std::is_same_v<cpp2::strict<typename S::type>,S>
699+
)
700+
{
701+
using C = typename S::type;
702+
return cpp2::strict_as<C>(std::forward<T>(t));
703+
}
704+
689705
//-------------------------------------------------------------------------------------------------------------
690706
// std::variant is and as
691707
//

0 commit comments

Comments
 (0)