经过一段时间的搜索,我仍然无法得到这个。有人可以告诉我如何以常量表达式返回元组。这是代码:
#include <tuple>
constexpr std::tuple<int, int> ret2 () {
int a = 1;
int b = 2;
return std::make_tuple(a, b);
}
constexpr int ret1 () {
int a = 0;
int b = 0;
std::tie(a, b) = ret2();
return a + b;
}
constexpr auto tmp = ret1();
clang ++ -std = c ++ 14 -o test test.cpp
test.cpp:15:16: error: constexpr variable 'tmp' must be initialized by a constant expression
constexpr auto tmp = ret1();
^ ~~~~~~
test.cpp:11:17: note: non-constexpr function
'operator=<std::__1::tuple<int, int>, void>' cannot be used in a constant expression
std::tie(a, b) = ret2();
^
test.cpp:15:22: note: in call to 'ret1()'
constexpr auto tmp = ret1();
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/tuple:899:9: note:
declared here
operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&...
^
1 error generated.
clang --version
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin17.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
我尝试将此更改为std::tuple<int&, int&>
,并使用std::ref
等等...我似乎无法找到正确的序列。
此外,调用std :: get 2x在代码中会很冗长,并且在运行时可能会浪费。有没有办法通过一次调用获得两个值 - 如图所示?
答案 0 :(得分:1)
答案 1 :(得分:1)
您无法使用declare @query varchar(max)
declare @char char = ''''
set @query='create procedure dbo.test as select '+@char+'<1>"hola"<1> '+@char
--PRINT @query
execute(@query)
,因为它不是std::tuple::operator=
。您的示例可以转换为:
constexpr
与原版相同,但我不确定它是否满足您的实际需求。