Topic: Defect Report: Associated function definitions of operator-> and operator[]
Author: Richard Smith <richard@ex-parrot.com>
Date: Fri, 15 May 2009 12:07:44 CST Raw View
Paragraph [concept.map.fct]/4 in Working Draft N2857 lists how
different types of associated function requirements are satisfied.
Bullet points five and six cover postfix unary operators and binary
operators respectively.
[bullet 5]: "If the associated function or function template is a
postfix unary operator Op, E is parm1' Op."
[bullet 6]: "If the associated function or function template is a
binary operator Op, E is parm1' Op parm2'."
No special mention is given to the member access operator (operator->)
or subscript operator (operator[]) which both use peculiar syntaxes.
The terms 'postfix unary operator' and 'binary operator' are not
explicitly defined in the Working Draft and it is unclear whether
either of these terms apply to the member access and subscript
operator. (Although they both have two arguments, they are both
listed in [expr.post] 'Postfix Expressions', and in the case of the
member access operator, the second argument is a name rather than
anything understood by the C++ type system.)
Irrespective of whether these operators are postfix unary, binary, or
something else, the syntax in the bullet points listed does not apply
to these operators. However, they are clearly intended to be used in
concept (for example, RandomAccessIterator [random.access.iterator]
has both, and for the concept_maps for raw pointers in
[random.access.iterator]/11 to compile, one of the cases in
[concept.map.fct]/4 would need to apply to them).
Suggested resolution
Add two further bullet points to [concept.map.fct]/4:
"If the associated function or function template is a subscript
operator, E is parm1' [ parm2' ]."
"If the associated function or function template is a member access
operator then: if the type of parm1' is an archetype, E is operator->
(parm1'); if parm1' is of class type, E is parm1'.operator->(); and if
parm1' is of pointer type, E is parm1'."
Of the three cases in the suggested wording for operator->, the first
occurs when the concept_map is itself a constrained template. E.g.
concept Pointer<typename X> {
typename pointer = X::pointer;
pointer operator->( X const& );
}
template <std::ForwardIterator It>
concept_map Pointer<It> {}
The second case occurs frequently in unconstrained templates, e.g.
template <typename X>
concept_map Pointer< std:shared_ptr<X> > {}
And the third occurs when raw pointers are involved, e.g.
template <typename X>
concept_map Pointer< X const* > {
typedef X const* pointer;
}
Richard Smith
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]