A compiler that can compile C ++ 17 lambda inheritance with a parameter package

I read about using function declarations , and I wanted to compile the last example. It:

#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 he will do, I would like to compile and test it. However, neither clang-4.0 nor g ++ - 7.0 seem to be able to compile it at the moment. Is there any place with any compiler, could I try it?

+4
source share
1 answer

P0195 , a proposed language extension that allows:

template <typename... Ts>
struct Overloader : Ts... {
    using Ts::operator()...; // <== ill-formed without p0195
};

++ Issaquah ( 2016 ). , gcc clang . .

Overloader.

+2

Source: https://habr.com/ru/post/1662890/


All Articles