
Rob Stewart <stewart@sig.com> writes:
From: David Abrahams <dave@boost-consulting.com>
Rob Stewart <stewart@sig.com> writes:
From: David Abrahams <dave@boost-consulting.com>
On the other hand\x{2014}as you may recall from the parameter table\x{2014}``color_map`` is an \x{201C}out\x{201D} parameter, so it really should be passed by non-const reference.
Note that "color_map" and "out" are quoted significantly differently with no apparent reason.
No, ``color_map`` isn't quotation; it's markup for "code font." Look at the HTML.
I was looking at it in the browser. I saw "``color_map``" and "<fancy open quote>out<fancy close quote>" so I saw no "code font" markup. Unless I'm misunderstanding you, something is wrong.
Thanks, I just fixed it.
A keyword object has a pair of operator= overloads that ensure we can pass anything by name, but when an \x{201C}out\x{201D} parameter is passed positionally, that's no help: in this case, core::depth_first_search would end up with a const reference to the color_map and compilation will fail when mutating operations are used on it.
That's a long sentence and did you really mean to say "we can pass *anything*" (emphasis mine)?
Yep.
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 another matter.
Perhaps this would be better:
A keyword object has a pair of operator = overloads that ensure we can pass references to const or non-const objects by name,
You don't get to pass references to anything in C++. You pass the object referred to by a name or expression and the callee decides whether it goes by reference.
Yeah, I misspoke (miswrote?). I was referring to the parameter type when I should have been discussing the allowable argument types.
Also, the point is that you can pass both lvalues and rvalues, or temporaries and non-temporaries, not that the objects can be const or non-const. You can do that just fine with a single templated function taking a T& (T will be deduced as U const when the object is constant).
Pedantry aside, that's not the same as *anything*.
Pedantry aside, what else is there?
but when an "out" parameter is passed positionally, that's no help. In that case, core:;depth_first_search would end up with a...."
What about splitting the sentence into two?
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: -- Dave Abrahams Boost Consulting www.boost-consulting.com