Using a slightly modified version of Howard Hinnants's C++11 stack allocator which is documented here and here, with std::basic_string
and compiling with gcc
which is using libstdc++
, the following example (see it live):
const unsigned int N = 200;
arena<N> a;
short_alloc<char, N> ac(a) ;
std::basic_string<char,std::char_traits<char>,short_alloc<char, N>> empty(ac);
gives the following error(amongst others):
error: no matching function for call to 'short_alloc<char, 200ul>::short_alloc()'
if (__n == 0 && __a == _Alloc())
^
However it works without error when compiling with clang
and using libc++
(see it live).
The stdlibc++
implementation of std::basic_string
expects the allocator to have a default constructor.
Does C++11 require allocators to be default constructible? Which implementation is correct?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…