Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2008-03-31 14:06:39


Sorry again I misread your post. As Steven already posted if you optimize
for speed compiler will optimize this down to const.

If you don't like the idea of checking the generated assembler and you use
visual studio. You can compile in release mode with debug infos enabled.
Then you can step through your functionality and see what was inlined. This
is for sure not a guarantee that compiler will always inline or optimize
this code, but most likely it will.

With Kind Regards,
Ovanes

On Mon, Mar 31, 2008 at 7:21 PM, Ovanes Markarian <om_boost_at_[hidden]>
wrote:

> Sorry, my current compiler is VC++ 7.1
>
>
> On Mon, Mar 31, 2008 at 7:21 PM, Ovanes Markarian <om_boost_at_[hidden]>
> wrote:
>
> > 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