fork download
  1. #include <map>
  2.  
  3. template<typename T>
  4. class TestAllocator;
  5.  
  6. template<>
  7. class TestAllocator<void>
  8. {
  9. public:
  10. typedef void * pointer;
  11. typedef const void * const_pointer;
  12. typedef void value_type;
  13. typedef size_t size_type;
  14. typedef ptrdiff_t difference_type;
  15. //typedef T & reference; not possible for void
  16. //typedef const T & const_reference; not possible for void
  17.  
  18. template<typename U>
  19. struct rebind
  20. {
  21. typedef TestAllocator<U> other;
  22. };
  23. };
  24.  
  25. template<typename T>
  26. class TestAllocator
  27. {
  28. public:
  29. typedef T * pointer;
  30. typedef const T * const_pointer;
  31. typedef T & reference;
  32. typedef const T & const_reference;
  33. typedef T value_type;
  34. typedef size_t size_type;
  35. typedef ptrdiff_t difference_type;
  36.  
  37. template<typename U>
  38. struct rebind
  39. {
  40. typedef TestAllocator<U> other;
  41. };
  42. };
  43.  
  44. struct Foo
  45. {
  46. int a, b;
  47. bool operator <(const Foo &r) const
  48. {
  49. return a < r.a;
  50. }
  51. };
  52.  
  53. struct Bar { float a, b; };
  54.  
  55. typedef std::map<
  56. Foo, Bar,
  57. TestAllocator<void>
  58. > TestContainer;
  59.  
  60. int main()
  61. {
  62. TestContainer x;
  63. x.insert(TestContainer::value_type(Foo(), Bar()));
  64. return 0;
  65. }
  66.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/map:60:0,
                 from prog.cpp:1:
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_tree.h: In member function 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(const _Val&) [with _Key = Foo, _Val = std::pair<const Foo, Bar>, _KeyOfValue = std::_Select1st<std::pair<const Foo, Bar> >, _Compare = TestAllocator<void>, _Alloc = std::allocator<std::pair<const Foo, Bar> >]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_map.h:501:41:   instantiated from 'std::pair<typename std::map<_Key, _Tp, _Compare, _Alloc>::_Rep_type::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const std::map<_Key, _Tp, _Compare, _Alloc>::value_type&) [with _Key = Foo, _Tp = Bar, _Compare = TestAllocator<void>, _Alloc = std::allocator<std::pair<const Foo, Bar> >, typename std::map<_Key, _Tp, _Compare, _Alloc>::_Rep_type::iterator = std::_Rb_tree_iterator<std::pair<const Foo, Bar> >, std::map<_Key, _Tp, _Compare, _Alloc>::value_type = std::pair<const Foo, Bar>]'
prog.cpp:63:53:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_tree.h:1184:4: error: no match for call to '(TestAllocator<void>) (const std::pair<const Foo, Bar>::first_type&, const Foo&)'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_map.h:501:41:   instantiated from 'std::pair<typename std::map<_Key, _Tp, _Compare, _Alloc>::_Rep_type::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const std::map<_Key, _Tp, _Compare, _Alloc>::value_type&) [with _Key = Foo, _Tp = Bar, _Compare = TestAllocator<void>, _Alloc = std::allocator<std::pair<const Foo, Bar> >, typename std::map<_Key, _Tp, _Compare, _Alloc>::_Rep_type::iterator = std::_Rb_tree_iterator<std::pair<const Foo, Bar> >, std::map<_Key, _Tp, _Compare, _Alloc>::value_type = std::pair<const Foo, Bar>]'
prog.cpp:63:53:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_tree.h:1195:7: error: no match for call to '(TestAllocator<void>) (const Foo&, const std::pair<const Foo, Bar>::first_type&)'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_tree.h: In member function 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_(const std::_Rb_tree_node_base*, const std::_Rb_tree_node_base*, const _Val&) [with _Key = Foo, _Val = std::pair<const Foo, Bar>, _KeyOfValue = std::_Select1st<std::pair<const Foo, Bar> >, _Compare = TestAllocator<void>, _Alloc = std::allocator<std::pair<const Foo, Bar> >, std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const Foo, Bar> >, const std::_Rb_tree_node_base* = const std::_Rb_tree_node_base*]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_tree.h:1191:65:   instantiated from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(const _Val&) [with _Key = Foo, _Val = std::pair<const Foo, Bar>, _KeyOfValue = std::_Select1st<std::pair<const Foo, Bar> >, _Compare = TestAllocator<void>, _Alloc = std::allocator<std::pair<const Foo, Bar> >]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_map.h:501:41:   instantiated from 'std::pair<typename std::map<_Key, _Tp, _Compare, _Alloc>::_Rep_type::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const std::map<_Key, _Tp, _Compare, _Alloc>::value_type&) [with _Key = Foo, _Tp = Bar, _Compare = TestAllocator<void>, _Alloc = std::allocator<std::pair<const Foo, Bar> >, typename std::map<_Key, _Tp, _Compare, _Alloc>::_Rep_type::iterator = std::_Rb_tree_iterator<std::pair<const Foo, Bar> >, std::map<_Key, _Tp, _Compare, _Alloc>::value_type = std::pair<const Foo, Bar>]'
prog.cpp:63:53:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_tree.h:897:25: error: no match for call to '(TestAllocator<void>) (const std::pair<const Foo, Bar>::first_type&, const Foo&)'
stdout
Standard output is empty