如何解决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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。