moya-lang / Allocator

Ultra fast C++11 allocator for STL containers.
BSD 2-Clause "Simplified" License
270 stars 25 forks source link

compile error of map with allocator #12

Closed Frandy closed 2 years ago

Frandy commented 4 years ago

Hi, I got below error when compile with make command, would you please help check it? g++ --std=c++17 -Wall Measure.cpp -O3 -o Measure In file included from /usr/include/c++/9/map:61, from Measure.cpp:6: /usr/include/c++/9/bits/stl_map.h: In instantiation of ‘class std::map<int, int, std::less, Moya::Allocator<int, 1024> >’: Measure.cpp:24:19: required from ‘class PerformanceTest<std::map<int, int, std::less, Moya::Allocator<int, 1024> > >’ Measure.cpp:81:7: required from ‘class MapTest<std::map<int, int, std::less, Moya::Allocator<int, 1024> > >’ Measure.cpp:140:85: required from here /usr/include/c++/9/bits/stl_map.h:122:71: error: static assertion failed: std::map must have the same value_type as its allocator 122 | static_assert(is_same<typename _Alloc::value_type, value_type>::value, | ^~~~~ make: *** [Makefile:2: default,] Error 1

moya-mmoczala commented 4 years ago

Sure, I'll look into this soon. Thanks for reporting.

VincentMcLoughlin commented 4 years ago

Hello, I've also received this error, but I noticed it appears with g++ (GCC) 9.2.0 but NOT with g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11).

Frandy commented 4 years ago

ok, thank you.

brettf1200 commented 3 years ago

The problem with the std::map test is that std:map has value_type std::pair<const Key, Value>.

The way the test case is set up, this ultimately becomes std::pair<const DataType, DataType> but, Allocator is parameterized as Allocator<DataType, growSize> which results in a value_type of DataType. To make this code run, Allocator's DataType argument needs to be std::pair<const DataType, DataType> as shown:

MapTest<std::map<DataType, DataType, std::less<DataType>, Moya::Allocator<std::pair<const DataType, DataType>, growSize>>> mapTestFast;

You can also do template magic like so: MapTest<std::map<DataType, DataType, std::less, Moya::Allocator<std::map<DataType, DataType>::value_type, growSize>>> mapTestFast;

Of course this can simplified with some typedefs which is left as an exercise to the reader. :-)

nedo99 commented 3 years ago

Hi,

Same issue here with the addition of many: /root/ORB_SLAM2/src/Tracking.cc:1512:13: error: ‘usleep’ was not declared in this scope 1512 | usleep(3000);

A similar issue is reported here: https://github.com/raulmur/ORB_SLAM2/issues/957

The setup used: Ubuntu 20.04 G++ 9.3.0

Is there a chance that this bug will be addressed?

Regards, Nedim

moya-mmoczala commented 2 years ago

Hi, the issue has been solved. Thank you @brettf1200 for your help!