Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++17 status.

2212.tuple_size forconst pair request<tuple> header

Section: 22.2[utility]Status:C++17Submitter: Alisdair MeredithOpened: 2012-11-09Last modified: 2017-07-30

Priority:3

View all otherissues in [utility].

View all issues withC++17 status.

Discussion:

The<utility> header declares sufficient of the tuple API to specializethe necessary templates forpair, notablytuple_size andtuple_element. However, it does not make available the partial specializationsthat support cv-qualified template arguments, so while I can write the following afterincluding 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 lattermay compile with some standard library implementationsbut not others, leading to subtle portability issues.

[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.

[2013-10-18 Daniel provides wording]

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

I also think that the restricted focus ontuple_size of this issue is too narrow and should be extended tothe similar partial template specializations oftuple_element as well. Therefore the suggested wordingensures this as well.

[2014-03-27 Library reflector vote]

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

Proposed resolution:

This wording is relative to N3936.

  1. Change 22.4.7[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- LetTS denotetuple_size<T> of thecv-unqualified typeT. Then each of the three templates shall meet theUnaryTypeTrait requirements (20.10.1) with aBaseCharacteristic of

    integral_constant<size_t,TS::value>

    -?- In addition to being available via inclusion of the<tuple> header, each of the three templates areavailable 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>;

    -?- LetTE denotetuple_element<I, T> of thecv-unqualified typeT. Then each of the three templates shall meet theTransformationTrait requirements (20.10.1) with a member typedeftype 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 areavailable when any of the headers<array> or<utility> are included.


[8]ページ先頭

©2009-2025 Movatter.jp