Eigen::aligned_allocator fails with std::unordered_multimap
Asked Answered
B

1

6

I am trying to compile this code in XCode 6:

std::unordered_multimap< Frame*, Sim3, std::hash<Frame*>, std::equal_to<Frame*>, Eigen::aligned_allocator< std::pair<const Frame*,Sim3> > > trackingFailed;

It fails with:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/unordered_map:1461:5: Static_assert failed "Invalid allocator::value_type"

Is it still necessary to use aligned_allocator in Eigen 3.2.2? Why is it failing with C++11/C++14 and libc++?

EDIT:

I get no type named value_type if I remove the Eigen allocator from the unordered_map template declaration.

Bobbette answered 6/12, 2014 at 21:47 Comment(0)
S
10

I believe the mistake is that the pointer should be const, not the pointee.
I.e. try Eigen::aligned_allocator< std::pair<Frame* const, Sim3> > as the allocator type.

Schlesinger answered 6/12, 2014 at 21:49 Comment(7)
Thanks a lot! The error was totally misleading. This is not my code and it was used in other projects, don't understand how it compiled for them? Maybe the GNU compiler is less strict?Bobbette
@Bobbette Perhaps libstdc++ does not static_assert that the value type of the allocator must be the same as the value type of the container.Schlesinger
I see. It seems Clang/libc++ are not forgiving about C++11 constructs (from my little experience).Bobbette
@Columbo, right, libstdc++ allows e.g. vector<int, allocator<char>> and it rebinds the allocator to the correct type. I hate this extension, I would like to deprecate it!Zeitgeist
Found another one: std::vector< KFConstraintStruct*, Eigen::aligned_allocator<FramePoseStruct*> > I really don't know how it compiled that, these two structs are completely separate.Bobbette
@aledalgrande, read my comment above. Libstdc++ ignores the exact type of the allocator and rebinds it to the container's value type. gcc.gnu.org/bugzilla/show_bug.cgi?id=21770Zeitgeist
Oh it ignores it completely. Wow.Bobbette

© 2022 - 2024 — McMap. All rights reserved.