[extension] factory_map::get() suggestion

Currently, there is no typedef to provide a convenient way to create variables of the return type of boost::extensions::factory_map::get(). For example, right now I have to do this: factory_map fm; std::map<int, factory<word> > & factory_list = fm.get<word, int>(); It would be ideal to do this instead: factory_map fm; factory_map::type& factory_list = fm.get<word, int>(); Could this be done?

Robert, Yep! Good idea. I'll take care of it. Jeremy On Thu, Jul 3, 2008 at 3:55 PM, Robert Dailey <rcdailey@gmail.com> wrote:
Currently, there is no typedef to provide a convenient way to create variables of the return type of boost::extensions::factory_map::get(). For example, right now I have to do this:
factory_map fm; std::map<int, factory<word> > & factory_list = fm.get<word, int>();
It would be ideal to do this instead:
factory_map fm; factory_map::type& factory_list = fm.get<word, int>();
Could this be done? _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

AMDG Jeremy Pack wrote:
Yep! Good idea. I'll take care of it.
For example, right now I have to do this:
factory_map fm; std::map<int, factory<word> > & factory_list = fm.get<word, int>();
It would be ideal to do this instead:
factory_map fm; factory_map::type& factory_list = fm.get<word, int>();
Is it really that easy? Doesn't the result of get depend on the particular template arguments? I don't quite see how you can get away with a single typedef. In Christ, Steven Watanabe

Steven, Yeah, it isn't quite that simple. I read the original post too quickly and thought he was referring to a different function. I originally had a type for that std::map<int, factory<word> >, so it would be something like type_factory_map<int, word>, which isn't much terser. (thus, I removed it) I think the best solution here is to make your own typedefs for your specific case. There are a couple of other places in the library though where I intend to add the type of typedefs suggested. Jeremy On Thu, Jul 3, 2008 at 5:26 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Jeremy Pack wrote:
Yep! Good idea. I'll take care of it.
For example, right now I have to do this:
factory_map fm; std::map<int, factory<word> > & factory_list = fm.get<word, int>();
It would be ideal to do this instead:
factory_map fm; factory_map::type& factory_list = fm.get<word, int>();
Is it really that easy? Doesn't the result of get depend on the particular template arguments? I don't quite see how you can get away with a single typedef.
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On Thu, Jul 3, 2008 at 7:36 PM, Jeremy Pack <rostovpack@gmail.com> wrote:
Steven,
Yeah, it isn't quite that simple. I read the original post too quickly and thought he was referring to a different function.
I originally had a type for that std::map<int, factory<word> >, so it would be something like type_factory_map<int, word>, which isn't much terser. (thus, I removed it)
I think the best solution here is to make your own typedefs for your specific case.
There are a couple of other places in the library though where I intend to add the type of typedefs suggested.
Jeremy
On Thu, Jul 3, 2008 at 5:26 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Jeremy Pack wrote:
Yep! Good idea. I'll take care of it.
For example, right now I have to do this:
factory_map fm; std::map<int, factory<word> > & factory_list = fm.get<word, int>();
It would be ideal to do this instead:
factory_map fm; factory_map::type& factory_list = fm.get<word, int>();
Is it really that easy? Doesn't the result of get depend on the particular template arguments? I don't quite see how you can get away with a single typedef.
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Why not turn factory_map::get() into a template utility class of some sort instead of a function? That would give you the ability to typedef the std::map. Perhaps another option is to do the following: factory_map<word, int>::get() I don't have time right now to give any reasonable ideas, but those are just some thoughts off the top of my head. Later on I may try to help find an alternative to this. All I know for sure is that exposing std::map seems like an implementation detail, and specifying the same template parameters more than once also bothers me slightly.

AMDG Robert Dailey wrote:
Why not turn factory_map::get() into a template utility class of some sort instead of a function? That would give you the ability to typedef the std::map. Perhaps another option is to do the following:
<snip>
All I know for sure is that exposing std::map seems like an implementation detail, and specifying the same template parameters more than once also bothers me slightly.
I kind of like the idea of allowing type_factory_map<word, int> factory_list(fm); In Christ, Steven Watanabe

