Boost logo

Boost :

Subject: Re: [boost] what is the interest of In Place factory
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-10-29 10:50:48


Am Thursday 29 October 2009 15:35:52 schrieb rodrigue pons:
> Hello,
>
> I was looking about the boost In Place Factory to resolve a problem i
> got, and there is something i don't understand: what is the advantage
> of this lib?
>
>
> For example:
>
> I get a class A, wich constructor is:
> A( int, const string& );
>
> And an another class, C, that contains an A*. C provides a method to
> construct this A*:
> void C::BuildA( int i, const string & str );
>
> wich will be called this way:
> instance_of_C.BuildA( 1, "test" );
>
>
> If now i use the boost In Place Factory, the member function C::BuildA
> will become:
>
> template<class InPlaceFactoryT>
> void C::BuildA( InPlaceFactoryT const& factory )
>
> wich will be called this way:
> instance_of_C.BuildA( 1, "test" );
>
>
> We can see here that with or wothout the In Place Factory, the code is
> exactly the same. So i guess there is something i didn't understand.
> But what?

the type of A might be unknown to the author of C, i.e. dependent on a
template parameter. so C cannot know the number and types of parameters to
the constructor of A.
see boost::optional<> for a use case.


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