Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.7 KiB

  1. #if _MSC_VER > 1000
  2. #pragma once
  3. #endif // _MSC_VER > 1000
  4. template< class Key, class Compare= less<Key>, class Allocator= allocator<Key> >
  5. class set:
  6. public RBTree< Key, Key, identity<Key>, Compare, Allocator>
  7. {
  8. public: // Types
  9. typedef set< Key, Compare, Allocator> set_type;
  10. typedef RBTree< Key, Key, identity<Key>, Compare, Allocator> tree_type;
  11. typedef tree_type::value_type value_type;
  12. typedef tree_type::key_type key_type;
  13. typedef tree_type::key_compare key_compare;
  14. typedef tree_type::key_compare value_compare;
  15. typedef tree_type::pointer pointer;
  16. typedef tree_type::const_pointer const_pointer;
  17. typedef tree_type::reference reference;
  18. typedef tree_type::const_reference const_reference;
  19. typedef tree_type::size_type size_type;
  20. typedef tree_type::difference_type difference_type;
  21. typedef tree_type::iterator iterator;
  22. typedef tree_type::const_iterator const_iterator;
  23. typedef tree_type::reverse_iterator reverse_iterator;
  24. typedef tree_type::const_reverse_iterator const_reverse_iterator;
  25. typedef tree_type::allocator_type allocator_type;
  26. public: // Functions
  27. using tree_type::begin;
  28. using tree_type::end;
  29. using tree_type::rbegin;
  30. using tree_type::rend;
  31. using tree_type::size;
  32. using tree_type::max_size;
  33. using tree_type::empty;
  34. using tree_type::key_comp;
  35. value_compare value_comp() const
  36. { return key_comp(); }
  37. explicit set( const Compare& comp= Compare(),
  38. const Allocator& A= Allocator()): tree_type( comp, identity<Key>(), A)
  39. { }
  40. template< class InputIterator>
  41. set( InputIterator f, InputIterator l, const Compare comp= Compare(),
  42. const Allocator& A= Allocator()): tree_type( comp, identity<Key>(), A)
  43. {
  44. insert_unique( f, l);
  45. }
  46. set( const set_type& Other): tree_type( Other)
  47. { }
  48. ~set()
  49. { }
  50. set_type& operator=( const set_type& Other)
  51. {
  52. tree_type::operator=( Other);
  53. return *this;
  54. }
  55. using tree_type::get_allocator;
  56. void swap( const set_type& Other)
  57. { tree_type::swap( Other); }
  58. pair< iterator, bool> insert( const value_type& x)
  59. { return insert_unique( x); }
  60. iterator insert( iterator pos, const value_type& x)
  61. { return insert_unique( x); }
  62. template< class InputIterator>
  63. void insert( InputIterator f, InputIterator l)
  64. { insert_unique( f, l); }
  65. using tree_type::erase;
  66. using tree_type::find;
  67. using tree_type::count;
  68. using tree_type::lower_bound;
  69. using tree_type::upper_bound;
  70. using tree_type::equal_range;
  71. };
  72. template< class Key, class Compare, class Allocator>
  73. bool operator==( const set< Key, Compare, Allocator>& x,
  74. const set< Key, Compare, Allocator>& y)
  75. {
  76. return x.size()== y.size()&& equal( x.begin(), x.end(), y.begin());
  77. }
  78. template< class Key, class Compare, class Allocator>
  79. bool operator!=( const set< Key, Compare, Allocator>& x,
  80. const set< Key, Compare, Allocator>& y)
  81. {
  82. return !(x== y);
  83. }
  84. template< class Key, class Compare, class Allocator>
  85. bool operator<( const set< Key, Compare, Allocator>& x,
  86. const set< Key, Compare, Allocator>& y)
  87. {
  88. return lexicographical_compare( x.begin(), x.end(), y.begin(), y.end());
  89. }
  90. template< class Key, class Compare, class Allocator>
  91. bool operator>( const set< Key, Compare, Allocator>& x,
  92. const set< Key, Compare, Allocator>& y)
  93. {
  94. return y< x;
  95. }
  96. template< class Key, class Compare, class Allocator>
  97. bool operator<=( const set< Key, Compare, Allocator>& x,
  98. const set< Key, Compare, Allocator>& y)
  99. {
  100. return !(y< x);
  101. }
  102. template< class Key, class Compare, class Allocator>
  103. bool operator>=( const set< Key, Compare, Allocator>& x,
  104. const set< Key, Compare, Allocator>& y)
  105. {
  106. return !(x< y);
  107. }