moya-lang / Allocator

Ultra fast C++11 allocator for STL containers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error with g++ list insert

plus2047 opened this issue · comments

This code fail when compile with g++, but it works well with clang++.

string hello = "hello";
list<char, Moya::Allocator<char>> s;
s.insert(s.end(), hello.begin(), hello.end());
// but it works if you do s.insert(s.end(), 'a')

Here is the error message,

In file included from prog_joined.cpp:1:
In file included from ./precompiled/headers.h:48:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/list:63:
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_list.h:933:16: error: no matching conversion for functional-style cast from 'const std::__cxx11::_List_base<char, Moya::Allocator<char, 1024>>::_Node_alloc_type' (aka 'const Allocator<std::_List_node<char>, 1024UL>') to 'std::__cxx11::list<char, Moya::Allocator<char, 1024>>::allocator_type' (aka 'Moya::Allocator<char, 1024>')
      { return allocator_type(_Base::_M_get_Node_allocator()); }
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/list.tcc:137:30: note: in instantiation of member function 'std::__cxx11::list<char, Moya::Allocator<char, 1024>>::get_allocator' requested here
        list __tmp(__first, __last, get_allocator());
                                    ^
Line 185: Char 11: note: in instantiation of function template specialization 'std::__cxx11::list<char, Moya::Allocator<char, 1024>>::insert<__gnu_cxx::__normal_iterator<char *, std::__cxx11::basic_string<char>>, void>' requested here
        s.insert(iter, text.begin(), text.end());
          ^
Line 82: Char 7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const Allocator<std::_List_node<char>, [...]>' to 'const Allocator<char, [...]>' for 1st argument
class Allocator : private MemoryPool<T, growSize>
      ^
Line 82: Char 7: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided

I try to fix it by myself but fail. could you help to have a look?

I'll look at it soon. Thank you for commenting.

Thx for idea, a small remark:
Allocator(Allocator &allocator) - is not copy constructor, const is missed.
maybe everything works without a copy constructor? or did I not understand something?