问题
I read about the using function declaration and I wanted to compile the last example. This is :
#include <iostream>
template <typename... Ts>
struct Overloader : Ts... {
using Ts::operator()...; // exposes operator() from every base
};
template <typename... T>
constexpr auto make_overloader(T&&... t) {
return Overloader<T...>{std::forward<T>(t)...};
}
int main() {
auto o = make_overloader([] (auto const& a) {std::cout << a;},
[] (float f) {std::cout << 13 << f;});
}
Even if I already know and understand what it will do, I would like to compile and test it. However, neither clang-4.0 and g++-7.0 seems to be able to compile it at the moment. Is there any place with any compiler I could try it ?
回答1:
P0195, the proposed language extension that allows for:
template <typename... Ts>
struct Overloader : Ts... {
using Ts::operator()...; // <== ill-formed without p0195
};
was only accepted into C++ in Issaquah a few weeks ago (November 2016). It's not surprising that gcc or clang haven't implemented it yet. Give them time.
The workaround for now is to create a linear hierarchy for Overloader
instead.
来源:https://stackoverflow.com/questions/40983367/compiler-which-can-compile-c17-lambda-inheritance-with-parameter-pack