Boost logo

Boost :

From: Jesse Jones (jesjones_at_[hidden])
Date: 2001-04-18 18:13:21


> > 3) The check_invariants class is overly complex and does heap
>> allocations which is pretty nasty. You can fix that by using that
>> voodoo I mentioned earlier:
>> class check_invariants {
>> public:
>> template <typename T>
>> check_invariants(const T* object) {
>> _object = object;
>> _invoker = invoke<T>;
>> _invoker(_object, true);
>> }
>> ~check_invariants() {
>> _invoker(_object, false);
>> }
>>
>> template <class T>
> > static void invoke(const void* object, bool entering) {
> > void (T::*method)(bool) const = &T::check_invariants;
> > (static_cast<const T*>(object)->*method)(entering);
>> }
>>
>> private:
>> void (*_invoker)(const void*, bool);
>> const void* _object;
>> };
>
>Actually, this is at least as ugly ;). I didn't care for the memory
>allocation, however, and this solution is nicer in this regard.
>

Well at least the ugliness has been squeezed into one little ball.
:-) The memory allocation is pretty big though. It'd be pretty icky
if every call to a public function hit the heap.

   -- Jesse


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