Boost logo

Boost :

From: Geurt Vos (G.Vos_at_[hidden])
Date: 2001-04-10 07:48:24


>
> This is an unfortunate side effect :(. The operator bool vs. operator
const
> void* debate has been brought up many times, and I am still not fully
decided
> on how it should be handled.
> Perhaps the best way is just to use operator
> bool but with many dead-end declarations so that the user cannot use any
of
> the operators, i.e.,
> template<...>
> bool operator==(const any_function<...>&, const any_function<...>&);
>

As I come to think of it, why not use the 'Modern C++ Design'
approach (it's where I first saw this one)? It could be
something like:

class C {
    class Tester {
        void operator delete(void *);
    };
public:
    operator Tester *() const
    {
        return (f == 0) ? 0 : &Tester();
    }

private:
    SomeType f;

};

now 'delete C();' will issue a compile-timer error.

Geurt


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