N4173: Operator Dot -- Bjarne Stroustrup and Gabriel Dos Reis

A new WG21 paper is available. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N4173

Date: 2014-10-11

Operator Dot

by Bjarne Stroustrup and Gabriel Dos Reis

Excerpt:

This is a proposal to allow user-defined operator dot (operator.()) so that we can provide “smart references” similar to the way we provide “smart pointers.” The gist of the proposal is that if an operator.() is defined for a class Ref then by default every operation on a Ref object is forwarded to the result of operator.(). However, an operation explicitly declared as a member of Ref is applied to the Ref object without forwarding. A programmer can prevent a pointer to a referred-to object from “leaking” into the larger program by declaring operator.() private.

Add a Comment

Comments are closed.

Comments (3)

0 0

Germán said on Oct 13, 2014 12:01 AM:

Well, the last section says more reasonably real world examples. I think another two real world examples would be a copy on write class and a flyweight class.

What I don't get very well is if this could be done:


template <class T>
class Optional { ... };

template <class T>
class Flyweight {};

class Big {};

using BigOpt = Optional<Flyweight<Big>>;

//Use transparently as if the object was a Big.
BigOpt opt;
0 0

Germán said on Oct 13, 2014 12:09 AM:

I don't know how polemic this proposal will be, but I think it would be a great addition. Also the uniform call syntax. Congrats because C++ is going a way where more generalization is achieved. If this proposal, uniform call syntax, modules, concepts and ABI compat went in I would feel more than happy.

If you add a conceptified range-based algorithms library and some parallelization algos, stackless coroutines and reflection, this is gonna be the greates thing ever.

I have used C++ for many years and no matter what people say about how complex it is: it is usable and a feature no other language except C has: it works almost everywhere. Go on with this good work. I think C++ is a language for a lifetime.

The only missing point for real language "completeness" is type erasure a la Boost.TypeErasure, because this plays nicely with templates. But I think static code generation would also be needed as long as it is designed as a library feature, because you must generate the boilerplate for the "interface" class somewhere. Operator.() would not be enough, am I right?
0 0

chico said on Oct 24, 2014 09:52 PM:

This proposal could impact and improve std::wrapper_reference at the same time, or provide an alternative that doesn't requires .get() anymore.