Skip to content

Instantly share code, notes, and snippets.

@kim366
Created April 17, 2019 22:28
Show Gist options
  • Save kim366/31088db800493ef11a2d067220bb0f9a to your computer and use it in GitHub Desktop.
Save kim366/31088db800493ef11a2d067220bb0f9a to your computer and use it in GitHub Desktop.
#include <utility>
template<typename T>
struct sample_templated
{
T x;
int y;
};
using instanciated = sample_templated<double>;
template<template<typename...> typename T>
struct types_match_impl
{
template<typename... ArgTs>
static std::true_type match(T<ArgTs...>);
template<typename O>
static std::false_type match(O);
};
template<template<typename...> typename T, typename O>
struct types_match
{
constexpr static bool value = decltype(types_match_impl<T>::match(std::declval<O>()))::value;
};
template<template<typename...> typename T, typename O>
constexpr bool types_match_v = types_match<T, O>::value;
int main()
{
static_assert(types_match_v<sample_templated, instanciated>);
static_assert(!types_match_v<sample_templated, int>);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment