Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-11-09 11:14:49


>From: "John Maddock" <john_maddock_at_[hidden]>

> Can whoever added this one, please add it to the docs (as a feature
macro).
>
> Is it possible to test for this? If so can a test program be supplied
> please - the test program should compile and run only if the feature is
> available - see one of the boost_has_XXX.cxx files for examples.

I've looked at the test-programs, there, but it wasn't clear to me in what
way it is preferred that the program fails to run (e.g. throwing an
exception), or if returning a non-zero value is enough. In any case, the
program below detects presence of NRVO, by returning zero, or greater than
zero if NRVO is not present.

Usage:

int result=boost_has_nrvo::test();

namespace boost_has_nrvo
{

class test_class
{
public:
  test_class() {}
  test_class(const test_class &other)
  {
    ++copy_count;
  }

  static int copy_count;
};

int test_class::copy_count;

test_class f()
{
  test_class nrv;

  return nrv;
}

int test()
{
  test_class::copy_count=0;

  f();

  return test_class::copy_count;
}

} // namespace boost_has_nrvo

Regards,

Terje


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk