Skip to content

Commit b0b3a5b

Browse files
add trait.hpp.
1 parent 3099e01 commit b0b3a5b

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

mlib.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<ClInclude Include="select.hpp" />
161161
<ClInclude Include="string_manip.hpp" />
162162
<ClInclude Include="times.hpp" />
163+
<ClInclude Include="trait.hpp" />
163164
<ClInclude Include="transform.hpp" />
164165
<ClInclude Include="tuple.hpp" />
165166
<ClInclude Include="tuple_inheritance.hpp" />

mlib.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
<ClInclude Include="times.hpp">
124124
<Filter>Header Files</Filter>
125125
</ClInclude>
126+
<ClInclude Include="trait.hpp">
127+
<Filter>Header Files</Filter>
128+
</ClInclude>
126129
</ItemGroup>
127130
<ItemGroup>
128131
<ClCompile Include="Main.cpp">

trait.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
// only works on Clang and MSVC, not GCC
3+
4+
namespace mlib
5+
{
6+
template<auto T>
7+
struct trait_module
8+
{
9+
constexpr auto operator()(auto X) const
10+
{
11+
// we call our NTTP
12+
T(X);
13+
return true;
14+
}
15+
};
16+
17+
18+
template<auto T, auto... trait_modules>
19+
requires((trait_modules(T), ...))
20+
struct trait
21+
{
22+
constexpr trait() {}
23+
24+
static constexpr auto value = true;
25+
};
26+
} // namespace mlib

0 commit comments

Comments
 (0)