I know what rvalues and lvalues are, to a degree. Still, it is difficult since they've long surpassed their original definitions and there are rules here and there that defines the terms now.
I never really had difficulty with the difference, personally:
Lvalues are location values.
Rvalues are everything else, including lvalues being used for the data they contain in an expression. Primitive data are always rvalues.
The only hang up is maybe functions which return references (because function calls are normally rvalues). To me, it makes sense when I consider how operator chaining is supposed to work.
Well, wait... I thought of another one. The fact that array names are rvalues confuses people who are not aware of the difference between pointers and arrays but I do not believe you are one of them.
No, because it still allows meaningless comparisons between objects that have operator void*():
All these tricks IMHO are trying to be overly clever. Again, I don't see what's wrong with an explicit IsNull(). If the concern is interoperability with generic algorithms, well, those algorithms should not have been designed to require conversion in a boolean context in the first place. You can always raise to another level:Code:class MyClass { public: operator void *(); }; MyClass a; std::ofstream b; a == b; // valid?!
Code:template < typename T > bool IsNull( const enable_if< SupportsIsNull< T >, T >::type &x ) { return x.IsNull(); } template < typename T > bool IsNull( const enable_if< SupportsBooleanConversion< T >, T >::type &x ) { return x; } // etc...
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
You can't do this:Again, I don't see what's wrong with an explicit IsNull().
If you only have an isNull, you have to do it like this:Code:if(boost::optional<stuff> o = func_that_returns_optional()) { // o is only visible here, where it's not empty }
Code:boost::optional<stuff> o = func_that_returns_optional(); if(!o.isNull()) { // o is not empty here } // but it's visible and indefinite here
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
*shrug* Suit yourself. It is to me. I find blocks for the sake of scope to be one of the ugliest thing in the language.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law