[multi-index] No constructor that takes allocator only
Joaquín, thanks so much for a wonderful library. I was wondering why there is no constructor that simply takes an allocator. This would make multi_index behave more like STD Library containers, which would aid me in allowing flexible storage options for generic algorithms. Is there a technical hurdle that makes this difficult to do? You currently provide: explicit multi_index_container( const ctor_args_list& args_list=ctor_args_list(), const allocator_type& al=allocator_type()); template<typename InputIterator> multi_index_container( InputIterator first,InputIterator last, const ctor_args_list& args_list=ctor_args_list(), const allocator_type& al=allocator_type()); Is it possible to also provide: explicit multi_index_container( const allocator_type& al=allocator_type()); ? Thanks again! --Michael Fawcett
Michael Fawcett ha escrito:
Joaquín, thanks so much for a wonderful library. I was wondering why there is no constructor that simply takes an allocator. This would make multi_index behave more like STD Library containers, which would aid me in allowing flexible storage options for generic algorithms.
Is there a technical hurdle that makes this difficult to do? You currently provide:
explicit multi_index_container( const ctor_args_list& args_list=ctor_args_list(), const allocator_type& al=allocator_type());
template<typename InputIterator> multi_index_container( InputIterator first,InputIterator last, const ctor_args_list& args_list=ctor_args_list(), const allocator_type& al=allocator_type());
Is it possible to also provide:
explicit multi_index_container( const allocator_type& al=allocator_type());
?
Hello Michael, Not all STL containers provide an allocator ctor (associative containers don't), which is the implicit reason why I didn't include it (I followed std::set's interface in the initial designs). That said, I don't see any technical problem in providing that ctor, so I'm putting it in my todo list for the next release (Boost 1.36, I'm afraid). Thanks for using Boost.MultiIndex, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
On Jan 30, 2008 12:48 PM, Joaquín Mª López Muñoz
Not all STL containers provide an allocator ctor (associative containers don't),
Ah, sorry for the blanket statement (I had been using vector and list as my test structures thus far). Do you know the rational or historical reasons for not including those ctors in the associative containers?
which is the implicit reason why I didn't include it (I followed std::set's interface in the initial designs). That said, I don't see any technical problem in providing that ctor, so I'm putting it in my todo list for the next release (Boost 1.36, I'm afraid).
Excellent news, I appreciate it! --Michael Fawcett
Michael Fawcett
On Jan 30, 2008 12:48 PM, Joaquín Mª López Muñoz
wrote: Not all STL containers provide an allocator ctor (associative containers don't),
Ah, sorry for the blanket statement (I had been using vector and list as my test structures thus far). Do you know the rational or historical reasons for not including those ctors in the associative containers?
Umm... Well, there's a theoretic possibility that we hit ambiguity: set(const Compare&=Compare(),const Allocator&=Allocator()); set(const Allocator&); What happens if Compare is the same type as Allocator? The possibility of this happening in the real world is close to zero, but theoretically it is possible: template<typename T> struct less_and_allocator: public std::allocator<T>, public std::less<T> { }; typedef std::set< int, less_and_allocator<int>, less_and_allocator<int>
paradoxical_set;
I'm holding your proposal in my todo list, but I have to think it over a bit. Thank you, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
On Jan 30, 2008 3:06 PM, Joaquin M Lopez Munoz
Umm... Well, there's a theoretic possibility that we hit ambiguity:
set(const Compare&=Compare(),const Allocator&=Allocator()); set(const Allocator&);
That explains it perfectly, thanks.
I'm holding your proposal in my todo list, but I have to think it over a bit.
I trust you'll come to the best decision. Really it comes down to what customization point is more often used (since the interface will favor that), and that is invariably the compare parameter. My original suggestion should probably be ignored in favor of keeping with the set interface. As an aside, does Boost.MultiIndex model any existing Boost concepts (e.g. AssociativeContainer)? http://www.boost.org/libs/concept_check/reference.htm#container-concepts I found some documentation here ( http://www.boost.org/libs/multi_index/doc/tutorial/techniques.html#emulate_s... ) , that hints it might, but no explicit mention of modeling Concepts. --Michael Fawcett
----- Mensaje original -----
De: Michael Fawcett
On Jan 30, 2008 3:06 PM, Joaquin M Lopez Munoz
wrote: I'm holding your proposal in my todo list, but I have to think it over a bit.
I trust you'll come to the best decision. Really it comes down to what customization point is more often used (since the interface will favor that), and that is invariably the compare parameter. My original suggestion should probably be ignored in favor of keeping with the set interface.
It's possible that both ctors could be provided, because the situation for multi_index_container is not entirely equivalent to that of std::set. I'll keep you informed.
As an aside, does Boost.MultiIndex model any existing Boost concepts (e.g. AssociativeContainer)?
http://www.boost.org/libs/concept_check/ reference.htm#container-concepts I found some documentation here ( http://www.boost.org/libs/multi_index/doc/tutorial/ techniques.html#emulate_std_containers ) , that hints it might, but no explicit mention of modeling Concepts.
Well, the answer is, in general, no. multi_index_containers certainly model Container, but nothing beyond that (Sequence or AssociativeContainer) for a variety of possible reasons: * Index #0 (as you know, multi_index_containers inherit the public interface of that index) might have some slight deviations from the interface of the corresponding container: for instance, sequenced indices are like std::lists, but push_back() and other memfuns have a different signature. * Elements are immutable (unlike standard Sequences). * Insertion semantics depends on every and each index comprising the multi_index_container, not only index #0. * Same for operation complexities: insertion, erasure, etc. So, you can get close to modelling a given Concept, but not strictly there. About the only exact match you've got is the emulation of std::set described at the section you refer to above. HTH, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (4)
-
"JOAQUIN LOPEZ MU?Z"
-
Joaquin M Lopez Munoz
-
Joaquín Mª López Muñoz
-
Michael Fawcett