c++ - CTAD 和带有参数包成员的模板构造函数
问题描述
尝试将通用引用与 CTAD 和参数包一起使用,我尝试了类似下面的方法,但它无法在 MinGW GCC 上编译。我不明白为什么。这是示例代码:
#include <utility>
template<typename... Ts>
struct Subtest
{
Subtest(Ts...) {}
};
template<typename... Ts>
struct Test
{
template<typename... Us>
Test( Us&&... values1 )
: values( std::forward<Us>( values1 )... )
{}
Subtest<Ts...> values;
};
template<typename... Ts>
Test(Ts&&...) -> Test<std::remove_reference_t<Ts>...>;
int main()
{
Test t(12, 14);
return 0;
}
这些是错误:
main.cpp: In instantiation of 'Test<Ts>::Test(Us&& ...) [with Us = {int, int}; Ts = {}]':
main.cpp:26:18: required from here
main.cpp:14:46: error: no matching function for call to 'Subtest<>::Subtest(int, int)'
14 | : values( std::forward<Us>( values1 )... )
| ^
main.cpp:6:5: note: candidate: 'Subtest<Ts>::Subtest(Ts ...) [with Ts = {}]'
6 | Subtest(Ts...) {}
| ^~~~~~~
main.cpp:6:5: note: candidate expects 0 arguments, 2 provided
main.cpp:4:8: note: candidate: 'constexpr Subtest<>::Subtest(const Subtest<>&)'
4 | struct Subtest
| ^~~~~~~
main.cpp:4:8: note: candidate expects 1 argument, 2 provided
main.cpp:4:8: note: candidate: 'constexpr Subtest<>::Subtest(Subtest<>&&)'
main.cpp:4:8: note: candidate expects 1 argument, 2 provided
解决方案
推荐阅读
- reactjs - 如何修复 TypeError:使用 react native/expo 时无法读取未定义的属性“状态”
- python - Python:如何保存不同长度的二维 numpy 数组列表
- swift - 努力使用 DispatchGroups 让多个异步调用正常工作
- angular - PrimeNG Treetable 以编程方式扩展所有不工作的节点
- typescript - RUC厄瓜多尔验证者
- numpy - 有没有更好的方法来调整 numpy 数组形式的图像的大小?
- arrays - 为什么我在 c 中分配 2048 * 2048 int 数组时出现分段错误
- c# - Visual Studio 上的鼠标交互
- python-3.x - python 3中pandas数据帧的自定义Scaler函数加倍长度(行)
- .net - BinarySearch 和 RegistryKey 的定义?