Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-06-13 13:42:35


I was wondering if we are trying to be too clever with operators.hpp.

The problem I had was that my sizeof==4 class became sizeof==56 when
I switched to using operators.hpp! Hmmm, I thought - I seem to recall
that someone attempted to address this problem, so I hunted through my
emails and found Aleksey Gurtovoy's clever solution.

Next problem - it didn't work with BCB4 because it's a bit
temperamental with bool template parameters.

OK, introduce

  struct true_t {};
  struct false_t {};

and

  s/static const bool value = true/typedef true_t value/
  s/static const bool value = false/typedef false_t value/
  s/bool/class/

and we're up and running.

Oh dear - sizeof(myclass) is still 8. Back to the drawing board.

So then I just restored the original simple operators.hpp and
wrote

    class myclass // lose the inheritance...
    {
        //...
    };
    // explicitly instantiate the operators I need.
    template class less_than_comparable<myclass>;
    template class equality_comparable<myclass>;
    template class incrementable<myclass>;
    template class decrementable<myclass>;
    template class addable<myclass,long>;
    template class subtractable<myclass,long>;

Now everything is less complex, and I've got sizeof(myclass) back
to 4 without relying on any compiler optimisations.

Comments?

Mark


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