是否可以编写一个类型特征来检查一个类型是否是带有附加项的特定类型?

Is it possible to write a type trait that checks if a type is a specific type with an addition?

我有一个类型:

struct A {}

template<typename T>
constexpr bool is_A_v = false;

template<>
constexpr bool is_A_v<A> = true; // here I don't know how to apply std::remove_cvref_t<?> before checking?

我是 trait 类型的新手,非常感谢您的帮助。

根据评论,您正在寻找:

template <typename T>
inline constexpr bool is_A = std::is_same_v<std::remove_cvref_t<T>, A>;

在 C++20 中,您可以将其拼写为一个概念:

template <typename T>
concept is_A = std::same_as<std::remove_cvref_t<T>, A>;

它有一些轻微的句法优势,但也阻止人们在事后专门化特征。