Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-12-01 20:45:09

"Eric Niebler" <eric_at_[hidden]> wrote:

> I'll probably need some docs and tests at some point. It's really quite
> useful and safe now(*) so perhaps I'll actually put it up for review soon.
> (*) There is one outstanding problem that I have not yet solved. I think
> it's unsolvable in the current language, but I hope I'm wrong. The
> current implementation does the wrong thing when the container
> expression is a const-qualified rvalue STL container. It uses the rules
> for binding to reference to distinguish lvalues from rvalues, storing
> references for lvalues and copies for rvalues. Const-qualified rvalues
> screw this up, so the following crashes:
> std::vector<int> const get_vector();
> ...
> BOOST_FOREACH( int i, get_vector() )
> I'm not sure how serious this problem is. If anyone knows of a foolproof
> way to distinguish lvalues from rvalues, I'm all ears.

Oddly enough, I was thinking about this last night, and wrote the attached code.
It may be wildly wrong, both because I haven't give it much thought and because
I am not an expert in this area of the language. In particular, I may have left
out key use cases, or misclassified some cases. It passes on VC7.1, Comeau 4.3.3
and GCC 3.4.1, and passes all but one test on Intel 8.0.


P.S. One problem I just noticed is that is passes non-POD types through
ellipses. I tried using the any_conversion technique from is_convertible, but it
didn't work. Maybe someone can fix it.

begin 666 is_lvalue.cpp
M86)L95]I9BYH<' ^#0HC:6YC;'5D92 \8F]O<W0O<W1A=&EC7V%S<V5R="YH
M<' ^#0HC:6YC;'5D92 \8F]O<W0O='EP95]T<F%I=',O:7-?8V]N<W0N:'!P
M='EP92YH<' ^#0H-"FYA;65S<&%C92!B;V]S="![(&YA;65S<&%C92!D971A
M='EP92 -"FQV86QU95]T97-T,B@@5"8L( T*(" @(" @(" @(" @("!T>7!E
M;F%M92 -"B @(" @(" @(" @(" @96YA8FQE7VEF/ T*(" @(" @(" @(" @
M(" @(" @:7-?8V]N<W0\5#X-"B @(" @(" @(" @(" @/CHZ='EP92H@/2 P
M("D[#0H-"GT@?2 O+R!N86UE<W!A8V4N#0H-"B-D969I;F4_at_0D]/4U1?25-?
M3%9!3%5%*'@I(%P-"B @(" H('-I>F5O9BAB;V]S=#HZ9&5T86EL.CIL=F%L
M=65?=&5S=#$H>"DI(#T](%P-"B @(" @('-I>F5O9BAB;V]S=#HZ='EP95]T
M<F%I=',Z.GEE<U]T>7!E*2 I('Q\(%P-"B @(" H('-I>F5O9BAB;V]S=#HZ
M9&5T86EL.CIL=F%L=65?=&5S=#(H>"DI(#T](%P-"B @(" @('-I>F5O9BAB
M;V]S=#HZ='EP95]T<F%I=',Z.GEE<U]T>7!E*2 I(%P-"B @(" O*BHO#0H-
M=7)N(")H96QL;R([('T-"@T*:6YT(&UA:6XH*0T*>R @( T*(" @(&EN="!I
M,3L-"B @("!C;VYS="!I;G0@:3(@/2 P.PT*(" @('-T9#HZ<W1R:6YG(',Q
M.PT*(" @(&-O;G-T('-T9#HZ<W1R:6YG(',R(#T@(FAE;&QO(CL-"B @("!"
M3T]35%]35$%424-?05-315)4*$)/3U-47TE37TQ604Q512AI,2DI.PT*(" @
M(" @0D]/4U1?4U1!5$E#7T%34T525"A"3T]35%])4U],5D%,544H<S$I*3L-
M"B @("!"3T]35%]35$%424-?05-315)4*$)/3U-47TE37TQ604Q512AS,BDI
M.PT*(" @($)/3U-47U-4051)0U]!4U-%4E0H(4)/3U-47TE37TQ604Q512AF
M*"DI*3L-"B @("!"3T]35%]35$%424-?05-315)4*"%"3T]35%])4U],5D%,
M544H9R_at_I*2D[#0H@(" @0D]/4U1?4U1!5$E#7T%34T525"@A0D]/4U1?25-?
M3%9!3%5%*&@H*2DI.PT*(" @($)/3U-47U-4051)0U]!4U-%4E0H(4)/3U-4

Boost list run by bdawes at, gregod at, cpdaniel at, john at