----- Original Message ----- From: "Robert Dailey" <rcdailey@gmail.com> To: <boost@lists.boost.org> Sent: Friday, July 04, 2008 2:49 AM Subject: Re: [boost] [extension] factory_map::get() suggestion
On Thu, Jul 3, 2008 at 7:36 PM, Jeremy Pack <rostovpack@gmail.com> wrote:
Steven,
Yeah, it isn't quite that simple. I read the original post too quickly and thought he was referring to a different function.
I originally had a type for that std::map<int, factory<word> >, so it would be something like type_factory_map<int, word>, which isn't much terser. (thus, I removed it)
I think the best solution here is to make your own typedefs for your specific case.
There are a couple of other places in the library though where I intend to add the type of typedefs suggested.
Jeremy
On Thu, Jul 3, 2008 at 5:26 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Jeremy Pack wrote:
Yep! Good idea. I'll take care of it.
For example, right now I have to do this:
factory_map fm; std::map<int, factory<word> > & factory_list = fm.get<word, int>();
It would be ideal to do this instead:
factory_map fm; factory_map::type& factory_list = fm.get<word, int>();
Is it really that easy? Doesn't the result of get depend on the particular template arguments? I don't quite see how you can get away with a single typedef.
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Why not turn factory_map::get() into a template utility class of some sort instead of a function? That would give you the ability to typedef the std::map. Perhaps another option is to do the following:
factory_map<word, int>::get()
I don't have time right now to give any reasonable ideas, but those are just some thoughts off the top of my head. Later on I may try to help find an alternative to this. All I know for sure is that exposing std::map seems like an implementation detail, and specifying the same template parameters more than once also bothers me slightly. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Hello, Maybe you are thinking on something like: struct factory_map { template <typename A, typename B> struct getter { typedef std::map<A, factory<B> > type; static type& apply(factory_map&fm){return fm.get<A,B>();} }; }; factory_map fm; typedef factory_map::getter<word, int> factory_map_getter; factory_map_getter::type& factory_list = factory_map_getter::apply(fm); Vicente

I'm not picking on vicente; this is a reminder to everyone: on Fri Jul 04 2008, "vicente.botet" <vicente.botet-AT-wanadoo.fr> wrote: <snip entire foregoing thread> Please see http://www.boost.org/community/policy.html#effective and limit the amount of quoted text if possible. Thanks!
Hello,
Maybe you are thinking on something like:
struct factory_map { template <typename A, typename B> struct getter { typedef std::map<A, factory<B> > type; static type& apply(factory_map&fm){return fm.get<A,B>();} }; }; factory_map fm; typedef factory_map::getter<word, int> factory_map_getter; factory_map_getter::type& factory_list = factory_map_getter::apply(fm);
Vicente
-- Dave Abrahams BoostPro Computing http://www.boostpro.com

From: "David Abrahams" <dave@boostpro.com> Sent: Friday, July 04, 2008 11:30 PM Subject: [boost] ** please try to limit quoting **
I'm not picking on vicente; this is a reminder to everyone:
Please see http://www.boost.org/community/policy.html#effective and limit the amount of quoted text if possible.
You are right Dave, I have not taken the time to remove the non concened lines. I'll take care next times. Vicente

Looking back at my code, I realized that I had provided similar functionality, but never tested it. I had a bug in the logic, which I have fixed. You can actually write the following: factory_map fm; std::map<int, factory<word> >& factory_list(fm); It's similar to Steven's suggestion, though it doesn't use a separate class for the map type. An alternative would be something like this: factory_map fm; std::map<int, factory<word> >* factory_list_ptr; std::map<int, factory<word> > factory_list_copy; fm.get(factory_list_ptr); // now factory_list_ptr points to the internal map. fm.get(factory_list_copy); // now factory_list_copy has a copy of the internal map. Any preferences? Jeremy On Fri, Jul 4, 2008 at 1:50 PM, vicente.botet <vicente.botet@wanadoo.fr> wrote:
----- Original Message ----- From: "Robert Dailey" <rcdailey@gmail.com> To: <boost@lists.boost.org> Sent: Friday, July 04, 2008 2:49 AM Subject: Re: [boost] [extension] factory_map::get() suggestion
On Thu, Jul 3, 2008 at 7:36 PM, Jeremy Pack <rostovpack@gmail.com> wrote:
Steven,
Yeah, it isn't quite that simple. I read the original post too quickly and thought he was referring to a different function.
I originally had a type for that std::map<int, factory<word> >, so it would be something like type_factory_map<int, word>, which isn't much terser. (thus, I removed it)
I think the best solution here is to make your own typedefs for your specific case.
There are a couple of other places in the library though where I intend to add the type of typedefs suggested.
Jeremy
On Thu, Jul 3, 2008 at 5:26 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Jeremy Pack wrote:
Yep! Good idea. I'll take care of it.
For example, right now I have to do this:
factory_map fm; std::map<int, factory<word> > & factory_list = fm.get<word, int>();
It would be ideal to do this instead:
factory_map fm; factory_map::type& factory_list = fm.get<word, int>();
Is it really that easy? Doesn't the result of get
depend on the particular template arguments? I don't quite see how you can get away with a single typedef.
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Why not turn factory_map::get() into a template utility class of some sort instead of a function? That would give you the ability to typedef the std::map. Perhaps another option is to do the following:
factory_map<word, int>::get()
I don't have time right now to give any reasonable ideas, but those are just some thoughts off the top of my head. Later on I may try to help find an alternative to this. All I know for sure is that exposing std::map seems like an implementation detail, and specifying the same template parameters more than once also bothers me slightly. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Hello,
Maybe you are thinking on something like:
struct factory_map { template <typename A, typename B> struct getter { typedef std::map<A, factory<B> > type; static type& apply(factory_map&fm){return fm.get<A,B>();} }; }; factory_map fm; typedef factory_map::getter<word, int> factory_map_getter; factory_map_getter::type& factory_list = factory_map_getter::apply(fm);
Vicente
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (5)
-
David Abrahams
-
Jeremy Pack
-
Robert Dailey
-
Steven Watanabe
-
vicente.botet