|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
what is the interest of In Place factoryHello,
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? _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost |
|
|
Re: what is the interest of In Place factoryAm 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 |
|
|
Re: what is the interest of In Place factoryHaaa okay i see.
Thank you :) 2009/10/29 Stefan Strasser <strasser@...>: > 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 > Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost |
| Free embeddable forum powered by Nabble | Forum Help |