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.

Jonathan

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
M(VEN8VQU9&4@/'-T<FEN9SX-"B-I;F-L=61E(#QB;V]S="]U=&EL:71Y+V5N
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/@T*(VEN8VQU9&4@/&)O;W-T+W1Y<&5?=')A:71S+V1E=&%I;"]Y97-?;F]?
M='EP92YH<' ^#0H-"FYA;65S<&%C92!B;V]S="![(&YA;65S<&%C92!D971A
M:6P@>PT*#0IT96UP;&%T93QT>7!E;F%M92!4/@T*='EP95]T<F%I=',Z.GEE
M<U]T>7!E(&QV86QU95]T97-T,2A4)BD[#0H-"G1E;7!L871E/'1Y<&5N86UE
M(%0^#0IT>7!E7W1R86ET<SHZ;F]?='EP92!L=F%L=65?=&5S=#$H8V]N<W0@
M5"8I.PT*#0IT>7!E7W1R86ET<SHZ;F]?='EP92!L=F%L=65?=&5S=#(H+BXN
M*3L-"@T*=&5M<&QA=&4\='EP96YA;64_at_5#X-"G1Y<&5?=')A:71S.CIY97-?
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"FEN="!F*"D@>R!R971U<FX@,#L@?0T*#0IS=&0Z.G-T<FEN9R!G*"D@>R!R
M971U<FX@(FAE;&QO(CL@?0T*8V]N<W0@<W1D.CIS=')I;F<@:"@I('L@<F5T
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($)/3U-47U-4051)0U]!4U-%4E0H0D]/4U1?25-?3%9!3%5%*&DR*2D[#0H@
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
87TE37TQ604Q512_at_B:&5L;&\B*2D[#0I]
`
end


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