[multi_index] feature proposal: member keys and typeless specification of keys

Hi all, This is a proposal for inclusion of two new features into Boost.MultiIndex, mem_key and BOOST_MULTI_INDEX_AUTO_KEY. Consider the following: struct foo { int x; int bar(); int baz()const; }; typedef multi_index_container< foo, indexed_by< ordered_unique<member<foo,int,&foo::x> >, ordered_unique<mem_fun<foo,int,&foo::bar> >, ordered_unique<const_mem_fun<foo,int,&foo::baz> > >
multi_t;
Note that we have to use member, mem_fun or const_mem_fun depending on the kind of key used. mem_key allows for a uniform specification syntax: typedef multi_index_container< foo, indexed_by< ordered_unique<mem_key<int foo::*,&foo::x> >, ordered_unique<mem_key<int (foo::*)(),&foo::bar> >, ordered_unique<mem_key<int (foo::*)()const,&foo::baz> > >
multi_t;
This in itself gains us relatively little; but if we have a C++11 compiler with decltype, BOOST_MULTI_INDEX_AUTO_KEY can use mem_key in a way that dispenses with the need for specifying the type of the key! typedef multi_index_container< foo, indexed_by< ordered_unique<BOOST_MULTI_INDEX_AUTO_KEY(&foo::x)>, ordered_unique<BOOST_MULTI_INDEX_AUTO_KEY(&foo::bar)>, ordered_unique<BOOST_MULTI_INDEX_AUTO_KEY(&foo::baz)> >
multi_t;
Some requests and questions: 1. If you're interested in these features, please download the attached mem_key.hpp file, play with it and report on successful/problematic usage. 2. Do you think this is worth including in Boost.MultiIndex? 3. Proposals on the naming scheme? Thank you, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo ________________________________ Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo. This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at. http://www.tid.es/ES/PAGINAS/disclaimer.aspx

Den 08-05-2011 13:31, JOAQUIN M. LOPEZ MUÑOZ skrev:
Hi all,
This is a proposal for inclusion of two new features into Boost.MultiIndex, mem_key and BOOST_MULTI_INDEX_AUTO_KEY.
This in itself gains us relatively little; but if we have a C++11 compiler
with decltype, BOOST_MULTI_INDEX_AUTO_KEY can use mem_key
in a way that dispenses with the need for specifying the type of
the key!
typedef multi_index_container<
foo,
indexed_by<
ordered_unique<BOOST_MULTI_INDEX_AUTO_KEY(&foo::x)>,
ordered_unique<BOOST_MULTI_INDEX_AUTO_KEY(&foo::bar)>,
ordered_unique<BOOST_MULTI_INDEX_AUTO_KEY(&foo::baz)>
>
multi_t;
If we have decltype, then can't we simply say indexed_by< ordered_unique<&foo::x>, ordered_unique<&foo::bar>, ordered_unique<&foo::baz> >
multi_t;
with some modifications to ordered_unique<>? -Thorsten

Thorsten Ottosen <thorsten.ottosen <at> dezide.com> writes:
If we have decltype, then can't we simply say
indexed_by< ordered_unique<&foo::x>, ordered_unique<&foo::bar>, ordered_unique<&foo::baz> >
multi_t;
with some modifications to ordered_unique<>?
I'm afraid this is impossible. What would the type be for the first template paramater of ordered_unique? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Joaquin M Lopez Munoz <joaquin <at> tid.es> writes:
I'm afraid this is impossible. What would the type be for the first template paramater of ordered_unique?
Sorry, I meant "first non-template parameter". Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Den 08-05-2011 16:18, Joaquin M Lopez Munoz skrev:
Joaquin M Lopez Munoz<joaquin<at> tid.es> writes:
I'm afraid this is impossible. What would the type be for the first template paramater of ordered_unique?
Sorry, I meant "first non-template parameter".
Well, I thought c++11 would allow us to deduce return type, argument types and class type of a member function pointer. Wouldn't http://www.boost.org/doc/libs/1_46_1/libs/function_types/doc/html/boost_func... help? -Thorsten

Thorsten Ottosen <thorsten.ottosen <at> dezide.com> writes:
Den 08-05-2011 16:18, Joaquin M Lopez Munoz skrev:
Joaquin M Lopez Munoz<joaquin<at> tid.es> writes:
I'm afraid this is impossible. What would the type be for the first template paramater of ordered_unique?
Sorry, I meant "first non-template parameter".
Well, I thought c++11 would allow us to deduce return type, argument types and class type of a member function pointer.
Wouldn't
http://www.boost.org/doc/libs/1_46_1/libs/function_types/doc/html/boost_func...
help?
You can decompose a pointer to member *type* into its constituents easily enough (even in C++98), but when you write ordered_unique<&foo::x> the entity passed to ordered_unique is not a *type* but a pointer (to a member). That's why you need decltype to do the object-->type magic, and that's why the syntax you propose can't work. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Den 08-05-2011 18:37, Joaquin M Lopez Munoz skrev:
You can decompose a pointer to member *type* into its constituents easily enough (even in C++98), but when you write
ordered_unique<&foo::x>
the entity passed to ordered_unique is not a *type* but a pointer (to a member). That's why you need decltype to do the object-->type magic, and that's why the syntax you propose can't work.
Apologizes for my ignorance. The following compiles fine for me: class Bar { public: int var; }; template< class T, class U> void foo( T U::* ptr ) { } but I see your point. What a pitty the language is a barior here. We simply can't create a class template without adding two arguments for the ruturn type and the class type. Thanks for explaining. Your solution is still pretty nice. -Thorsten
participants (3)
-
Joaquin M Lopez Munoz
-
JOAQUIN M. LOPEZ MUÑOZ
-
Thorsten Ottosen