template <class... Types> // Types is a template type parameter pack
class Tuple; // but not a pack expansion
template <class T, int... Dims> // Dims is a non-type template parameter pack
struct multi_array; // but not a pack expansion
template <class... T>
struct value_holder {
template <T... Values> struct apply { }; // Values is a non-type template parameter pack
}; // and a pack expansion
template <class... T, T... Values> // error: Values expands template type parameter
struct static_array; // pack T within the same template parameter list
-示例]
答案 1 :(得分:0)
在这种情况下,似乎无法推导模板参数。
您可能想尝试使用函数参数,似乎推导规则更容易处理。
类似这样,如果需要将输出作为类型,则可以将其包装在结构上:
#include <type_traits>
template<int x, int y, bool visible>
struct Point { };
template <typename T>
struct NoPoint { };
template <typename T>
constexpr auto Match(T &&)
{
return false;
}
template<template < auto ... > typename Head, auto ... Values>
constexpr auto Match(Head<Values...> &&)
{
return true;
}
static_assert(Match(Point<1, 2, true>{}), "I am a wombat.");
static_assert(Match(NoPoint<int>{}), "I am also a wombat.");
#include <type_traits>
#include <utility>
template<int x, int y, bool visible>
struct Point { };
template <typename T>
struct NoPoint { };
template <typename T>
constexpr auto Match(T) -> std::false_type;
template<template < auto ... > typename Head, auto ... Values>
constexpr auto Match(Head<Values...>) -> std::true_type;
template <typename T>
struct Predicate : decltype(Match(std::declval<T>())) {};
static_assert(Predicate<Point<1, 2, true>>::value, "I am a wombat.");
static_assert(Predicate<NoPoint<int>>::value, "I am not a wombat.");
//Test types
template<int x, int y, bool visible>
struct Point { };
template <typename T>
struct NoPoint { };
//Test Cases
static_assert(Predicate_v<Point<1, 2, true>>, "I am a wombat.");
static_assert(Predicate_v<NoPoint<int>>, "I am not a wombat.");