Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2005-07-22 12:17:25


From: David Abrahams <dave_at_[hidden]>
> Rob Stewart <stewart_at_[hidden]> writes:
> > From: David Abrahams <dave_at_[hidden]>
>
>> I didn't look, but it sounded odd that one could pass an int,>
>char *, std::complex, etc.
>
> Well, you can at least pass anything to the keyword's
> operator=.Whether or not the depth_first_search function
> compiles is anothermatter.

OK.

> Pedantry aside, what else is there?

I suppose there are two levels of pedantry in this case. One is
in the tutorial itself, and the other was due to my talking about
passing references.

> How's this?
> A keyword object has a pair of ``operator=`` overloads that
> ensure we can pass anything—temporary or not,
> ``const`` or not—by name, while preserving the
> mutability of non-temporaries:
> .. parsed-literal::
> template <class A> // handles non-const, |ArgumentPack| operator=(A&); // non-temporary objects
> template <class A> // handles const objects |ArgumentPack| operator=(A const&); // and temporaries
> However, when an “out” parameter is passed
> positionally, there's no keyword object involved. With our
> ``depth_first_search`` overload set above, the ``color_map``
> will be passed by ``const`` reference, and compilation will
> fail when mutating operations are used on it. The simple
> solution is to add another overload that takes a non-``const``
> reference in the position of the “out”
> parameter:

That should do it!

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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