我了解了使用函数声明,我想编译最后一个例子。这是:
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继承的编译器
发布评论