
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?

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.

Haaa okay i see. Thank you :) 2009/10/29 Stefan Strasser <strasser@uni-bremen.de>:
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. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
rodrigue pons
-
Stefan Strasser