可以使用参数包编译c ++ 17 lambda继承的编译器

编程入门 行业动态 更新时间:2024-10-15 20:19:50
本文介绍了可以使用参数包编译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继承的编译器

本文发布于:2023-11-13 22:31:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585503.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编译器   可以使用   参数   lambda

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!