Date
2012-11-09.14:15:34
Message id
6278

Content

The <utility> header declares sufficient of the tuple API to specialize the necessary templates for pair, notably tuple_size and tuple_element. However, it does not make available the partial specializations that support cv-qualified template arguments, so while I can write the following after including only <utility>:

#include <utility>

using TestType = std::pair<int, int>;
static_assert(2 == std::tuple_size<TestType>(), "Pairs have two elements");
std::tuple_element<0, TestType>::type var{1};

the following may fail to compile unless I also include <tuple>:

#include <utility>

using TestType = const std::pair<int, int>;
static_assert(2 == std::tuple_size<TestType>(), "Pairs have two elements");
std::tuple_element<0, TestType>::type var{1};

Note, however, that the latter may compile with some standard library implementations but not others, leading to subtle portability issues.