Created
April 17, 2019 22:28
-
-
Save kim366/31088db800493ef11a2d067220bb0f9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <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