I was watching this video on a topic about C++17's Variadic using
. So out of curiosity I tried this code snippet here exactly as is within my own IDE MS Visual Studio 2017 CE
with compiler language settings to c++17
.
#include <iostream>
#include <utility>
template<typename ... B>
struct Merged : B... {
template<typename ... T>
Merged( T && ... t ) : B( std::forward<T>( t ) )... {
}
using B::operator()...;
};
template<typename ... T>
Merged( T... ) -> Merged<std::decay_t<T>...>;
int main() {
const auto l1 = []() { return 4; };
const auto l2 = []( const int i ) { return i * 10; };
Merged merged( l1, l2, []( const double d ) { return d * 3.2; } );
std::cout << merged() << "\n";
std::cout << merged( 5 ) << "\n";
std::cout << merged( 4.5 ) << "\n";
return 0;
}
Of course it fails to compile. So I then ventured to websites with built in compilers. I tried using Compiler Explorer and I used a majority of the compiler versions available on that website setting the appropriate compiler options for c++17
. They all failed to compile. I eventually tried WandBox
and it only seems to compile for Clang
versions 5.0 and higher. None of the GCC
compilers would compile it from either Compiler Explorer
or WandBox
, and the only compilers that would compile and run it as is are the Clang
compilers at WandBox
.
I'm not interested in actually trying to make this work; I was just curious or interested in the subject of the video itself. When I tried to implement the code it became vary curious and apparent on how much of a variation there is from one compiler of the C++ language to another.
Why does it appear in this specific case that Clang's
versions 5.0+ are the only ones to fully support this feature of the C++17
language with the syntax currently being the way it is?