Boost logo

Boost :

From: David Bergman (davidb_at_[hidden])
Date: 2002-08-13 12:58:58


Dave,

The only plausible way to achieve that compiler warning seems to be to
change the type of the wrapper as a result of the 'def_init', and then
allow the 'def' and other post-construction operations only on that new
type.

Like:

        Template<class X> class inited_class_ : public class_<X> { };

        template<class X> inited_class_<X>& class_::def_init(...);

        template<class X> inited_class_::def(...);

This, would of course, not allow for 'def_init' anywhere in the chain,
but only at the beginning (i.e., before any 'def's...)

If you want it to occur *anywhere* in the chain, then you would probably
need to have a "stopper", such as

        class_<X>("X").def_init(...).def(...). ... .stop();

and define that stop only in "inited_class_"...

But, then again, I have not used Boost.Python and have not either looked
at the virtues of that library, so my input is probably worthless.

/David

-----Original Message-----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of David Abrahams
Sent: Tuesday, August 13, 2002 1:18 PM
To: boost
Subject: [boost] Error if member function not called?

Hi everybody,

I'm looking for a clever trick, if anyone can come up with it...
In v2 of the Boost.Python library, when users define a class wrapper, it
looks something like this:

    class_<X>("X")
        .def_init(args<int, char*>()) // constructor
        .def("foo", &X::foo) // member function
        ;

Each of class_<>'s member functions returns *this to allow the chaining
idiom shown above.

What I'd like is to be able to generate a compiler warning or error if
the
user fails to call the def_init() member function somewhere in the
chain.
Any ideas?

Thanks,
Dave

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com

_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


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