Skip to content

Commit c6dc531

Browse files
committed
Type: LazyEvaluation
1 parent a3268d6 commit c6dc531

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

modules/Type/Type.mpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export import CppUtils.Type.Enum;
66
export import CppUtils.Type.Mapping;
77
export import CppUtils.Type.MemberFunction;
88
export import CppUtils.Type.Tuple;
9+
export import CppUtils.Type.Utility;
910
export import CppUtils.Type.VariadicTemplate;
1011
export import CppUtils.Type.Variant;

modules/Type/Utility.mpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export module CppUtils.Type.Utility;
2+
3+
import std;
4+
5+
export namespace CppUtils::Type
6+
{
7+
template<bool, template<class> class Then, class Arg, class Else>
8+
struct LazyEvaluation
9+
{
10+
using type = Else;
11+
};
12+
13+
template<template<class> class Then, class Arg, class Else>
14+
struct LazyEvaluation<true, Then, Arg, Else>
15+
{
16+
using type = Then<Arg>;
17+
};
18+
19+
template<bool Condition, template<class> class Then, class Arg, class Else>
20+
using LazyEvaluationType = typename LazyEvaluation<Condition, Then, Arg, Else>::type;
21+
22+
static_assert(std::is_same_v<LazyEvaluationType<true, std::type_identity, int, char>, std::type_identity<int>>);
23+
static_assert(std::is_same_v<LazyEvaluationType<false, std::type_identity, int, char>, char>);
24+
}

0 commit comments

Comments
 (0)