Title
tuple_size for const pair request <tuple> header
Status
c++17
Section
[utility]
Submitter
Alisdair Meredith

Created on 2012-11-09.00:00:00 last changed 89 months ago

Messages

Date: 2014-03-27.20:34:56

Proposed resolution:

This wording is relative to N3936.

  1. Change [tuple.helper] as indicated:

    template <class T> class tuple_size<const T>;
    template <class T> class tuple_size<volatile T>;
    template <class T> class tuple_size<const volatile T>;
    

    -3- Let TS denote tuple_size<T> of the cv-unqualified type T. Then each of the three templates shall meet the UnaryTypeTrait requirements (20.10.1) with a BaseCharacteristic of

    integral_constant<size_t, TS::value>
    

    -?- In addition to being available via inclusion of the <tuple> header, each of the three templates are available when any of the headers <array> or <utility> are included.

    template <size_t I, class T> class tuple_element<I, const T>;
    template <size_t I, class T> class tuple_element<I, volatile T>;
    template <size_t I, class T> class tuple_element<I, const volatile T>;
    

    -?- Let TE denote tuple_element<I, T> of the cv-unqualified type T. Then each of the three templates shall meet the TransformationTrait requirements (20.10.1) with a member typedef type that names the following type:

    • for the first specialization, add_const<TE::type>::type,

    • for the second specialization, add_volatile<TE::type>::type, and

    • for the third specialization, add_cv<TE::type>::type.

    -?- In addition to being available via inclusion of the <tuple> header, each of the three templates are available when any of the headers <array> or <utility> are included.

Date: 2014-03-27.00:00:00

[ 2014-03-27 Library reflector vote ]

The issue has been identified as Tentatively Ready based on eight votes in favour.

Date: 2013-10-18.00:00:00

[ 2013-10-18 Daniel provides wording ]

The suggested wording uses a similar approach as we already have in [iterator.range] to ensure that the range access templates are available when at least one of an enumerated list of header files is included.

I also think that the restricted focus on tuple_size of this issue is too narrow and should be extended to the similar partial template specializations of tuple_element as well. Therefore the suggested wording ensures this as well.

Date: 2013-03-15.00:00:00

[ 2013-03-15 Issues Teleconference ]

Moved to Open.

Howard notes that we have the same issue with array, so any resolution should apply to that header too.

Date: 2012-11-09.14:15:34

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.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2014-11-08 19:44:42adminsetstatus: voting -> wp
2014-11-04 10:26:50adminsetstatus: ready -> voting
2014-03-27 20:17:28adminsetmessages: + msg6926
2014-03-27 20:17:28adminsetstatus: open -> ready
2013-10-18 21:08:04adminsetmessages: + msg6754
2013-10-18 21:08:04adminsetmessages: + msg6753
2013-03-18 14:33:00adminsetmessages: + msg6427
2013-03-18 13:02:36adminsetstatus: new -> open
2012-11-09 00:00:00admincreate