Boost logo

Boost :

From: Vincent Finn (vincent.finn_at_[hidden])
Date: 2003-04-23 04:09:20


Justin M. Lewis wrote:
> I don't really know how this works. I know someone who's a big Boost
> fan, and he said he didn't know of anything like what I'm going to
> propose exists in Boost here. So, here it is.
>
> The problem I was having, we have references, that allows me to pass a
> paramter to a function, that function modifies the value passed in, at
> the point where that function is called, I cannot tell that the data is
> being modified. Basically, it leads to somewhat confusing code,
> especially in a case where you're looking at someone else's code trying
> to track down where a value gets set.
>
> void func(int &x){x = 1977;};
>
> void blah()
> {
> int y=0;
> func(y);
> func2(y);
> printf("%d\n", y);
> }
>
>
> Something along those lines could become confusing, obviously in a much
> larger program.
>
> My idea was, if you make a simple template class, originally I called it
> CRetVal, you could force people to specify at the time the function is
> called what's going on. I made a helper template function retval that
> would create and return a CRetVal object of the desired type to save
> from needing to use template notation in line all over the place. So,
> the above would become something more like.
>
> void func(CRetVal<int> x){x = 1977;};
>
> void blah()
> {
> int y=0;
> func(retval(y));
> func2(y);
> printf("%d\n", y);
> }

could you not get the same effect by using
void func(int* px) {*px = 1977;}

int y = 0;
func(&y);
func2(y);

        Vin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk