Boost logo

Boost :

Subject: [boost] [phoenix] Implementing phoenix::make_shared<T>(...)
From: Pyry Jahkola (pyry.jahkola_at_[hidden])
Date: 2011-06-29 07:31:56


Hi, Thomas and other Boosters!

I promised on #boost yesterday to try implementing make_shared<T>(...) for Boost.Phoenix. Well, I got the first version working, it was mostly a find-and-replace task to the existing phoenix::new_<T>(...) implementation. I put the modifications to the current Phoenix trunk version here:

    https://github.com/pyrtsa/boost-svn/commit/b37cb155ff157199a88e59e44f1d8edee12e0bfc

First, the questions, then some remarks and ideas for improvement:

1) If I've understood correctly, you and Hartmut used Wave to generate the preprocessed headers. What command did you use for them? (Currently, I just added a false condition to the preprocessor #if's to fallback to the Boost.Preprocessor iteration.)

2) Where would you put the new make_shared stuff? The first implementation resides below boost/phoenix/object, but I think we should use another directory for all the smart pointer stuff - especially if we're trying to support all of (boost|std::tr1|std)! How about the following pattern?

    boost/phoenix/smart_ptr/... for all Boost.SmartPtr support stuff
    boost/phoenix/tr1/... for TR1 support (alternatively, boost/phoenix/std/tr1)
    boost/phoenix/std/... for C++0x (with #ifdef guards checking against std version)

3) To my pleasant surprise, I didn't need any hacks to create a functor of type

    function<shared_ptr<Parent>()>

using a Phoenix construct like phx::make_shared<Child>(args), where Child inherits Parent. You'll find a working example in https://gist.github.com/1051564. Nevertheless, I think there's also a need for implementing the Phoenix versions of static_pointer_cast etc.

4) Another feature worth implementing might be phoenix::make_unique<T>(...).

5) We also discussed about an API that allows you to make "deep" copies of pointed objects in Phoenix. I think it might already work using something like

    phoenix::make_shared<T>(ref(x))

if x is of type T, or

    phoenix::make_shared<T>(*ref(p))

if p points to T.

6) When we get this far, I'll promise help in the documentation effort too. ;-)

-- 
Pyry Jahkola (pyrtsa @ IRC, Twitter, etc.)
pyry.jahkola_at_[hidden]
+358 40 7529128

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