문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top