
AMDG Robert Dailey wrote:
Hi,
I realize that C++03 will not permit functions to evaluate down to compile-time constants. However, I cannot wait until C++0x for this feature. So, I'm hoping that Boost will allow a temporary solution. Consider the following structure:
static struct nullptr_t { template< typename t_type > operator t_type*() { return 0; } } nullptr;
The compiler has everything it needs to turn this code into a single integral constant value. So, if I do the following:
int* foo; if( foo == nullptr ) { }
Then it should evaluate down to:
int* foo; if( foo == 0 ) { }
Is there any way to provide this behavior in Boost? I would like to avoid altering the actual design if possible. Perhaps this actually *does* evaluate to a constant and the problem is that I'm actually unaware of some specific rule that I didn't find in the C++03 standard. Thanks.
If you don't need a constant expression, the compiler will probably figure it out if you compile with optimization. In Christ, Steven Watanabe