C ++:std :: tie的返回类型,带std :: ignore [英] C++: Return type of std::tie with std::ignore

查看:347
本文介绍了C ++:std :: tie的返回类型,带std :: ignore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道C ++ 11标准是否对由<$ c>返回的 std :: tuple 类型当一些参数 std :: ignore 时,$ c> std :: tie 。

I am wondering if the C++11 standard gives any requirement about the type of the std::tuple returned by std::tie when some arguments are std::ignore.

更具体地说,我可以假设:

More specifically, can I assume that:


  1. decltype(std :: tie(42,std :: ignore ))不等于 decltype(std :: tie(std :: ignore,42))

  2. decltype(std :: tie(42,std :: ignore))不同于 decltype(std :: tie ))

  3. decltype(std :: tie(std :: ignore,42)) decltype(std :: tie(42))

  4. std :: ignore(std :: ignore))不等于 decltype(std :: tie / li>
  1. decltype(std::tie(42, std::ignore)) is not the same as decltype(std::tie(std::ignore, 42))
  2. decltype(std::tie(42, std::ignore)) is not the same as decltype(std::tie(42))
  3. decltype(std::tie(std::ignore, 42)) is not the same as decltype(std::tie(42))
  4. decltype(std::tie(std::ignore, std::ignore)) is not the same as decltype(std::tie(std::ignore))

换句话说,从类型角度看,生成的元组是否具有类型 decltype对于所有符合 std :: ignore 的位置的模板参数

In other words, from the type perspective, does the generated tuple behaves as a tuple which has type decltype(std::ignore) for all template arguments that match std::ignore by position?

推荐答案

是的, std :: tie 返回 std :: tuple< T& ...> $ c> T ... 是赋予它的类型。

std :: ignore 有一个未指定类型,但它仍然会出现在 tuple 根据您在 std :: tie 中指定的位置。

Yes you can, std::tie returns a std::tuple<T&...> where T... are the types that are given to it.
std::ignore has an unspecified type, but it will still appear in the tuple according to where you specified it in std::tie.

如果您觉得自己感觉更好,您可以在您的代码中包括:

If if makes you feel better, you could include in your code somewhere:

    int n;
    auto i = std::tie(std::ignore, n);
    auto j = std::tie(n, std::ignore);
    auto k = std::tie(n);
    static_assert(!std::is_same<decltype(i), decltype(j)>::value, "");
    static_assert(!std::is_same<decltype(i), decltype(k)>::value, "");
    static_assert(!std::is_same<decltype(j), decltype(k)>::value, "");

等等。这样,如果您的假设无效,编译将失败。

and so on for whatever combinations you are explicitly using. This way compilation will fail if your assumption is invalid.

这篇关于C ++:std :: tie的返回类型,带std :: ignore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