Skip to content

Instantly share code, notes, and snippets.

@Asher-
Created April 27, 2020 10:50
Show Gist options
  • Save Asher-/168b7c08c6328b95d054ad9365fa26d1 to your computer and use it in GitHub Desktop.
Save Asher-/168b7c08c6328b95d054ad9365fa26d1 to your computer and use it in GitHub Desktop.
#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