Created
April 27, 2020 10:50
-
-
Save Asher-/168b7c08c6328b95d054ad9365fa26d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
#include <assert.h> | |
template | |
< | |
typename Identifier | |
> | |
struct Leaf | |
{ | |
}; | |
template | |
< | |
typename... Identifiers | |
> | |
struct KV | |
: | |
Leaf<Identifiers>... | |
{ | |
template <typename Identifier> | |
using Type = Leaf<Identifier>; | |
template <typename Identifier> | |
static constexpr std::false_type includes(...); | |
template <typename Identifier, | |
typename=typename std::enable_if_t | |
<std::is_base_of_v<Type<Identifier>, KV>, | |
Type<Identifier>>> | |
static constexpr std::true_type includes(bool); | |
template <typename Identifier> | |
using Includes = decltype(includes<Identifier>(true)); | |
}; | |
/*************************************************/ | |
struct ID { | |
struct A {}; | |
struct B {}; | |
}; | |
using PackA = KV<ID::A>; | |
using PackB = KV<ID::B>; | |
int main() | |
{ | |
assert( PackA::template Includes<ID::A>::value ); | |
assert( ! PackA::template Includes<ID::B>::value ); | |
assert( PackB::template Includes<ID::B>::value ); | |
assert( ! PackB::template Includes<ID::A>::value ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment