Skip to content

Commit

Permalink
add trait.hpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertshepherdcpp committed Feb 26, 2023
1 parent 3099e01 commit b0b3a5b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions mlib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<ClInclude Include="select.hpp" />
<ClInclude Include="string_manip.hpp" />
<ClInclude Include="times.hpp" />
<ClInclude Include="trait.hpp" />
<ClInclude Include="transform.hpp" />
<ClInclude Include="tuple.hpp" />
<ClInclude Include="tuple_inheritance.hpp" />
Expand Down
3 changes: 3 additions & 0 deletions mlib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<ClInclude Include="times.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="trait.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
Expand Down
26 changes: 26 additions & 0 deletions trait.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
// only works on Clang and MSVC, not GCC

namespace mlib
{
template<auto T>
struct trait_module
{
constexpr auto operator()(auto X) const
{
// we call our NTTP
T(X);
return true;
}
};


template<auto T, auto... trait_modules>
requires((trait_modules(T), ...))
struct trait
{
constexpr trait() {}

static constexpr auto value = true;
};
} // namespace mlib

0 comments on commit b0b3a5b

Please sign in to comment.