0

I have boost map with the definition as below:

typedef std::pair< int,complex_data > map_value_type;
typedef boost::interprocess::allocator<map_value_typemanaged_shared_memory::segment_manager> map_value_type_allocator;
typedef boost::interprocess::map<  int, complex_data, std::less<  int>,map_value_type_allocator > complex_map_type;

I took the code from http://www.boost.org/doc/libs/1_49_0/doc/html/interprocess/allocators_containers.html#interprocess.allocators_containers.containers_explained.containers_of_containers and replaced the keys with integers. However I am getting the following error i can not resolve:

/usr/include/boost/container/map.hpp:147:1: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE<false>’

If I replace the keys the code seems to work fine. Can anyone see what the problem is here?

Lukas Schmelzeisen
  • 2,934
  • 4
  • 24
  • 30
godzilla
  • 3,005
  • 7
  • 44
  • 60
  • Is your real code also missing a `,` from the definition of `map_value_type_allocator`? – Mike Seymour Jun 25 '12 at 12:36
  • It is a static assertion that is triggered, have you bothered looking at the code/error message on what is actually asserted? – PlasmaHH Jun 25 '12 at 12:40
  • If I simply "replace the keys with integers", then it compiles without error: http://ideone.com/XkhLp (although that gives link errors due to libraries not being available at ideone). Could you post your code so we can see where it's gone wrong? – Mike Seymour Jun 25 '12 at 12:43
  • Please post a complete example that reproduces the problem. – n. m. could be an AI Jun 25 '12 at 12:44
  • using the example in the above i have managed to reverse engineer and resolve the problem - is it possible to have an unsigned int as the key? – godzilla Jun 25 '12 at 13:09
  • @godzilla: You can use any type as the key, as long as two values can be compared using either `<` or a custom comparator. Certainly, any integer type is fine. – Mike Seymour Jun 25 '12 at 14:10
  • thanks god it working, it turns out the key must be a const! – godzilla Jun 27 '12 at 12:52

1 Answers1

1

The error message is familiar to those with experience in C++ template programming. Ignore the sizeof part; the clue is in boost::STATIC_ASSERTION_FAILURE<false>. That type shouldn't be instantiated, you want boost::STATIC_ASSERTION_FAILURE<true>. But what exact expression is used as the template argument?

Your template instantiation error should have an instantiation stack, which leads from your code to the failure. Presumably it's checking

MSalters
  • 173,980
  • 10
  • 155
  • 350