可以使用参数包编译c ++ 17 lambda继承的编译器 [英] Compiler which can compile c++17 lambda inheritance with parameter pack

查看:84
本文介绍了可以使用参数包编译c ++ 17 lambda继承的编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解了使用函数声明,我想编译最后一个例子。这是:

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;});
}

即使我已经知道并理解它会做什么,我也想编译并测试它。
但是,目前clang-4.0和g ++-7.0似乎都无法对其进行编译。我可以尝试使用任何编译器吗?

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 ?

推荐答案

P0195 ,该语言扩展名允许:

P0195, the proposed language extension that allows for:

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

几周前(2016年11月)才在Issaquah被C ++接受。 gcc或clang尚未实现它也就不足为奇了。给他们时间。

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.

目前的解决方法是为 Overloader 创建线性层次结构。

The workaround for now is to create a linear hierarchy for Overloader instead.

这篇关于可以使用参数包编译c ++ 17 lambda继承的编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