Topic: Explicate template instantiation and operator->


Author: Sean A Corfield <sean@ocsltd.com>
Date: 1996/10/01
Raw View
In article <4xpw36qmya.fsf@lambert.Stanford.EDU>,
Brian Michael Freyburger <freyburg@lambert.stanford.edu> wrote:

|> Within a template class, a definition of operator-> should only be
|> instantiated if it is used, allowing for an invalid return type for a
|> definition which is never used.
...
|> Has the committee already thought of this?

Yes. A few meetings ago (July '95) I suggested that the return type of
operator->() not be checked at all (removing some wording from clause 14)
since the existing wording on builtin -> would be enough to trap errors at
use.

This means that the following is now legal:

    struct Strange {
        int operator->() { return 42; }
    };

    Strange brew;
    int cream = brew.operator->();

See www.ocsltd.com/c++/cppopp.html for more about this.

Sean A Corfield
Object Consultancy Services Ltd






[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Brian Michael Freyburger <freyburg@lambert.stanford.edu>
Date: 1996/09/29
Raw View

Within a template class, a definition of operator-> should only be
instantiated if it is used, allowing for an invalid return type for a
definition which is never used.  This is a very good thing.  However,
this *doesn't* work for explicit instantiation of a template class, at
least how it is currently defined.  An explicit instantiation of a
template class instantiates *all* of the members of the template.
Unfortunately, this causes an error if the class contains an
operator-> which can't be used (which an incorrect return type).

Therefore, I propose that the definition of explicit instantiation of
a class be modified slightly, so that errors involving the return type
of operator-> are silently ignored (and the operator-> isn't
instantiated).

Has the committee already thought of this?

Brian Freyburger


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]