Const: what do you want to achieve (proposition...)?
Gilles G.
schaouette at free.fr
Tue Nov 13 02:03:19 PST 2007
I am reading all those posts about constness and how some people want to be sure data never gets modified when passed as an argument to a function.
I would like to try a proposition:
For the following function, you cannot tell if foo is modified or not:
Bar myFunction(Foo foo)
Now, let me introduce an other way of expressing things. If one wants a function that *can* modify foo, it could be defined like this:
(Bar,Foo) myFunction(Foo foo);
and this function may be used like this:
Bar myBar;
Foo myFoo;
Foo myFoo2;
(myBar,myFoo2) = myFunction(myFoo); // don't modify myFoo
(myBar,myFoo) = myFunction(myFoo); // modify myFoo
Here, the *compiler knows* if it must ensure the constness of myFoo or not. And the user of the function knows *explicitly* if myFoo gets modified or not.
So, what do you think? Is this a clumsy proposition?
--
Gilles G.
PS: I don't say that this is *the* right way. I would just like to understand why this proposition never arised.
More information about the Digitalmars-d
mailing list