Skip to content

Instantly share code, notes, and snippets.

@DasNaCl
Created November 21, 2018 12:39
Show Gist options
  • Save DasNaCl/0a1fefa63d7beb45dd992b59a37f6b59 to your computer and use it in GitHub Desktop.
Save DasNaCl/0a1fefa63d7beb45dd992b59a37f6b59 to your computer and use it in GitHub Desktop.
#include <type_traits>
template<int> struct int_constant {};
template<char> struct char_constant {};
inline constexpr struct ubiq
{
template<class T>
constexpr operator T() const noexcept
{ return T{}; }
} ubiq_;
template<auto X, template<auto> class T>
auto match(T<X>) -> decltype(X);
template<template<auto> class Trait>
using nttp_t = decltype(match(Trait<ubiq_>{}));
static_assert(std::is_same_v<decltype(match(int_constant<42>{})), int>);
static_assert(std::is_same_v<nttp_t<int_constant>, int>);
static_assert(std::is_same_v<nttp_t<char_constant>, char>);
int main(){}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment