[英]Error when passing template template parameter with dependent nested parameters types
為什么這個結構不起作用?
Visual Studio 顯示錯誤 C3201:類模板“AA”的模板參數列表與模板參數“C”的模板參數列表不匹配。 但在這兩種情況下它似乎都是<int, char, bool>
。
template<int I, char C, bool B>
struct AA
{
static const int i = I;
static const char c = C;
static const bool b = B;
};
template<typename... T>
struct outer
{
template <template<T... > typename C>
struct inner
{
template<T... X>
using type = C<X...>;
};
};
static_assert(outer<int, char, bool>::inner<AA>::type<5, 'a', true>::i == 5, "???");
添加:此外,編譯器無法推斷像這樣的專業化類型
template<class T, template<T> class C, T X>
struct A<C<X>> { ... };
標准是否禁止此類技巧,還是僅僅是編譯器限制?
我懷疑這是允許的,這只是編譯器搞砸了。 當我嘗試使用它來獲得解決方法時,我遇到了很多內部編譯器錯誤; 這通常表明它沒有被故意拒絕,而且錯誤消息毫無意義。
在c++20 中,我可以生成此解決方法。
template<int I, char C, bool B>
struct AA
{
static const int i = I;
static const char c = C;
static const bool b = B;
};
template<template<auto... > typename C, typename... Ts>
struct outer_base
{
struct inner
{
template<Ts... X>
using type = C<X...>;
};
};
template<typename... Ts>
struct outer
{
template <template<auto... > typename C>
using inner = typename outer_base<C, Ts...>::inner;
};
static_assert(outer<int, char, bool>::inner<AA>::type<5, 'a', true>::i == 5, "???");
這比您可能喜歡的要少一些,因為它不需要C
來匹配類型Ts...
確切地說,只需與它們兼容即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.