我以std::tuple
.
... myFunction()
{
...
return std::tuple< int, unsigned long long, unsigned int >{ errorCode, timeStamp, sizeOfBuffer };
}
由于必须使用std::get
or访问返回值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