バリデーションテンプレートで非常に奇妙な問題が発生しました。間違ったパックが展開されているようです。ここでは、コードスニペットです:バリデーションテンプレートで間違ったパックが展開されました
#include <tuple>
template<typename...>
struct types {};
template<typename = types<>>
struct Base;
template<typename... Args1>
struct Base<types<Args1...>> {
template<typename... Args2>
static auto construct(Args1... args1, Args2&&... args2)
-> decltype(std::make_tuple(args1.forward()..., std::declval<Args2>()...))
{
return std::make_tuple(args1.forward()..., std::forward<Args2>(args2)...);
}
};
struct Derived : Base<> {};
int main() {
auto test = &Derived::construct<char const(&)[7]>;
}
私はこのエラーを取得する:
13 : <source>:13:43: error: request for member 'forward' in 'args2#0', which is of non-class type 'const char [7]'
-> decltype(std::make_tuple(args1.forward()..., std::declval<Args2>()...))
~~~~~~^~~~~~~
13 : <source>:13:43: error: request for member 'forward' in 'args2#0', which is of non-class type 'const char [7]'
<source>: In function 'int main()':
22 : <source>:22:27: error: unable to deduce 'auto' from '& construct<const char (&)[7]>'
auto test = &Derived::construct<char const(&)[7]>;
^~~~~~~~~~~~~~~~~~~~~~~~~~~
22 : <source>:22:27: note: could not resolve address from overloaded function '& construct<const char (&)[7]>'
Compiler exited with result code 1
パックはそれに値を持っているときしかし、それは起こりません。
struct HasForward { int forward() { return 0; } };
struct Derived : Base<types<HasForward>> {};
はここFirst snippet liveですおよびSecond snippet live
このコードで何が問題になっていますか?これはコンパイラのバグですか?それを克服し、最初のパックを空のままにする方法はありますか?
マイ打ち鳴らす++問題なくコンパイル。私はそれがg ++バグだと思う。 – max66