Conversion from std::tuple<T, U> to std::pair<T, U>

86 views Asked by At

Both GCC and Clang (or rather libstdc++ and libc++ respectively) agree that

std::is_convertible<std::pair<int, int>, std::tuple<int, int>>::value

is true, which one should expect since std::tuple<T, U> has a non-explicit constructor taking a pair.

Going in the other direction however, from a tuple to a pair, the implementations disagree:

static_assert(std::is_convertible<std::tuple<int, int>, std::pair<int, int>>::value,
              "Cannot convert from tuple to pair");

fails with GCC but passes with Clang. I notice that std::pair has no constructor taking a tuple.

Questions:

  • According to the letter of the law, should the latter implicit conversion be allowed, or not? i.e. which implementation is correct here?

  • When calling std::pair<int, int> p = std::make_tuple(3, 4); under Clang, which std::pair constructor is being called?

0

There are 0 answers