Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2006-07-07 17:31:54

On 7/8/06, Felipe Magno de Almeida <felipe.m.almeida_at_[hidden]> wrote:
> I prefer the pointer, that way one can define the variable inside the if
> if(exception_info* p = get_exception_info(e))
> {
> }

I don't see the benefit in this since if exception_info is defined in
the following sense:

struct exception_info {
  exception_info() : is_valid(false) {};
  exception_info(const exception_info & other) : is_valid(other.is_valid) {};
  bool is_valid;
  operator bool () {
    // return true if it's a copy of a real
    // exception, false if it's uninitialized...
    return is_valid;

Then something like this will be possible:

if (get_exception_info(e)) {
  std::cout << get_string<tag_file_name>(get_exception_info(e)) << std::endl;

> IMO, the pointer is cleaner.

Since a pointer is basically a primitive type which you can manipulate
like an integral type, it opens up a can of worms you don't want to
deal with -- and will only make the code a lot easier to get wrong.
Since you can manipulate pointers like int's, the following operations
will be valid:

exception_info * x = get_exception_info(e);

But if you're using references, you give a cleaner and more definite
handle to your data:

exception_info & info (get_exception_info(e));
info ++; // won't work, unless operator++ is defined for exception_info


Dean Michael C. Berris
C/C++ Software Architect
Orange and Bronze Software Labs
Mobile: +639287291459
Email: dean [at] orangeandbronze [dot] com

Boost list run by bdawes at, gregod at, cpdaniel at, john at