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++23 status.

3545.std::pointer_traits should be SFINAE-friendly

Section: 20.2.3[pointer.traits]Status:C++23Submitter: Glen Joseph FernandesOpened: 2021-04-20Last modified: 2023-11-22

Priority:2

View all otherissues in [pointer.traits].

View all issues withC++23 status.

Discussion:

P1474R1 chose to usestd::to_address (a mechanism of converting pointer-like types to raw pointers) for contiguous iterators.std::to_address provides an optional customization point via an optional member instd::pointer_traits. However all iterators are not pointers, and the primary template ofstd::pointer_traits<Ptr> requires that eitherPtr::element_type is valid orPtr is of the formtemplate<T, Args...> or thepointer_traits specialization isill-formed. This requires specializingpointer_traits for those contiguous iterator types which is inconvenient for users.P1474should have also madepointer_traits SFINAE friendly.

[2021-05-10; Reflector poll]

Priority set to 2. Send to LEWG.Daniel: "there is no similar treatment for therebind membertemplate and I think it should be clarified whetherpointer_to'ssignature should exist and in which form in the offending case."

[2022-01-29; Daniel comments]

This issue has some overlap with LWG3665(i) in regard to the question how we should handletherebind_alloc member template of theallocator_traits template as specified by 20.2.9.2[allocator.traits.types]/11. It would seem preferable to decide for the same approach in both cases.

[2022-02-22 LEWG telecon; Status changed: LEWG → Open]

No objection to unanimous consent for Jonathan's suggestion to makepointer_traits an empty class when there is noelement_type. Jonathan to provide a paper.

Previous resolution [SUPERSEDED]:

This wording is relative toN4885.

  1. Modify 20.2.3.2[pointer.traits.types] as indicated:

    As additional drive-by fix the improper usage of the term "instantiation"has been corrected.

    using element_type =see below;

    -1-Type:Ptr::element_type if thequalified-idPtr::element_type is valid and denotes a type (13.10.3[temp.deduct]); otherwise,T ifPtr is a class templateinstantiationspecialization of the formSomePointer<T, Args>, whereArgs is zero or more type arguments; otherwise,the specialization is ill-formedpointer_traits has no memberelement_type.

[2022-09-27; Jonathan provides new wording]

Previous resolution [SUPERSEDED]:

This wording is relative toN4917.

  1. Modify 20.2.3.1[pointer.traits.general] as indicated:

    -1-The class templatepointer_traits supplies a uniform interface tocertain attributes of pointer-like types.

    namespace std {  template<class Ptr> struct pointer_traits {using pointer         = Ptr;using element_type    =see below;using difference_type =see below;template<class U> using rebind =see below;static pointer pointer_to(see below r);see below;  };  template<class T> struct pointer_traits<T*> {    using pointer         = T*;    using element_type    = T;    using difference_type = ptrdiff_t;    template<class U> using rebind = U*;    static constexpr pointer pointer_to(see below r) noexcept;  };}
  2. Modify 20.2.3.2[pointer.traits.types] as indicated:

    -?-The definitions in this subclause make use of the followingexposition-only class template and concept:

    template<class T>structptr-traits-elem// exposition only{ };template<class T> requires requires { typename T::element_type; }structptr-traits-elem<T>{ using type = typename T::element_type; };template<template<class...> class SomePointer, class T, class... Args>requires (!requires { typename SomePointer<T, Args...>::element_type; })structptr-traits-elem<SomePointer<T, Args...>>{ using type = T; };template<class Ptr>  concepthas-elem-type =// exposition only    requires { typenameptr-traits-elem<Ptr>::type; }

    -?-IfPtr satisfieshas-elem-type,a specializationpointer_traits<Ptr> generated from thepointer_traits primary template has the members described in20.2.3.2[pointer.traits.types] and 20.2.3.3[pointer.traits.functions];otherwise, such a specialization has no members by any of the names describedin those subclauses or in 20.2.3.4[pointer.traits.optmem].

    using pointer = Ptr;
    using element_type =see belowtypenameptr-traits-elem<Ptr>::type;

    -1-Type:Ptr::element_type if thequalified-idPtr::element_type is valid and denotes a type (13.10.3[temp.deduct]);otherwise,T ifPtr is a class template instantiation of theformSomePointer<T, Args>, whereArgs is zero or moretype arguments; otherwise, thespecialization is ill-formed.

    using difference_type =see below;

    -2-Type:Ptr::difference_type if thequalified-idPtr::difference_type is valid and denotes a type (13.10.3[temp.deduct]);otherwise,ptrdiff_t.

    template<class U> using rebind =see below;

    -3-Alias template:Ptr::rebind<U> if thequalified-idPtr::rebind<U> is valid and denotes a type (13.10.3[temp.deduct]);otherwise,SomePointer<U, Args> ifPtr is a class template instantiation of theformSomePointer<T, Args>, whereArgs is zero or moretype arguments; otherwise, the instantiation ofrebind is ill-formed.

