|
Boost : |
Subject: Re: [boost] safe bool operator
From: Domagoj Saric (dsaritz_at_[hidden])
Date: 2010-03-01 16:47:17
"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:A062A9144EEA45339956BFD0D4FDC906_at_pdimov2...
> Using a single type allows unrelated classes to compare equal with
> operator==.
Do'h :)
Even if I thought of that I would have thought that the
'only-a-single-conversion-may-take-place' rule would apply...Thanks for the
correction ;)
...but still the proposal can work, only in the usual template-uglified form:
class my_class
{
public:
bool some_is_valid_function() const;
operator boost::safe_bool<my_class>::type() const { return
boost::safe_bool<my_class>::make( some_is_valid_function() ); }
//or by using a macro
BOOST_SAFE_BOOL_FROM_FUNCTION( my_class, some_is_valid_function() );
//or by using a data member
unsigned int size_;
operator boost::safe_bool<my_class>::type() const { return
boost::safe_bool<my_class>::make( size_ ); }
BOOST_SAFE_BOOL_FROM_DATA( my_class, size_ );
}
...still less hassle than status quo...
...or maybe even more so if we take advantage of the fact that now we can use
the CRTP idiom (or part of it):
class my_class : boost::safe_bool<my_class>
{
public:
bool some_is_valid_function() const;
operator unspecified_bool_type() const { return make(
some_is_valid_function() ); }
}
-- "What Huxley teaches is that in the age of advanced technology, spiritual devastation is more likely to come from an enemy with a smiling face than from one whose countenance exudes suspicion and hate." Neil Postman begin 666 safe_bool.hpp M(W!R86=M82!O;F-E#0HC:69N9&5F('-A9F5?8F]O;%]H<' -"B-D969I;F4@ M<V%F95]B;V]L7VAP< T*+R\M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM M+2TM+2T-"B-I;F-L=61E(")B;V]S="]M<&PO8F]O;"YH<' B#0HO+RTM+2TM M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0T*;F%M97-P86-E(&)O;W-T M#0I[#0HO+RTM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0T*#0IT M96UP;&%T92 \8VQA<W,@5#X-"G-T<G5C="!S869E7V)O;VP-"GL-"G!R:79A M=&4Z#0H@(" @<W1R=6-T('5N<W!E8VEF:65D7V)O;VQ?='EP95]H96QP97(- M"B @("![#0H@(" @(" @('9O:60@;65M8F5R7V9U;F-T:6]N*"D@>WT[#0H@ M(" @(" @(&EN="!M96UB97)?9&%T85\[#0H@(" @?3L-"@T*(" @('1Y<&5D M968@=F]I9" H=6YS<&5C:69I961?8F]O;%]T>7!E7VAE;'!E<CHZ*G5N<W!E M8VEF:65D7V)O;VQ?='EP95]F=6YC=&EO;BD@*"D[#0H@(" @='EP961E9B!I M;G0@("!U;G-P96-I9FEE9%]B;V]L7W1Y<&5?:&5L<&5R.CHJ=6YS<&5C:69I M961?8F]O;%]T>7!E7V1A=&$@(" @(" @(#L-"@T*(" @('5N:6]N(&9A<W1? M<V%F95]B;V]L#0H@(" @>PT*(" @(" @("!U;G-I9VYE9"!L;VYG(" @(" @ M(" @(" @(" @(" @<&QA:6Y?<&]I;G1E<E]P;&%C96AO;&1E<CL-"B @(" @ M(" @=6YS<&5C:69I961?8F]O;%]T>7!E7V9U;F-T:6]N('!O:6YT97)?=&]? M;65M8F5R(" @(" @(" [#0H@(" @?3L-"@T*(" @("\O(" @270@:7,@87-S M=6UE9"!T:&%T(&EF('1H92!C;VUP:6QE<B!I<R!A8FQE('1O(&9I="!A('!L M86EN+"!S:6YG;&4-"B @(" O+R!I;FAE<FET86YC92!M96UB97(@9G5N8W1I M;VX@<&]I;G1E<B!I;G1O('-I>F5O9B@@=F]I9" J("D@=&AA="!I=',@;G5L M; T*(" @("\O(&)I;F%R>2!R97!R97-E;G1A=&EO;B!I<R!I9&5N=&EC86P@ M=&\@82!P;&%I;B!N=6QL('9O:60@<&]I;G1E<B H86QL(&)I=',-"B @(" O M+R!Z97)O960I+B!7:71H;W5T(&$@=V%Y('1O(&-H96-K('1H:7,@870_at_8V]M M<&EL92!T:6UE('1H:7,@87-S97)T960_at_870-"B @(" O+R!R=6YT:6UE+@T* M(" @("\O(" @5&AE(&%B;W9E(&YE960@;F]T(&AO;&0_at_9F]R(&1A=&$@;65M M8F5R('!O:6YT97)S("AE+F<N($U35D,K*R!U<V5S("TQ#0H@(" @+R\@9F]R M(&YU;&PM9&%T82!M96UB97(@<&]I;G1E<G,I+@T*(" @('1Y<&5D968@;7!L M.CIB;V]L7PT*(" @(" @(" \#0H@(" @(" @(" @(" H('-I>F5O9B@@9F%S M=%]S869E7V)O;VP@*2 \/2!S:7IE;V8H('5N<VEG;F5D(&QO;F<@*2 I#0H@ M(" @(" @(#X_at_8V%N7W5S95]F87-T7V)O;VQ?:&%C:SL-"@T*<')O=&5C=&5D M._at_T*(" @('1Y<&5D968@='EP96YA;64@;7!L.CII9E\-"B @(" @(" @/ T* M(" @(" @(" @(" @8V%N7W5S95]F87-T7V)O;VQ?:&%C:RP-"B @(" @(" @ M(" @('5N<W!E8VEF:65D7V)O;VQ?='EP95]F=6YC=&EO;BP-"B @(" @(" @ M(" @('5N<W!E8VEF:65D7V)O;VQ?='EP95]D871A#0H@(" @(" @(#XZ.G1Y M<&4@=6YS<&5C:69I961?8F]O;%]T>7!E.PT*#0IP<FEV871E._at_T*(" @('-T M871I8PT*(" @('5N<W!E8VEF:65D7V)O;VQ?='EP95]F=6YC=&EO;@T*(" @ M(&UA:V5?<V%F95]B;V]L7W-T86YD87)D7W=O<FME<B@@8F]O;"!C;VYS="!B M;V]L7W9A;'5E+"!U;G-P96-I9FEE9%]B;V]L7W1Y<&5?9G5N8W1I;VX_at_8V]N M<W0@;G5L;%]V86QU92 I#0H@(" @>PT*(" @(" @("!R971U<FX_at_8F]O;%]V M86QU92 _("9U;G-P96-I9FEE9%]B;V]L7W1Y<&5?:&5L<&5R.CIM96UB97)? M9G5N8W1I;VX_at_.B!N=6QL7W9A;'5E.PT*(" @('T-"B @("!S=&%T:6,-"B @ M("!U;G-P96-I9FEE9%]B;V]L7W1Y<&5?9&%T80T*(" @(&UA:V5?<V%F95]B M;V]L7W-T86YD87)D7W=O<FME<B@@8F]O;"!C;VYS="!B;V]L7W9A;'5E+"!U M;G-P96-I9FEE9%]B;V]L7W1Y<&5?9&%T82 @(" @8V]N<W0@;G5L;%]V86QU M92 I#0H@(" @>PT*(" @(" @("!R971U<FX_at_8F]O;%]V86QU92 _("9U;G-P M96-I9FEE9%]B;V]L7W1Y<&5?:&5L<&5R.CIM96UB97)?9&%T85\@(" @.B!N M=6QL7W9A;'5E.PT*(" @('T-"@T*(" @('-T871I8PT*(" @('5N<W!E8VEF M:65D7V)O;VQ?='EP92!M86ME7W-A9F5?8F]O;%]W;W)K97(H(&)O;VP_at_8V]N M<W0@=F%L=64L(&UP;#HZ9F%L<V5?("\J=7-E('-T86YD87)D('9E<G-I;VXJ M+R I#0H@(" @>PT*(" @(" @("!R971U<FX@;6%K95]S869E7V)O;VQ?<W1A M;F1A<F1?=V]R:V5R*"!V86QU92P@=6YS<&5C:69I961?8F]O;%]T>7!E*" P M("D@*3L-"B @("!]#0H-"B @("!S=&%T:6,-"B @("!U;G-P96-I9FEE9%]B M;V]L7W1Y<&4@;6%K95]S869E7V)O;VQ?=V]R:V5R*"!B;V]L(&-O;G-T('9A M;'5E+"!M<&PZ.G1R=65?("\J=7-E(&9A<W0M:&%C:R!V97)S:6]N*B\@*0T* M(" @('L-"B @(" @(" @9F%S=%]S869E7V)O;VP_at_8V]N<W0_at_9F%S=%-A9F5" M;V]L(#T@>R!V86QU92!].PT*(" @(" @("!A<W-E<G0-"B @(" @(" @* T* M(" @(" @(" @(" @*" A(69A<W13869E0F]O;"YP;VEN=&5R7W1O7VUE;6)E M<B ]/2 A(79A;'5E("D@)B8-"B @(" @(" @(" @(")4:&4@=F]I9"UP;VEN M=&5R+7-I>F5D(&UE;6)E<B!P;VEN=&5R(&YU;&P_at_8FEN87)Y(@T*(" @(" @ M(" @(" @(G)E<')E<V5N=&%T:6]N(&%S<W5M<'1I;VX_at_9&]E<R!N;W0@:&]L M9"!F;W(@=&AI<R(-"B @(" @(" @(" @(")C;VUP:6QE<B]P;&%T9F]R;2XB M#0H@(" @(" @("D[#0H@(" @(" @(')E='5R;B!F87-T4V%F94)O;VPN<&]I M;G1E<E]T;U]M96UB97([#0H@(" @?0T*#0IP=6)L:6,Z#0H@(" @='EP961E M9B!U;G-P96-I9FEE9%]B;V]L7W1Y<&4@='EP93L-"@T*(" @('1E;7!L871E M(#QT>7!E;F%M92!I;7!L:6-I=%]B;V]L/@T*(" @('-T871I8R!T>7!E(&UA M:V4H(&EM<&QI8VET7V)O;VP_at_8V]N<W0@=F%L=64@*0T*(" @('L-"B @(" @ M(" @<F5T=7)N(&UA:V5?<V%F95]B;V]L7W=O<FME<B@@(2%V86QU92P_at_8V%N M7W5S95]F87-T7V)O;VQ?:&%C:R_at_I("D[#0H@(" @?0T*?3L@+R\@;F%M97-P M86-E(&1E=&%I; T*#0H-"@T*#0HO+R!)9B!W92!C;W5L9"!U<V4@;65M8F5R M('!O:6YT97)S(&)E9F]R92!T:&4@;65M8F5R(&ES(&%C='5A;&QY(&1E8VQA M<F5D+W-E96X-"B\O('=E(&-O=6QD('5S92!#4E10+6)A<V5D(&AE;'!E<B!C M;&%S<V5S(&9O<B!M:6YI;75M('9E<F)O<VET>2!S869E7V)O;VP-"B\O(&EM M<&QE;65N=&%T:6]N<SH-"B\O('1E;7!L871E(#QC;&%S<R!"87-E+"!B;V]L M("A"87-E.CHJ8F]O;%]F=6YC=&EO;BD@*"D_at_8V]N<W0^#0HO+R!C;&%S<R!S M869E7V)O;VP-"B\O('L-"B\O(" @("!O<&5R871O<B!U;G-P96-I9FEE9%]B M;V]L7W1Y<&4H*2!C;VYS="![(')E='5R;B!M86ME7W-A9F5?8F]O;"@@<W1A M=&EC7V-A<W0\0F%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9B O+R!S869E7V)O;VQ?:'!P#0H` ` end
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk