Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Return type of std::tie with std::ignore

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)) 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))

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?

like image 812
eold Avatar asked Oct 01 '22 01:10

eold


1 Answers

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.

like image 155
SirGuy Avatar answered Oct 03 '22 16:10

SirGuy