1

シンプルで効率的な SFINAE 選択decltypeを使用することは (少なくとも私のコードでは) 非常に一般的です。std::enable_if_t次のようなもの:

template <typename A1, typename A2, typename... Auts>
inline
auto
infiltration(const A1& a1, const A2& a2, const Auts&... as)
  -> decltype(std::enable_if_t<sizeof...(Auts) != 0>{},
              infiltration(infiltration(a1, a2), as...))
{
  return infiltration(infiltration(a1, a2), as...);
}

ただし、何らかの理由で有効ではないため (少なくとも Clang と GCC では)、これをvoid{}書くことはできません。()std::enable_if_t

$ cat foo.cc
    auto foo() -> decltype(void()) {}
    auto bar() -> decltype(void{}) {}

    int main()
    {
      foo();
      bar();
    }
$ clang++-mp-3.6 -std=c++14 foo.cc
foo.cc:2:32: error: illegal initializer type 'void'
    auto bar() -> decltype(void{}) {}
                               ^
1 error generated.
$ clang++-mp-3.7 -std=c++14 foo.cc
foo.cc:2:32: error: illegal initializer type 'void'
    auto bar() -> decltype(void{}) {}
                               ^
1 error generated.
$ g++-mp-5 -std=c++14 foo.cc
foo.cc:2:33: error: compound literal of non-object type 'void'
     auto bar() -> decltype(void{}) {}
                                 ^
foo.cc:2:33: error: compound literal of non-object type 'void'
foo.cc: In function 'int main()':
foo.cc:7:11: error: 'bar' was not declared in this scope
       bar();
           ^

何故ですか?

4

0 に答える 0