Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2008-03-31 13:21:11


I would like to refer you to this address:

http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/nullptr

Is there any chance tha in your tests int* foo is a member variable? Which
compiler do you use?

The example from the location above compiles fine, except the line:

  const int n = 0;
  if (nullptr == n) {} // ok

Which IMO is a mistake in the wiki page.

With Kind Regards,
Ovanes Markarian

On Mon, Mar 31, 2008 at 6:57 PM, Robert Dailey <rcdailey_at_[hidden]> 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.
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net