[2022-10-11; Jonathan provides improved wording]

[2022-10-19; Reflector poll]

Set status to "Tentatively Ready" after six votes in favour in reflector poll.

[2022-11-12 Approved at November 2022 meeting in Kona. Status changed: Voting → WP.]

Proposed resolution:

This wording is relative toN4917.

  1. Modify 20.2.3.1[pointer.traits.general] as indicated:

    -1-The class templatepointer_traits supplies a uniform interface tocertain attributes of pointer-like types.

    namespace std {  template<class Ptr> struct pointer_traits {using pointer         = Ptr;using element_type    =see below;using difference_type =see below;template<class U> using rebind =see below;static pointer pointer_to(see below r);see below;  };  template<class T> struct pointer_traits<T*> {    using pointer         = T*;    using element_type    = T;    using difference_type = ptrdiff_t;    template<class U> using rebind = U*;    static constexpr pointer pointer_to(see below r) noexcept;  };}
  2. Modify 20.2.3.2[pointer.traits.types] as indicated:

    -?-The definitions in this subclause make use of the followingexposition-only class template and concept:

    template<class T>structptr-traits-elem// exposition only{ };template<class T> requires requires { typename T::element_type; }structptr-traits-elem<T>{ using type = typename T::element_type; };template<template<class...> class SomePointer, class T, class... Args>requires (!requires { typename SomePointer<T, Args...>::element_type; })structptr-traits-elem<SomePointer<T, Args...>>{ using type = T; };template<class Ptr>  concepthas-elem-type =// exposition only    requires { typenameptr-traits-elem<Ptr>::type; }

    -?-IfPtr satisfieshas-elem-type,a specializationpointer_traits<Ptr> generated from thepointer_traits primary template has the following membersas well as those described in 20.2.3.3[pointer.traits.functions];otherwise, such a specialization has no members by any of those names.

    using pointer =see below;

    -?-Type:Ptr.

    using element_type =see below;

    -1-Type:typenameptr-traits-elem<Ptr>::type.Ptr::element_type if thequalified-idPtr::element_type is valid and denotes a type (13.10.3[temp.deduct]);otherwise,T ifPtr is a class template instantiation of theformSomePointer<T, Args>, whereArgs is zero or moretype arguments; otherwise, thespecialization is ill-formed.

    using difference_type =see below;

    -2-Type:Ptr::difference_type if thequalified-idPtr::difference_type is valid and denotes a type (13.10.3[temp.deduct]);otherwise,ptrdiff_t.

    template<class U> using rebind =see below;

    -3-Alias template:Ptr::rebind<U> if thequalified-idPtr::rebind<U> is valid and denotes a type (13.10.3[temp.deduct]);otherwise,SomePointer<U, Args> ifPtr is a class template instantiation of theformSomePointer<T, Args>, whereArgs is zero or moretype arguments; otherwise, the instantiation ofrebind is ill-formed.

  3. Modify 20.2.3.4[pointer.traits.optmem] as indicated:

    -1-Specializations ofpointer_traits may define the member declaredin this subclause to customize the behavior of the standard library.A specialization generated from thepointer_traits primary templatehas no member by this name.

    static element_type* to_address(pointer p) noexcept;

    -1-Returns:A pointer of typeelement_type* that references the same locationas the argumentp.


[8]ページ先頭

©2009-2026 Movatter.jp