Is it technically valid to use mismatched std::allocator
specialization (surely, except its specialization for void
) as a template parameter for STL containers (not all of them, but enumerated below plus unordered_(multi)map/set)? Following code compiles fine.
#include <list>
#include <forward_list>
#include <deque>
#include <set>
#include <map>
int main()
{
struct A { bool operator < (A) const { return true; } };
struct B {};
struct C {};
std::list< A, std::allocator< C > > l;
std::forward_list< A, std::allocator< C > > fl;
std::deque< A, std::allocator< C > > d;
std::set< A, std::less< A >, std::allocator< C > > s;
std::multiset< A, std::less< A >, std::allocator< C > > ms;
std::map< A, B, std::less< A >, std::allocator< C > > m;
std::multimap< A, B, std::less< A >, std::allocator< C > > mm;
}
I believe this is due to allocator being immediately rebound to underlying node type without any relation to its source type.