我想在獲取表單型別串列的類中使用靜態方法std::tuple<T1, T2, T3,...>。而不是與std::tuple<...>我想擁有<...>. 如何實作示例struct x導致Ts == <T1, T2, T3,...>
template<template <typename...> typename TL, typename... Ts>
struct x {
static void test() {
// expecting Ts == <int, char, float, double> (without std::tuple<>)
std::cout << __PRETTY_FUNCTION__ << '\n';
}
};
using types = std::tuple<int, char, float, double>;
x<types>::test();
參見godbolt上的示例
uj5u.com熱心網友回復:
在我看來,您正在尋找模板專業化。
某事作為
// declaration (not definition) for a template struct x
// receiving a single template parameter
template <typename>
struct x;
// definition for a x specialization when the template
// parameter is in the form TL<Ts...>
template<template<typename...> typename TL, typename... Ts>
struct x<TL<Ts...>> {
static constexpr void test() {
// you can use Ts... (and also TL, if you want) here
std::cout << __PRETTY_FUNCTION__ << ' ' << sizeof...(Ts) << '\n';
}
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/470836.html
