c++ - 获取 Boost Proto 子表达式的标签类型

标签 c++ boost typetraits boost-proto

在 Boost Proto 表达式中,我什么时候不应该期待 proto_tag 成员?例如,我可以使用以下任一方法查询占位符的标记类型:

typedef proto::tag_of<decltype(_1)>::type ta;
typedef decltype(_1)::proto_tag           tb;

但是如果我询问表达式的 child 的标签类型,似乎没有 proto_tag 成员;而下面代码第三行报错:

auto f = _1 + _2;
typedef proto::tag_of<decltype(proto::child_c<0>(f))>::type tc;
typedef decltype(proto::child_c<0>(f))::proto_tag           td; // error

Clang 和 GCC 的错误报告有问题的类型:不是类、命名空间或作用域枚举。我使用 Clang 3.2、GCC 4.7.2 和 Boost 1.53。

最佳答案

g++ 4.8.0 给出的错误基本上是:

decltype evaluates to phx::actor<proto::expression>&, which is not a class or enumeration type

为了使用::你需要有一个不合格的类型,所以你必须删除引用:

#include <type_traits>
typedef std::remove_reference<decltype(proto::child_c<0>(f))>::type::proto_tag td;

我相信你也可以使用:

typedef proto::result_of::child_c<decltype(f),0>::type::proto_tag td;

使用 proto::tag_of您无需担心可能的引用,因为它会在必要时被删除:

template<typename Expr>
struct tag_of
{
    typedef typename Expr::proto_tag type;
};

template<typename Expr>
struct tag_of<Expr &>
{
    typedef typename Expr::proto_tag type;
};

关于c++ - 获取 Boost Proto 子表达式的标签类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16619048/

相关文章:

c++ - Qt:如何在模型/ View 设置中同步访问来自多个线程的数据?

c++ - 变量隐藏在 Boost Phoenix 的嵌套 let block 中

c++ - 无法将变量参数传递给嵌套可变参数模板调用

c++ - 如何使用 Boost Filesystem 忽略隐藏文件(和隐藏目录中的文件)?

c++ - boost 文本反序列化在 32 位 Windows 机器上崩溃

用于 boost/c++11 的 C++ 包装器

c++ - 检测结构是否有填充

c++ - 使用 enable_if 隐藏函数定义

c++ - 将粒子位置(glm vec3s)顶点传递给顶点缓冲区对象

c++ - 将 std::type_identity 对象转换为类型