元组作为一种返回类型,是经过优化的未处理值
Tuple as a return type, are unaccessed values optimized out?
我以std::tuple
的形式从一个函数返回三项。
... myFunction()
{
...
return std::tuple< int, unsigned long long, unsigned int >{ errorCode, timeStamp, sizeOfBuffer };
}
由于必须使用std::get
或std::tie
访问返回值,编译器是否针对未使用的值(g++4.8)进行了优化?
是的,可以。http://goo.gl/UB7DNc
#include "stdio.h"
#include <tuple>
std::tuple<int, unsigned long long, unsigned int> myFunction()
{
return std::tuple<int, unsigned long long, unsigned int>{ 1, 2, 3 };
}
int f()
{
return std::get<0>(myFunction());
}
成为
myFunction():
movq %rdi, %rax
movl $3, (%rdi)
movq $2, 8(%rdi)
movl $1, 16(%rdi)
ret
f():
movl $1, %eax
ret
相关文章:
- 空基优化子对象的地址
- 关闭||运算符优化
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 返回值优化:显式移动还是隐式
- 人脸跟踪arduino代码的优化
- 使用仅使用一次的变量调用的复制构造函数.这可能是通过调用move构造函数进行编译器优化的情况吗
- 纯函数,为什么没有优化
- 为什么大多数 pair 实现默认不使用压缩(空基优化)?
- 如何以优化的方式同时迭代两个间距不相等的数组
- 小字符串优化(调试与发布模式)
- 浮点定向舍入和优化
- Visual Studio 调试优化如何工作?
- 为什么开关的优化方式与 c/c++ 中的链接不同?
- 线性优化目标函数中的绝对值
- GCC 会优化内联访问器吗?
- const-ref传递的模板化参数是否经过优化,以便在足够小时按值传递
- 为什么这个浮点运算被编译得如此奇怪(没有经过优化)
- 当我使用这种 RAII 样式模式时,对象本身是否经过优化
- 元组作为一种返回类型,是经过优化的未处理值
- C++:是经过优化的if()指针检查