Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't std types provide conversion constructor / assignment from sources differing in allocator

For example, why doesn't template< typename Elem, typename Traits, typename Alloc > basic_string { ... } provide:

template< typename OtherAlloc >
basic_string( const basic_string< Elem, Traits, OtherAlloc >& a_Other ) { ... }

It would seem fairly trivial to implement such a conversion constructor which respects both allocators. The current state of affair makes it very cumbersome to interface between types just differing in allocators.

like image 714
Ylisar Avatar asked Sep 20 '26 17:09

Ylisar


1 Answers

The Standard hash also does not permit allocator fun- it can hash std::string and std::wstring but not std::basic_string<char, std::char_traits<char>, custom_alloc>. In addition, you cannot create an unordered_map or unordered_set with just an allocator- you must also provide a bucket number, which defaults to an implementation-defined constant you can't access, so you effectively must just make something up. The support, generally, is not very good.

It seems to me that, relatively simply, nobody proposed such a function or explored this use space.

like image 113
Puppy Avatar answered Sep 23 '26 06:09

Puppy