Reputation: 9
I could get the following code (also found in cppreference http://en.cppreference.com/w/cpp/utility/variant/visit) to compile (https://wandbox.org/permlink/stCFKi0VQlF49Bxr)
#include <type_traits>
#include <utility>
template <typename... Types>
struct Overload : public Types... {
using Types::operator()...;
};
template <typename... Types>
auto make_overload(Types&&... instances) {
return Overload<std::decay_t<Types>...>{std::forward<Types>(instances)...};
}
int main() {
auto overloaded = make_overload([](int) {}, [](double) {});
static_cast<void>(overloaded);
}
How does the code above compile in C++17? It does not compile in C++14. What is happening behind the scenes? Also why does the variadic using
declaration not work in C++14? Which new feature is this?
Upvotes: 0
Views: 66
Reputation: 218323
As you can read in parameter_pack,
Introduced in C++17
The following is the list of all allowed contexts: [...]
Using-declarations
In using declaration, ellipsis may appear in the list of declarators, this is useful when deriving from a parameter pack:
template <typename... bases>
struct X : bases... {
using bases::g...;
};
X<B, D> x; // OK: B::g and D::g introduced
Upvotes: 1