c++ - 返回类型很长的表达式

标签 c++ c++11 return-type

我有以下功能:

inline auto iterateSomething(obj & o)
{
    auto iterators = baseIterator(o);
    auto tranformer = boost::bind(transofrmToSomething, _1, o);
    typedef boost::transform_iterator<decltype(tranformer), decltype(iterators.first)> iterator_t;
    iterator_t begin(iterators.first, tranformer);
    iterator_t end(iterators.second, tranformer);
    return std::make_pair(begin, end);
}

如您所见,我不知道返回值,即使我将 int 放在那里然后从错误消息中复制类型,它也是一个非常长的类型...
有没有办法将返回类型指定为函数中唯一返回的类型?是否有任何解决方法不涉及返回类型中的巨大类型?

最佳答案

我认为你应该按照 Raymond Chen 在评论中的建议去做:

Move the typedefs outside the function. Then you can use it to declare the return type.

如果 Raymond 发布了一个答案,那么应该优先接受它而不是我的——我发布这个是为了让 bitmask 的答案不是唯一的,因为我认为它是一种比疾病更糟糕的治疗方法。

关于c++ - 返回类型很长的表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9851236/

相关文章:

c++ - 带有 protected 字段的微妙 C++ 继承错误

c++ - 将 std::function 绑定(bind)到不同对象实例的相同函数

c++ - 从对其他进程(如 cmds)可见的 C++ 代码设置当前用户环境变量

c++ - constexpr 静态成员与变量

Java方法据说返回类的对象但返回子类的对象

arrays - VBA 编译错误 : Can't Assign to Read-Only Property Returning Array from Custom Class Get Property

c++ - 为什么我的 64 位 C++ 应用程序崩溃了?

c++ - 数据库表在内存中表示的容器

c++ - 在小尺寸窗口中保存大尺寸图片

c - Floodfill 算法 C - 返回双数组?