We currently ensure that use of support::Path is correct by using a macro:

// path.h
class Path : boost::noncopyable {
public:
        /// change to the given directory
        explicit Path(std::string const & path);

        /// set cwd to the previous value if needed
        ~Path();
};

// To avoid the wrong usage:
// Path("/tmp");   // wrong
// Path p("/tmp");  // right
// we add this macro:
#ifndef PATH_C
#define Path(x) unnamed_Path;
#endif
// Tip gotten from Bobby Schmidt's column in C/C++ Users Journal

// path.C
#define PATH_C
#include "path.h"


Here's an alternative, pure C++ way, that's just been posted to c.l.c++.m
by 'tom_usenet'.

Angus


{
  transaction t(to_guard, t);
  //...
}

e.g. take a transaction& parameter as the second parameter. This makes
transaction(to_guard); produce a compile time error. The constructor
can assert if the address doesn't match "this". e.g.

transaction(guard& g, transaction& thisObject)
  :to_guard(g)
{
  assert(this == &thisObject); //ensure above form was used
  //and that some other transaction object wasn't passed.
  to_guard.lock();
}

It is legal to take the address of thisObject, since even though the
lifetime of thisObject hasn't started, the memory for it exists so you
can use a reference to it in limited ways (including taking the
address of it). Correct me if I'm wrong.

Tom


Reply via email to