Changeset 48323


Ignore:
Timestamp:
Aug 23, 2008, 8:25:06 PM (10 years ago)
Author:
Douglas Gregor
Message:

Fix forward's requirements by adding IdentityOf?, and apply the proposed resolution to LWG issue 823.

Location:
sandbox/committee/concepts/stdlib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sandbox/committee/concepts/stdlib/clib-concepts.tex

    r48273 r48323  
    133133\item Added the \tcode{underlying_type} associated type to the
    134134  \tcode{EnumerationType} concept.
     135
     136\item Added the \tcode{IdentityOf} concept, which acts like a simple
     137  identity metafunction. It is used by \tcode{std::forward}.
    135138\end{itemize}
    136139
     
    239242  concept DerivedFrom<typename Derived, typename Base> { }
    240243
    241   // \ref{concept.rvalue}, rvalue:
     244  // \ref{concept.transform}, type transformations:
     245  auto concept IdentityOf<typename T> @\textit{see below}@;
    242246  auto concept RvalueOf<typename T> @\textit{see below}@;
    243247  template<typename T> concept_map RvalueOf<T&> @\textit{see below}@;
     
    688692\end{itemdescr}
    689693
    690 \rSec2[concept.rvalue]{Rvalue}
     694\rSec2[concept.transform]{Type transformations}
     695\begin{itemdecl}
     696auto concept IdentityOf<typename T> {
     697  typename type = T;
     698  requires SameType<type, T>;
     699}
     700\end{itemdecl}
     701
     702\begin{itemdescr}
     703\pnum
     704\addedConcepts{\mbox{\reallynote} concept form of the \mbox{\tcode{identity}} type metafunction (\mbox{\ref{forward}}).}
     705\end{itemdescr}
     706
    691707\begin{itemdecl}
    692708auto concept RvalueOf<typename T> {
  • sandbox/committee/concepts/stdlib/clib-utilities.tex

    r48273 r48323  
    7676\item Replaced \tcode{HasConstructor} requirements with \tcode{Constructible} requirements.
    7777\item Constrain \tcode{move} with the \tcode{RvalueOf} concept.
    78 \item Constrain the \tcode{identity} helper template of \tcode{forward}.
     78\item Constrain the \tcode{identity} template, which has been moved
     79  to~\ref{function.objects} since it is not used by
     80  \tcode{forward}. Instead, we use the \tcode{IdentityOf} concept.
    7981\item Fixed syntactic errors in the \tcode{mem_fn} signatures.
    8082\item Constrain \tcode{tuple_element}, \tcode{tuple_size}.
     
    99101  constrained templates solves the problem of construction from a
    100102  literal 0.
     103\item[Issue 823. \tcode{identity<void>} seems broken.] Applied the proposed resolution to \tcode{identity}, which constrains the function call operator with a \tcode{ReferentType} requirement.
    101104\end{description}
    102105
     
    167170
    168171  // \ref{forward}, forward/move:
    169   template <@\changedConcepts{class}{VariableType}@ T> struct identity;
    170   template <@\changedConcepts{class}{VariableType}@ T> T&& forward(typename identity<T>::type&&);
     172  @\removedConcepts{template <class T> struct identity;}@
     173  template <@\changedConcepts{class}{IdentityOf}@ T> T&& forward(@\changedConcepts{typename identity<T>}{IdentityOf<T>}@::type&&);
    171174  template <@\changedConcepts{class}{RvalueOf}@ T> @\changedConcepts{typename remove_reference<T>::type\&\&}{RvalueOf<T>::type}@ move(T&&);
    172175
     
    297300of forwarding functions.}
    298301
    299 \index{identity@\tcode{identity}}%
    300 \begin{itemdecl}
    301 template <@\changedConcepts{class}{VariableType}@ T> struct identity { typedef T type; };
    302 \end{itemdecl}
    303 
    304 \begin{itemdescr}
    305 \pnum
    306 \addedD{\mbox{\enternote} The use of \mbox{\tcode{identity}} in
     302\editorial{\tcode{identity} is no longer used to make the argument
     303  type non-deduced. Instead, we use the \tcode{IdentityOf} concept and
     304  its associated type \tcode{type}, and have moved \tcode{identity}
     305  to~\ref{function.objects}.}
     306
     307\index{forward@\tcode{forward}}%
     308\begin{itemdecl}
     309template <@\changedConcepts{class}{IdentityOf}@ T> T&& forward(@\changedConcepts{typename identity<T>}{IdentityOf<T>}@::type&& t);
     310\end{itemdecl}
     311
     312\begin{itemdescr}
     313\pnum
     314\mbox{\enternote} The use of \changedConcepts{\mbox{\tcode{identity}}}{\mbox{\tcode{IdentityOf}}} in
    307315\mbox{\tcode{forward}} forces users to explicitly specify the
    308316template parameter. This is necessary to get the correct forwarding
    309 semantics.\mbox{\exitnote}}
    310 \end{itemdescr}
    311 
    312 \index{forward@\tcode{forward}}%
    313 \begin{itemdecl}
    314 template <@\changedConcepts{class}{VariableType}@ T> T&& forward(typename identity<T>::type&& t);
    315 \end{itemdecl}
    316 
    317 \begin{itemdescr}
     317semantics.\mbox{\exitnote}
     318
    318319\pnum
    319320\addedD{\mbox{\returns} \mbox{\tcode{t}}.}
     
    16141615  template <@\changedConcepts{class}{ObjectType}@ T> reference_wrapper<const T> cref(reference_wrapper<T>);
    16151616
     1617  // \ref{identity.operation}, identity operation:
     1618  @\addedConcepts{template <class T> struct identity;}@
     1619
    16161620  //    \ref{arithmetic.operations}, arithmetic operations:
    1617   template <class T> struct plus;
    1618   template <class T> struct minus;
    1619   template <class T> struct multiplies;
    1620   template <class T> struct divides;
    1621   template <class T> struct modulus;
    1622   template <class T> struct negate;
     1621  template <@\changedConcepts{class}{ReferentType}@ T> struct plus;
     1622  template <@\changedConcepts{class}{ReferentType}@ T> struct minus;
     1623  template <@\changedConcepts{class}{ReferentType}@ T> struct multiplies;
     1624  template <@\changedConcepts{class}{ReferentType}@ T> struct divides;
     1625  template <@\changedConcepts{class}{ReferentType}@ T> struct modulus;
     1626  template <@\changedConcepts{class}{ReferentType}@ T> struct negate;
    16231627
    16241628  // \ref{comparisons}, comparisons:
    1625   template <class T> struct equal_to;
    1626   template <class T> struct not_equal_to;
    1627   template <class T> struct greater;
    1628   template <class T> struct less;
    1629   template <class T> struct greater_equal;
    1630   template <class T> struct less_equal;
     1629  template <@\changedConcepts{class}{ReferentType}@ T> struct equal_to;
     1630  template <@\changedConcepts{class}{ReferentType}@ T> struct not_equal_to;
     1631  template <@\changedConcepts{class}{ReferentType}@ T> struct greater;
     1632  template <@\changedConcepts{class}{ReferentType}@ T> struct less;
     1633  template <@\changedConcepts{class}{ReferentType}@ T> struct greater_equal;
     1634  template <@\changedConcepts{class}{ReferentType}@ T> struct less_equal;
    16311635
    16321636  // \ref{logical.operations}, logical operations:
    1633   template <class T> struct logical_and;
    1634   template <class T> struct logical_or;
    1635   template <class T> struct logical_not;
     1637  template <@\changedConcepts{class}{ReferentType}@ T> struct logical_and;
     1638  template <@\changedConcepts{class}{ReferentType}@ T> struct logical_or;
     1639  template <@\changedConcepts{class}{ReferentType}@ T> struct logical_not;
    16361640
    16371641  // \ref{bitwise.operations}, bitwise operations:
    1638   template <class T> struct bit_and;
    1639   template <class T> struct bit_or;
    1640   template <class T> struct bit_xor;
     1642  template <@\changedConcepts{class}{ReferentType}@ T> struct bit_and;
     1643  template <@\changedConcepts{class}{ReferentType}@ T> struct bit_or;
     1644  template <@\changedConcepts{class}{ReferentType}@ T> struct bit_xor;
    16411645
    16421646  // \ref{negators}, negators:
     
    17441748
    17451749  // \marktr{}\ref{unord.hash}, hash function base template:
    1746   template <class T> struct hash;
     1750  template <@\changedConcepts{class}{ReferentType}@ T> struct hash;
    17471751
    17481752  // Hash function specializations
     
    17671771  template <> struct hash<long double>;
    17681772
    1769   template<class T> struct hash<T*>;
     1773  template<@\changedConcepts{class}{PointeeType}@ T> struct hash<T*>;
    17701774
    17711775  template <> struct hash<std::string>;
     
    18861890\end{itemdescr}
    18871891
     1892\editorial{Add the following new section [identity.operation]}
     1893\rSec2[identity.operation]{Identity operation}
     1894\index{identity@\tcode{identity}}%
     1895\begin{itemdecl}
     1896template <@\changedConcepts{class}{IdentityOf}@ T> struct identity {
     1897  typedef T type;
     1898
     1899  @\addedConcepts{requires ReferentType<T>}@
     1900    const T& operator()(const T& x) const;
     1901};
     1902\end{itemdecl}
     1903
     1904\begin{itemdecl}
     1905@\addedConcepts{requires ReferentType<T>}@
     1906  const T& operator()(const T& x) const;
     1907\end{itemdecl}
     1908
     1909\begin{itemdescr}
     1910\pnum
     1911\returns\
     1912\tcode{x}
     1913\end{itemdescr}
     1914
    18881915\rSec2[arithmetic.operations]{Arithmetic operations}
    18891916
     
    18941921\index{plus@\tcode{plus}}%
    18951922\begin{itemdecl}
    1896 template <class T> struct plus : binary_function<T,T,T> {
     1923template <@\changedConcepts{class}{ReferentType}@ T> struct plus : binary_function<T,T,T> {
    18971924  @\addedConcepts{requires HasPlus<T> \&\& Convertible<T::result_type, T>}@
    18981925    T operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    19091936\index{minus@\tcode{minus}}%
    19101937\begin{itemdecl}
    1911 template <class T> struct minus : binary_function<T,T,T> {
     1938template <@\changedConcepts{class}{ReferentType}@ T> struct minus : binary_function<T,T,T> {
    19121939  @\addedConcepts{requires HasMinus<T> \&\& Convertible<T::result_type, T>}@
    19131940    T operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    19241951\index{multiplies@\tcode{multiplies}}%
    19251952\begin{itemdecl}
    1926 template <class T> struct multiplies : binary_function<T,T,T> {
     1953template <@\changedConcepts{class}{ReferentType}@ T> struct multiplies : binary_function<T,T,T> {
    19271954  @\addedConcepts{requires HasMultiply<T> \&\& Convertible<T::result_type, T>}@
    19281955    T operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    19391966\index{divides@\tcode{divides}}%
    19401967\begin{itemdecl}
    1941 template <class T> struct divides : binary_function<T,T,T> {
     1968template <@\changedConcepts{class}{ReferentType}@ T> struct divides : binary_function<T,T,T> {
    19421969  @\addedConcepts{requires HasDivide<T> \&\& Convertible<T::result_type, T>}@
    19431970  T operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    19541981\index{modulus@\tcode{modulus}}%
    19551982\begin{itemdecl}
    1956 template <class T> struct modulus : binary_function<T,T,T> {
     1983template <@\changedConcepts{class}{ReferentType}@ T> struct modulus : binary_function<T,T,T> {
    19571984  @\addedConcepts{requires HasModulus<T> \&\& Convertible<T::result_type, T>}@
    19581985    T operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    19671994\index{negate@\tcode{negate}}%
    19681995\begin{itemdecl}
    1969 template <class T> struct negate : unary_function<T,T> {
     1996template <@\changedConcepts{class}{ReferentType}@ T> struct negate : unary_function<T,T> {
    19701997  @\addedConcepts{requires HasNegate<T> \&\& Convertible<T::result_type, T>}@
    19711998    T operator()(const T& @\farg{x}@) const;
     
    19862013\index{equal_to@\tcode{equal_to}}%
    19872014\begin{itemdecl}
    1988 template <class T> struct equal_to : binary_function<T,T,bool> {
     2015template <@\changedConcepts{class}{ReferentType}@ T> struct equal_to : binary_function<T,T,bool> {
    19892016  @\addedConcepts{requires HasEqualTo<T, T>}@
    19902017    bool operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    19992026\index{not_equal_to@\tcode{not_equal_to}}%
    20002027\begin{itemdecl}
    2001 template <class T> struct not_equal_to : binary_function<T,T,bool> {
     2028template <@\changedConcepts{class}{ReferentType}@ T> struct not_equal_to : binary_function<T,T,bool> {
    20022029  @\addedConcepts{requires HasNotEqualTo<T, T>}@
    20032030    bool operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    20122039\index{greater@\tcode{greater}}%
    20132040\begin{itemdecl}
    2014 template <class T> struct greater : binary_function<T,T,bool> {
     2041template <@\changedConcepts{class}{ReferentType}@ T> struct greater : binary_function<T,T,bool> {
    20152042  @\addedConcepts{requires HasGreater<T, T>}@
    20162043    bool operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    20252052\index{less@\tcode{less}}%
    20262053\begin{itemdecl}
    2027 template <class T> struct less : binary_function<T,T,bool> {
     2054template <@\changedConcepts{class}{ReferentType}@ T> struct less : binary_function<T,T,bool> {
    20282055  @\addedConcepts{requires HasLess<T, T>}@
    20292056    bool operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    20382065\index{greater_equal@\tcode{greater_equal}}%
    20392066\begin{itemdecl}
    2040 template <class T> struct greater_equal : binary_function<T,T,bool> {
     2067template <@\changedConcepts{class}{ReferentType}@ T> struct greater_equal : binary_function<T,T,bool> {
    20412068  @\addedConcepts{requires HasGreaterEqual<T, T>}@
    20422069    bool operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    20512078\index{less_equal@\tcode{less_equal}}%
    20522079\begin{itemdecl}
    2053 template <class T> struct less_equal : binary_function<T,T,bool> {
     2080template <@\changedConcepts{class}{ReferentType}@ T> struct less_equal : binary_function<T,T,bool> {
    20542081  @\addedConcepts{requires HasLessEqual<T, T>}@
    20552082    bool operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    20762103\index{logical_and@\tcode{logical_and}}%
    20772104\begin{itemdecl}
    2078 template <class T> struct logical_and : binary_function<T,T,bool> {
     2105template <@\changedConcepts{class}{ReferentType}@ T> struct logical_and : binary_function<T,T,bool> {
    20792106  @\addedConcepts{requires HasLogicalAnd<T, T>}@
    20802107    bool operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    20892116\index{logical_or@\tcode{logical_or}}%
    20902117\begin{itemdecl}
    2091 template <class T> struct logical_or : binary_function<T,T,bool> {
     2118template <@\changedConcepts{class}{ReferentType}@ T> struct logical_or : binary_function<T,T,bool> {
    20922119  @\addedConcepts{requires HasLogicalOr<T, T>}@
    20932120    bool operator()(const T& @\farg{x}@, const T& @\farg{y}@) const;
     
    21022129\index{logical_not@\tcode{logical_not}}%
    21032130\begin{itemdecl}
    2104 template <class T> struct logical_not : unary_function<T,bool> {
     2131template <@\changedConcepts{class}{ReferentType}@ T> struct logical_not : unary_function<T,bool> {
    21052132  @\addedConcepts{requires HasLogicalNot<T>}@
    21062133    bool operator()(const T& @\farg{x}@) const;
     
    21212148\index{bit_and@\tcode{bit_and}}%
    21222149\begin{itemdecl}
    2123 template <class T> struct bit_and : binary_function<T,T,T> {
     2150template <@\changedConcepts{class}{ReferentType}@ T> struct bit_and : binary_function<T,T,T> {
    21242151  @\addedConcepts{requires HasBitAnd<T, T>}@
    21252152    T operator()(const T& x, const T& y) const;
     
    21342161\index{bit_or@\tcode{bit_or}}%
    21352162\begin{itemdecl}
    2136 template <class T> struct bit_or : binary_function<T,T,T> {
     2163template <@\changedConcepts{class}{ReferentType}@ T> struct bit_or : binary_function<T,T,T> {
    21372164  @\addedConcepts{requires HasBitOr<T, T>}@
    21382165    T operator()(const T& x, const T& y) const;
     
    21472174\index{bit_xor@\tcode{bit_xor}}%
    21482175\begin{itemdecl}
    2149 template <class T> struct bit_xor : binary_function<T,T,T> {
     2176template <@\changedConcepts{class}{ReferentType}@ T> struct bit_xor : binary_function<T,T,T> {
    21502177  @\addedConcepts{requires HasBitXor<T, T>}@
    21512178    T operator()(const T& x, const T& y) const;
Note: See TracChangeset for help on using the changeset viewer.