Compiler which can compile c++17 lambda inheritance with parameter pack

爱⌒轻易说出口 提交于 2019-12-23 13:04:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!