相关疑难解决方法(0)

std :: ignore with structured bindings?

序幕:

std::tuple<int, int, int> f();
std::tuple<int, int, float, int> g();
Run Code Online (Sandbox Code Playgroud)

C++ 1z将引入结构化绑定的语法,这样可以编写代替

int a, b, c;
std::tie(a, b, c) = f();
Run Code Online (Sandbox Code Playgroud)

就像是

auto [a, b, c] = f();
Run Code Online (Sandbox Code Playgroud)

但是,std::tie也允许指定std::ignore忽略某些组件,例如:

std::tie(a, b, std::ignore, c) = g();
Run Code Online (Sandbox Code Playgroud)

是否可以使用新的结构化绑定语法执行类似的操作?它会如何工作?

c++ language-lawyer c++17

61
推荐指数
4
解决办法
8767
查看次数

标签 统计

c++ ×1

c++17 ×1

language-lawyer ×1