On Monday 14 July 2014 11:08:01 Peter Dimov wrote:
Andrey Semashev wrote:
I think Boost.Proto is one of the examples where undesired reference recursion happened.
Boost.Proto just uses cref in a generic context, where its argument sometimes happens to be a reference_wrapper. That's not undesired.
Generic code can still be written with the trait I proposed. What's undesired is the reference recursiveness, especially if accidental.
If not because of performance, conceptually there are no references to references in C++, and std::ref attempts to reflect that.
There are references to reference_wrapper though.
Yes, you can also manually instantiate
reference_wrapper
Now that Boost.Proto does reference collapsing, reverting the change will break it again (I think).
That's possible, but I don't think so.
I suspect that you don't actually have a motivating example in mind.
That's true, I don't have a practical example at hand. But neither I can see why recursive references could be useful. With this kind of choice I prefer reference collapsing, at least because it looks more natural and std-like.
Given reference collapsing, how would you take advantage of it? What code have you written, or will write, that needs it?
In my probably uneducated view, generic libraries such as Proto or Phoenix should do reference collapsing. If not by the means of boost::ref then manually themselves. Whenever the user provides a reference_wrapper and the library intends to save it by reference (e.g. into the expression tree), reference collapsing should happen.
Do you realize that the simple use
#include
int main() { int x = 0; boost::reference_wrapper<int> r = boost::ref( x );
boost::reference_wrapper< boost::reference_wrapper<int> > r2 = boost::ref( r ); boost::reference_wrapper<int> r3 = boost::ref( r ); }
actually works without the overloads? They only serve to break r2.
I realize that the code will break but I disagree that the overloads only serve to break it. Why would you want r2? I mean, in what case would you intentionally write code to employ recursive references?