Boost logo

Boost :

From: Justin M. Lewis (boost_at_[hidden])
Date: 2003-05-03 22:12:44


----- Original Message -----
From: "Noel Yap" <Noel.Yap_at_[hidden]>
To: "Boost mailing list" <boost_at_[hidden]>
Sent: Saturday, May 03, 2003 6:01 PM
Subject: Re: [boost] Re: in/out parameters, codingstylesandmaintenance

> Gregory Colvin wrote:
> > > So you're saying the parameter can be an out-only parameter? If so,
> > > for
> > > out parameters, use:
> > >
> > > boost::dumb_ptr< T > f();
> > > t = f();
> > >
> > > IMHO, the intent is much more clear than:
> > >
> > > f( out< T > t );
> > > f( out< T >( t ) );
> >
> > Not to me it isn't.
>
> So we've established that we disagree about the coding style. Does this
> mean that c_out, a subjective coding style helper, shouldn't be put in
> the C++ standard, a, ummm, standard?
>
> > Anyway, I dislike out parameters more than I do raw pointers.
>
> So do I.
>
> >From the above, it sounds like you would rather use out parameters than
> return values. Do you write code like:
>
> void square_root( double input_, double& output_ );
>
> rather than:
>
> double square_root( double input_ );
>

A little bit of an overly simple example. How about something more like

void MyGetCWD(c_out<std::string> cwd)
{
    char *buf = new char[FIRSTSIZE];
    unsigned int size = FIRSTSIZE;
    while(getcwd(buf, sizeof(buf)) == NULL)
    {
        delete [] buf;
        size += step;
        buf = new char[size];
    }

    cwd = buf;
    delete[] buf;
}

I doubt that's entirely correct, I just made it up off the top of my head.

Or, how about,
void GetFileName(c_in_out<std::string> path, const std::string &filter)
{
    std::string fname;
    FindFirstFileWithFilter(out(fname), path, filter);
    path += "/";
    path += fname;
}

I could probably make up much better examples, but I was doing something
with getcwd on friday, so it's on my mind still.

> Noel
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
>


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