48 #ifndef BIMAP_H_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761 49 #define BIMAP_H_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761 50 #define VERSION_BIMAP_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761 0x00010002 53 #pragma warning(disable:4786) 69 #if defined(__GNUC__)&&(__GNUC__>3||(__GNUC__==3&&__GNUC_MINOR__>= 1)) 70 #define BIMAP_OFFSETOF_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(type,member) \ 75 reinterpret_cast<size_t>( \ 76 reinterpret_cast<const char*>( \ 84 #define BIMAP_OFFSETOF_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(type,member) offsetof(type,member) 92 #if defined(_MSC_VER)&&_MSC_VER==1200 93 #define BIMAP_REBIND_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(type1,type2) type1 95 #define BIMAP_REBIND_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(type1,type2) \ 96 typename type1::template rebind<type2>::other 101 namespace bimap_detail{
111 typedef char equal_types_yes;
115 equal_types_yes equal_types_helper(T,T);
116 template <
typename T>
119 static const T* make();
127 sizeof(equal_types_yes))};
141 template<
class then,
class els>
struct result 149 template<
class then,
class els>
struct result 165 template<
bool test,
typename then,
typename els>
169 typedef typename sel::template result<then,els>::type result;
183 #if defined(_MSC_VER)&&_MSC_VER>=1300 184 #pragma warning(push) 185 #pragma warning(disable:4512) 189 template<
typename first_type,
typename second_type>
192 template<
typename first_type_,
typename second_type_>
195 typedef first_type_ first_type;
196 typedef second_type_ second_type;
201 inv_pair():second(second_type()),first(first_type()){}
202 inv_pair(
const first_type& first,
const second_type& second):second(second),first(first){}
203 inv_pair(
const std::pair<first_type,second_type>& r):second(r.second),first(r.first){}
204 template<
typename F,
typename S>
218 template<
typename first_type,
typename second_type>
219 struct direct_pair:
public std::pair<first_type,second_type>
222 typedef std::pair<first_type,second_type> super;
226 direct_pair(
const first_type& first,
const second_type& second):super(first,second){}
228 template<
typename F,
typename S>
229 direct_pair(
const std::pair<F,S>& r):super(r.first,r.second){}
242 #if defined(_MSC_VER)&&_MSC_VER>=1300 246 template<
typename first_type,
typename second_type>
248 const first_type& first,
249 const second_type& second)
258 template<
typename first_type,
typename second_type>
263 return x.first==y.first&&x.second==y.second;
266 template<
typename first_type,
typename second_type>
269 const std::pair<first_type,second_type>& y)
271 return x.first==y.first&&x.second==y.second;
274 template<
typename first_type,
typename second_type>
276 const std::pair<first_type,second_type>& x,
279 return x.first==y.first&&x.second==y.second;
284 template<
typename first_type,
typename second_type>
292 template<
typename first_type,
typename second_type>
295 const std::pair<first_type,second_type>& y)
300 template<
typename first_type,
typename second_type>
302 const std::pair<first_type,second_type>& x,
310 template<
typename first_type,
typename second_type>
315 return x.first<y.first||x.first==y.first&&x.second<y.second;
318 template<
typename first_type,
typename second_type>
321 const std::pair<first_type,second_type>& y)
323 return x.first<y.first||x.first==y.first&&x.second<y.second;
326 template<
typename first_type,
typename second_type>
328 const std::pair<first_type,second_type>& x,
331 return x.first<y.first||x.first==y.first&&x.second<y.second;
336 template<
typename first_type,
typename second_type>
344 template<
typename first_type,
typename second_type>
347 const std::pair<first_type,second_type>& y)
352 template<
typename first_type,
typename second_type>
354 const std::pair<first_type,second_type>& x,
362 template<
typename first_type,
typename second_type>
370 template<
typename first_type,
typename second_type>
373 const std::pair<first_type,second_type>& y)
378 template<
typename first_type,
typename second_type>
380 const std::pair<first_type,second_type>& x,
388 template<
typename first_type,
typename second_type>
396 template<
typename first_type,
typename second_type>
399 const std::pair<first_type,second_type>& y)
404 template<
typename first_type,
typename second_type>
406 const std::pair<first_type,second_type>& x,
437 template<
typename bimap_type>
441 from_binding(bimap_type& bm,
const typename bimap_type::from_type& f):bm(bm),f(f){}
443 const typename bimap_type::to_type&
get()
const 445 typename bimap_type::from_set::const_iterator it=bm.fset.find(&f);
447 return bimap_type::element_by_from(*it)->second;
450 operator const typename bimap_type::to_type&()
const 455 from_binding& operator=(
const typename bimap_type::to_type& t)
461 typedef typename bimap_type::element bimap_element;
463 typename bimap_type::fset_iterator fit=bm.fset.find(&f);
464 typename bimap_type::tset_iterator tit=bm.tset.find(&t);
465 if(tit!=bm.tset.end()){
467 if(fit!=bm.fset.end()&&
468 bimap_type::element_by_from(*fit)==bimap_type::element_by_to(*tit)){
474 bimap_element * pne=0;
475 typename bimap_type::tset_iterator tnit=bm.tset.end();
477 pne=bm.new_element(bimap_element(f,t));
478 tnit=bm.tset.insert(&pne->second).first;
479 if(fit==bm.fset.end()){
480 bm.fset.insert(&pne->first);
484 bimap_element * pe=bimap_type::element_by_from(*fit);
485 bm.tset.erase(bm.tset.find(&pe->second));
486 bm.delete_element(pe);
487 const_cast<typename bimap_type::from_type *&
>(*fit)=
488 &
const_cast<typename bimap_type::from_type &
>(pne->first);
492 if(tnit!=bm.tset.end())bm.tset.erase(tnit);
493 if(pne)bm.delete_element(pne);
502 const typename bimap_type::from_type f;
505 template<
typename bimap_type>
513 const typename bimap_type::to_type&
get()
const 515 typename bimap_type::from_set::const_iterator it=bm.fset.find(&f);
517 return bimap_type::element_by_from(*it)->second;
520 operator const typename bimap_type::to_type&()
const 528 const bimap_type& bm;
529 const typename bimap_type::from_type f;
532 template<
typename bimap_type>
536 to_binding(bimap_type& bm,
const typename bimap_type::to_type& t):bm(bm),t(t){}
538 const typename bimap_type::from_type&
get()
const 540 typename bimap_type::to_set::const_iterator it=bm.tset.find(&t);
542 return bimap_type::element_by_to(*it)->first;
545 operator const typename bimap_type::from_type&()
const 550 to_binding& operator=(
const typename bimap_type::from_type& f)
556 typedef typename bimap_type::element bimap_element;
558 typename bimap_type::tset_iterator tit=bm.tset.find(&t);
559 typename bimap_type::fset_iterator fit=bm.fset.find(&f);
560 if(fit!=bm.fset.end()){
562 if(tit!=bm.tset.end()&&
563 bimap_type::element_by_to(*tit)==bimap_type::element_by_from(*fit)){
569 bimap_element * pne=0;
570 typename bimap_type::fset_iterator fnit=bm.fset.end();
572 pne=bm.new_element(bimap_element(f,t));
573 fnit=bm.fset.insert(&pne->first).first;
574 if(tit==bm.tset.end()){
575 bm.tset.insert(&pne->second);
579 bimap_element * pe=bimap_type::element_by_to(*tit);
580 bm.fset.erase(bm.fset.find(&pe->first));
581 bm.delete_element(pe);
582 const_cast<typename bimap_type::to_type *&
>(*tit)=
583 &
const_cast<typename bimap_type::to_type &
>(pne->second);
587 if(fnit!=bm.fset.end())bm.fset.erase(fnit);
588 if(pne)bm.delete_element(pne);
597 const typename bimap_type::to_type t;
600 template<
typename bimap_type>
604 const_to_binding(
const bimap_type& bm,
const typename bimap_type::to_type& t):
608 const typename bimap_type::from_type&
get()
const 610 typename bimap_type::to_set::const_iterator it=bm.tset.find(&t);
612 return bimap_type::element_by_to(*it)->first;
615 operator const typename bimap_type::from_type&()
const 623 const bimap_type& bm;
624 const typename bimap_type::to_type t;
634 typename from_type_,
typename to_type_,
635 typename from_compare,
typename to_compare,
636 typename allocator_type_>
645 typedef from_type_ from_type;
646 typedef to_type_ to_type;
648 template<
typename type,
typename compare>
651 p_compare(
const compare& c=compare()):c(c){}
652 bool operator()(
const type* p1,
const type* p2)
const{
return c(*p1,*p2);}
653 compare get_compare()
const{
return c;}
663 BIMAP_REBIND_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(allocator_type_,
const from_type*)>
670 BIMAP_REBIND_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(allocator_type_,
const to_type*)>
672 typedef typename from_set::allocator_type fset_allocator_type;
673 typedef typename to_set::allocator_type tset_allocator_type;
674 typedef typename from_set::iterator fset_iterator;
675 typedef typename from_set::const_iterator const_fset_iterator;
676 typedef typename to_set::iterator tset_iterator;
677 typedef typename to_set::const_iterator const_tset_iterator;
681 allocator_type_ allocator;
691 element * new_element(
const element& e)
693 element * pe=allocator.allocate(1,0);
695 allocator.construct(pe,e);
697 allocator.destroy(pe);
703 void delete_element(element *pe)
705 allocator.destroy(pe);
706 allocator.deallocate(pe,1);
709 static element * element_by_from(
const from_type* pf)
712 reinterpret_cast<element*
>(
713 reinterpret_cast<char*
>(
714 const_cast<from_type *
>(pf))-
715 BIMAP_OFFSETOF_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(element,first));
718 static element * element_by_to(
const to_type* pt)
721 reinterpret_cast<element *
>(
722 reinterpret_cast<char*
>(
723 const_cast<to_type *
>(pt))-
724 BIMAP_OFFSETOF_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(element,second));
747 return size()==r.size()&&std::equal(begin(),end(),r.begin());
758 std::lexicographical_compare(
759 begin(),end(),r.begin(),r.end());
779 typedef from_type_ key_type;
780 typedef to_type_ mapped_type;
781 typedef to_type_ referent_type;
782 typedef to_type_ data_type;
783 typedef from_compare key_compare;
784 typedef allocator_type_ allocator_type;
797 bool operator()(
const value_type& x,
const value_type& y)
799 if(kcomp(x.first,y.first))
return true;
800 if(kcomp(y.first,x.first))
return false;
801 return tcomp(x.second,y.second);
804 value_compare(key_compare kcomp,to_compare tcomp):kcomp(kcomp),tcomp(tcomp){}
809 typedef typename allocator_type_::size_type size_type;
810 typedef typename allocator_type_::difference_type difference_type;
819 class iterator:
public std::iterator<std::bidirectional_iterator_tag,const value_type>
823 friend class prebimap<from_type,to_type,from_compare,to_compare,allocator_type>;
825 #if defined(_MSC_VER)&&_MSC_VER==1200 828 typedef const value_type& reference;
837 typename reference operator*()
const{
return *element_by_from(*fit);}
838 typename value_type * operator->()
const{
return &operator*();}
840 typename iterator::reference operator*()
const{
return *element_by_from(*fit);}
841 typename iterator::value_type * operator->()
const{
return &operator*();}
844 iterator& operator++(){++fit;
return *
this;}
845 const iterator operator++(
int){
const iterator tmp=*
this;++*
this;
return tmp;}
846 iterator& operator--(){--fit;
return *
this;}
847 const iterator operator--(
int){
const iterator tmp=*
this;--*
this;
return tmp;}
848 bool operator==(
const iterator& it)
const{
return fit==it.fit;}
849 bool operator!=(
const iterator& it)
const{
return !(*
this==it);}
851 iterator(
const fset_iterator& fit):fit(fit){}
855 class const_iterator:
public std::iterator<std::bidirectional_iterator_tag,const value_type>
858 friend class prebimap<from_type,to_type,from_compare,to_compare,allocator_type>;
860 #if defined(_MSC_VER)&&_MSC_VER==1200 863 typedef const value_type& reference;
879 typename reference operator*()
const{
return *element_by_from(*fit);}
880 const typename value_type * operator->()
const{
return &operator*();}
882 typename const_iterator::reference operator*()
const{
return *element_by_from(*fit);}
883 const typename const_iterator::value_type * operator->()
const{
return &operator*();}
890 bool operator==(
const const_iterator& it)
const{
return fit==it.fit;}
891 bool operator!=(
const const_iterator& it)
const{
return !(*
this==it);}
894 const_fset_iterator fit;
897 #if defined(_MSC_VER)&&_MSC_VER==1200 899 std::reverse_bidirectional_iterator<
904 difference_type> reverse_iterator;
906 typedef std::reverse_iterator<const_iterator> reverse_iterator;
909 typedef reverse_iterator const_reverse_iterator;
914 const_iterator begin()
const{
return const_iterator(owner().fset.begin());}
916 const_iterator end()
const{
return const_iterator(owner().fset.end());}
918 reverse_iterator rbegin(){
return reverse_iterator(end());}
919 const_reverse_iterator rbegin()
const{
return const_reverse_iterator(end());}
920 reverse_iterator rend(){
return reverse_iterator(begin());}
921 const_reverse_iterator rend()
const{
return const_reverse_iterator(begin());}
925 size_type size()
const{
return owner().fset.size();}
926 size_type max_size()
const{
return owner().fset.max_size();}
927 bool empty()
const{
return owner().fset.empty();}
928 allocator_type get_allocator()
const{
return owner().allocator;}
933 operator[](
const from_type_& f)
941 operator[](
const from_type_& f)
const 950 std::pair<iterator,bool> insert(
const value_type& x)
952 fset_iterator fit=owner().fset.find(&x.first);
953 if(fit!=owner().fset.end()){
954 return std::make_pair(
iterator(fit),
false);
956 tset_iterator tit=owner().tset.find(&x.second);
960 tset_iterator tnit=owner().tset.end();
961 fset_iterator fnit=owner().fset.end();
963 pe=owner().new_element(x);
964 tnit=owner().tset.insert(&pe->second).first;
965 fnit=owner().fset.insert(&pe->first).first;
967 if(tnit!=owner().tset.end())owner().tset.erase(tnit);
968 if(pe)owner().delete_element(pe);
971 return std::make_pair(
iterator(fnit),
true);
976 if(!adjacent(it.fit,x.first))
return insert(x).first;
978 tset_iterator tit=owner().tset.find(&x.second);
982 tset_iterator tnit=owner().tset.end();
983 fset_iterator fnit=owner().fset.end();
985 pe=owner().new_element(x);
986 tnit=owner().tset.insert(&pe->second).first;
987 fnit=owner().fset.insert(it.fit,&pe->first);
989 if(tnit!=owner().tset.end())owner().tset.erase(tnit);
990 if(pe)owner().delete_element(pe);
996 template<
typename it_type>
997 void insert(it_type first,it_type last)
1015 fset_iterator& fit=it.fit;
1016 element * pe=element_by_from(*fit);
1017 tset_iterator tit=owner().tset.find(&pe->second);
1018 owner().delete_element(pe);
1019 owner().tset.erase(tit);
1020 return(
iterator(owner().fset.erase(fit)));
1025 fset_iterator& fit=it.fit;
1026 element * pe=element_by_from(*fit);
1027 tset_iterator tit=owner().tset.find(&pe->second);
1028 owner().delete_element(pe);
1029 owner().tset.erase(tit);
1030 owner().fset.erase(fit);
1036 while(first!=last)erase(first++);
1039 size_type erase(
const key_type& key)
1041 fset_iterator fit=owner().fset.find(&key);
1042 if(fit==owner().fset.end())
return 0;
1043 element * pe=element_by_from(*fit);
1044 owner().tset.erase(owner().tset.find(&pe->second));
1045 owner().fset.erase(fit);
1046 owner().delete_element(pe);
1052 erase(begin(),end());
1059 owner().fset.swap(x.owner().fset);
1060 owner().tset.swap(x.owner().tset);
1065 key_compare key_comp()
const 1067 return owner().fset.key_comp().get_compare();
1074 owner().fset.key_comp().get_compare(),
1075 owner().tset.key_comp().get_compare());
1080 return iterator(owner().fset.find(&key));
1083 const_iterator find(
const key_type& key)
const 1085 return const_iterator(owner().fset.find(&key));
1088 size_type count(
const key_type& key)
const 1090 return owner().fset.count(&key);
1093 iterator lower_bound(
const key_type& key)
1095 return iterator(owner().fset.lower_bound(&key));
1098 const_iterator lower_bound(
const key_type& key)
const 1100 return const_iterator(owner().fset.lower_bound(&key));
1103 iterator upper_bound(
const key_type& key)
1105 return iterator(owner().fset.upper_bound(&key));
1108 const_iterator upper_bound(
const key_type& key)
const 1110 return const_iterator(owner().fset.upper_bound(&key));
1113 std::pair<iterator,iterator> equal_range(
const key_type& key)
1115 return std::make_pair(lower_bound(key),upper_bound(key));
1118 std::pair<const_iterator,const_iterator> equal_range(
const key_type& key)
const 1120 return std::make_pair(lower_bound(key),upper_bound(key));
1129 return *
reinterpret_cast<prebimap*
>(
1130 reinterpret_cast<char*
>(
this)-
1131 BIMAP_OFFSETOF_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(
prebimap,
from));
1135 return *
reinterpret_cast<const prebimap*
>(
1136 reinterpret_cast<const char*
>(
this)-
1137 BIMAP_OFFSETOF_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(
prebimap,
from));
1140 bool adjacent(const_fset_iterator fit,
const from_type_& f)
const 1142 if(fit==owner().fset.end()){
1143 if(owner().fset.size()==0)
return true;
1144 const_fset_iterator fit2=fit;
1146 return owner().fset.key_comp()(*fit2,&f);
1148 else if(owner().fset.key_comp()(&f,*fit)){
1149 if(fit==owner().fset.begin())
return true;
1150 const_fset_iterator fit2=fit;
1152 return owner().fset.key_comp()(*fit2,&f);
1155 else if(owner().fset.key_comp()(*fit,&f)){
1156 const_fset_iterator fit2=fit;
1158 if(fit2==owner().fset.end())
return true;
1159 return owner().fset.key_comp()(&f,*fit2);
1169 friend class prebimap<from_type_,to_type_,from_compare,to_compare,allocator_type_>;
1199 prebimap tmp(r.owner());
1206 bool operator==(
const to_impl& r)
const 1208 return size()==r.size()&&std::equal(begin(),end(),r.begin());
1211 bool operator!=(
const to_impl& r)
const 1216 bool operator<(
const to_impl& r)
const 1219 std::lexicographical_compare(
1220 begin(),end(),r.begin(),r.end());
1223 bool operator>(
const to_impl& r)
const 1228 bool operator<=(
const to_impl& r)
const 1233 bool operator>=(
const to_impl& r)
const 1240 typedef to_type_ key_type;
1241 typedef from_type_ mapped_type;
1242 typedef from_type_ referent_type;
1243 typedef from_type_ data_type;
1244 typedef to_compare key_compare;
1245 typedef allocator_type_ allocator_type;
1254 bool operator()(
const value_type& x,
const value_type& y)
1256 if(kcomp(x.first,y.first))
return true;
1257 if(kcomp(y.first,x.first))
return false;
1258 return fcomp(x.second,y.second);
1261 value_compare(key_compare kcomp,from_compare fcomp):kcomp(kcomp),fcomp(fcomp){}
1266 typedef typename allocator_type_::size_type size_type;
1267 typedef typename allocator_type_::difference_type difference_type;
1276 class iterator:
public std::iterator<std::bidirectional_iterator_tag,const value_type>
1280 friend class prebimap<from_type,to_type,from_compare,to_compare,allocator_type>;
1282 #if defined(_MSC_VER)&&_MSC_VER==1200 1285 typedef const value_type& reference;
1293 typename reference operator*()
const{
return *element_by_to(*tit);}
1294 typename value_type * operator->()
const{
return &operator*();}
1296 typename iterator::reference operator*()
const{
return *element_by_to(*tit);}
1297 typename iterator::value_type * operator->()
const{
return &operator*();}
1300 iterator& operator++(){++tit;
return *
this;}
1301 const iterator operator++(
int){
const iterator tmp=*
this;++*
this;
return tmp;}
1302 iterator& operator--(){--tit;
return *
this;}
1303 const iterator operator--(
int){
const iterator tmp=*
this;--*
this;
return tmp;}
1304 bool operator==(
const iterator& it)
const{
return tit==it.tit;}
1305 bool operator!=(
const iterator& it)
const{
return !(*
this==it);}
1307 iterator(
const tset_iterator& tit):tit(tit){}
1311 class const_iterator:
public std::iterator<std::bidirectional_iterator_tag,const value_type>
1314 friend class prebimap<from_type,to_type,from_compare,to_compare,allocator_type>;
1316 #if defined(_MSC_VER)&&_MSC_VER==1200 1319 typedef const value_type& reference;
1326 #if _MSC_VER >= 1400 1336 typename reference operator*()
const{
return *element_by_to(*tit);}
1337 const typename value_type * operator->()
const{
return &operator*();}
1339 typename const_iterator::reference operator*()
const{
return *element_by_to(*tit);}
1340 const typename const_iterator::value_type * operator->()
const{
return &operator*();}
1347 bool operator==(
const const_iterator& it)
const{
return tit==it.tit;}
1348 bool operator!=(
const const_iterator& it)
const{
return !(*
this==it);}
1351 const_tset_iterator tit;
1354 #if defined(_MSC_VER)&&_MSC_VER==1200 1356 std::reverse_bidirectional_iterator<
1361 difference_type> reverse_iterator;
1363 typedef std::reverse_iterator<const_iterator> reverse_iterator;
1366 typedef reverse_iterator const_reverse_iterator;
1371 const_iterator begin()
const{
return const_iterator(owner().tset.begin());}
1373 const_iterator end()
const{
return const_iterator(owner().tset.end());}
1375 reverse_iterator rbegin(){
return reverse_iterator(end());}
1376 const_reverse_iterator rbegin()
const{
return const_reverse_iterator(end());}
1377 reverse_iterator rend(){
return reverse_iterator(begin());}
1378 const_reverse_iterator rend()
const{
return const_reverse_iterator(begin());}
1382 size_type size()
const{
return owner().tset.size();}
1383 size_type max_size()
const{
return owner().tset.max_size();}
1384 bool empty()
const{
return owner().tset.empty();}
1385 allocator_type get_allocator()
const{
return owner().allocator;}
1390 operator[](
const to_type_& t)
1398 operator[](
const to_type_& t)
const 1407 std::pair<iterator,bool> insert(
const value_type& x)
1409 tset_iterator tit=owner().tset.find(&x.first);
1410 if(tit!=owner().tset.end()){
1411 return std::make_pair(
iterator(tit),
false);
1413 fset_iterator fit=owner().fset.find(&x.second);
1417 fset_iterator fnit=owner().fset.end();
1418 tset_iterator tnit=owner().tset.end();
1420 pe=owner().new_element(x);
1421 fnit=owner().fset.insert(&pe->first).first;
1422 tnit=owner().tset.insert(&pe->second).first;
1424 if(fnit!=owner().fset.end())owner().fset.erase(fnit);
1425 if(pe)owner().delete_element(pe);
1428 return std::make_pair(
iterator(tnit),
true);
1433 if(!adjacent(it.tit,x.first))
return insert(x).first;
1435 fset_iterator fit=owner().fset.find(&x.second);
1439 fset_iterator fnit=owner().fset.end();
1440 tset_iterator tnit=owner().tset.end();
1442 pe=owner().new_element(x);
1443 fnit=owner().fset.insert(&pe->first).first;
1444 tnit=owner().tset.insert(it.tit,&pe->second);
1446 if(fnit!=owner().fset.end())owner().fset.erase(fnit);
1447 if(pe)owner().delete_element(pe);
1453 template<
typename it_type>
1454 void insert(it_type first,it_type last)
1468 tset_iterator& tit=it.tit;
1469 element * pe=element_by_to(*tit);
1470 fset_iterator fit=owner().fset.find(&pe->first);
1471 owner().delete_element(pe);
1472 owner().fset.erase(fit);
1473 return(
iterator(owner().tset.erase(tit)));
1478 tset_iterator& tit=it.tit;
1479 element * pe=element_by_to(*tit);
1480 fset_iterator fit=owner().fset.find(&pe->first);
1481 owner().delete_element(pe);
1482 owner().fset.erase(fit);
1483 owner().tset.erase(tit);
1489 while(first!=last)erase(first++);
1492 size_type erase(
const key_type& key)
1494 tset_iterator tit=owner().tset.find(&key);
1495 if(tit==owner().tset.end())
return 0;
1496 element * pe=element_by_to(*tit);
1497 owner().fset.erase(owner().fset.find(&pe->first));
1498 owner().tset.erase(tit);
1499 owner().delete_element(pe);
1505 erase(begin(),end());
1512 owner().tset.swap(x.owner().tset);
1513 owner().fset.swap(x.owner().fset);
1518 key_compare key_comp()
const 1520 return owner().tset.key_comp().get_compare();
1527 owner().tset.key_comp().get_compare(),
1528 owner().fset.key_comp().get_compare());
1533 return iterator(owner().tset.find(&key));
1536 const_iterator find(
const key_type& key)
const 1538 return const_iterator(owner().tset.find(&key));
1541 size_type count(
const key_type& key)
const 1543 return owner().tset.count(&key);
1546 iterator lower_bound(
const key_type& key)
1548 return iterator(owner().tset.lower_bound(&key));
1551 const_iterator lower_bound(
const key_type& key)
const 1553 return const_iterator(owner().tset.lower_bound(&key));
1556 iterator upper_bound(
const key_type& key)
1558 return iterator(owner().tset.upper_bound(&key));
1561 const_iterator upper_bound(
const key_type& key)
const 1563 return const_iterator(owner().tset.upper_bound(&key));
1566 std::pair<iterator,iterator> equal_range(
const key_type& key)
1568 return std::make_pair(lower_bound(key),upper_bound(key));
1571 std::pair<const_iterator,const_iterator> equal_range(
const key_type& key)
const 1573 return std::make_pair(lower_bound(key),upper_bound(key));
1582 return *
reinterpret_cast<prebimap*
>(
1583 reinterpret_cast<char*
>(
this)-
1584 BIMAP_OFFSETOF_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(prebimap,
to));
1586 const prebimap& owner()
const 1588 return *
reinterpret_cast<const prebimap*
>(
1589 reinterpret_cast<const char*
>(
this)-
1590 BIMAP_OFFSETOF_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761(prebimap,
to));
1593 bool adjacent(const_tset_iterator tit,
const to_type_& t)
const 1595 if(tit==owner().tset.end()){
1596 if(owner().tset.size()==0)
return true;
1597 const_tset_iterator tit2=tit;
1599 return owner().tset.key_comp()(*tit2,&t);
1601 else if(owner().tset.key_comp()(&t,*tit)){
1602 if(tit==owner().tset.begin())
return true;
1603 const_tset_iterator tit2=tit;
1605 return owner().tset.key_comp()(*tit2,&t);
1608 else if(owner().tset.key_comp()(*tit,&t)){
1609 const_tset_iterator tit2=tit;
1611 if(tit2==owner().tset.end())
return true;
1612 return owner().tset.key_comp()(&t,*tit2);
1622 friend class prebimap<from_type_,to_type_,from_compare,to_compare,allocator_type_>;
1625 friend void swap(
to& x,
to& y)
1648 std::pair<typename from::iterator,typename to::iterator>
1653 if(!
from.adjacent(fit.fit,x.first)){
1654 fit=fset.find(&x.first);
1655 if(fit!=fset.end()){
1656 tset_iterator tnit=tset.find(&x.second);
1657 if(tnit!=tset.end()&&element_by_from(*(fit.fit))==element_by_to(*tnit)){
1664 if(!
to.adjacent(tit.tit,x.second)){
1665 tit=tset.find(&x.second);
1671 tset_iterator tnit=tset.begin();
1672 fset_iterator fnit=fset.begin();
1675 tnit=tset.insert(tit.tit,&pe->second);
1676 fnit=fset.insert(fit.fit,&pe->first);
1678 if(tnit!=tset.end())tset.erase(tnit);
1679 if(pe)delete_element(pe);
1687 const from_compare& from_comp,
1688 const to_compare& to_comp,
1689 const allocator_type_& al):
1691 fset(p_compare<from_type,from_compare>(from_comp),fset_allocator_type(allocator)),
1692 tset(p_compare<to_type,to_compare>(to_comp),tset_allocator_type(allocator))
1695 prebimap(
const prebimap& r):
1696 allocator(r.allocator),
1697 fset(r.fset.key_comp(),fset_allocator_type(allocator)),
1698 tset(r.tset.key_comp(),tset_allocator_type(allocator))
1702 #if defined(_MSC_VER)&&_MSC_VER==1200 1710 insert(fhint,thint,*it);
1716 std::pair<typename from::iterator,typename to::iterator>
1717 p=insert(fhint,thint,*it);
1731 for(fset_iterator it=fset.begin();it!=fset.end();++it){
1732 delete_element(element_by_from(*it));
1745 typename from_type,
typename to_type,
1746 typename from_compare,
typename to_compare,
1747 typename allocator_type>
1748 struct prebimap_identity
1758 typename from_type_,
typename to_type_,
1759 typename from_compare,
typename to_compare,
1760 typename allocator_type_>
1764 public prebimap_identity<from_type_,to_type_,from_compare,to_compare,allocator_type_>::type
1766 public prebimap<from_type_,to_type_,from_compare,to_compare,allocator_type_>
1774 typedef typename super::to::value_type to_value_type;
1775 typedef typename super::to::iterator to_iterator;
1778 typedef typename super::from::key_type key_type;
1779 typedef typename super::from::mapped_type mapped_type;
1780 typedef typename super::from::referent_type referent_type;
1781 typedef typename super::from::data_type data_type;
1782 typedef typename super::from::key_compare key_compare;
1783 typedef typename super::from::allocator_type allocator_type;
1784 typedef typename super::from::value_type value_type;
1785 typedef typename super::from::value_compare value_compare;
1786 typedef typename super::from::size_type size_type;
1787 typedef typename super::from::difference_type difference_type;
1788 typedef typename super::from::pointer pointer;
1789 typedef typename super::from::const_pointer const_pointer;
1790 typedef typename super::from::reference reference;
1791 typedef typename super::from::const_reference const_reference;
1792 typedef typename super::from::iterator iterator;
1793 typedef typename super::from::const_iterator const_iterator;
1794 typedef typename super::from::reverse_iterator reverse_iterator;
1795 typedef typename super::from::const_reverse_iterator const_reverse_iterator;
1797 iterator begin(){
return from.begin();}
1798 const_iterator begin()
const{
return from.begin();}
1799 iterator end(){
return from.end();}
1800 const_iterator end()
const{
return from.end();}
1801 reverse_iterator rbegin(){
return from.rbegin();}
1802 const_reverse_iterator rbegin()
const{
return from.rbegin();}
1803 reverse_iterator rend(){
return from.rend();}
1804 const_reverse_iterator rend()
const{
return from.rend();}
1805 size_type size()
const{
return from.size();}
1806 size_type max_size()
const{
return from.max_size();}
1807 bool empty()
const{
return from.empty();}
1808 allocator_type get_allocator()
const{
return from.get_allocator();}
1809 from_binding_t operator[](
const key_type& key){
return from[key];}
1810 const_from_binding_t operator[](
const key_type& key)
const{
return from[key];}
1811 using super::insert;
1812 std::pair<iterator,bool> insert(
const value_type& x){
return from.insert(x);}
1813 iterator insert(iterator it,
const value_type& x){
return from.insert(it,x);}
1816 void insert(it_type first,it_type last){
from.insert(first,last);}
1819 iterator erase(iterator it){
return from.erase(it);}
1821 void erase(iterator it){
from.erase(it);}
1824 void erase(iterator first,iterator last){
from.erase(first,last);}
1825 size_type erase(
const key_type& key){
return from.erase(key);}
1826 void clear(){
from.clear();}
1829 key_compare key_comp()
const{
return from.key_comp();}
1830 value_compare value_comp()
const{
return from.value_comp();}
1831 iterator find(
const key_type& key){
return from.find(key);}
1832 const_iterator find(
const key_type& key)
const{
return from.find(key);}
1833 size_type count(
const key_type& key)
const{
return from.count(key);}
1834 iterator lower_bound(
const key_type& key){
return from.lower_bound(key);}
1835 const_iterator lower_bound(
const key_type& key)
const{
return from.lower_bound(key);}
1836 iterator upper_bound(
const key_type& key){
return from.upper_bound(key);}
1837 const_iterator upper_bound(
const key_type& key)
const{
return from.upper_bound(key);}
1840 iterator> equal_range(
const key_type& key){
return from.equal_range(key);}
1843 const_iterator> equal_range(
const key_type& key)
const{
return from.equal_range(key);}
1849 bool> insert(
const to_value_type& x){
return to.insert(x);}
1850 to_iterator insert(to_iterator it,
const to_value_type& x){
return to.insert(it,x);}
1851 void insert(
const to_value_type *first,
const to_value_type *last)
1852 {
to.insert(first,last);}
1855 to_iterator erase(to_iterator it){
return to.erase(it);}
1857 void erase(to_iterator it){
to.erase(it);}
1860 void erase(to_iterator first,to_iterator last){
to.erase(first,last);}
1864 const from_compare& from_comp,
1865 const to_compare& to_comp,
1866 const allocator_type_& al):
1867 super(from_comp,to_comp,al)
1879 typename from_type_,
typename to_type_,
1880 typename from_compare,
typename to_compare,
1881 typename allocator_type_>
1885 public prebimap_identity<from_type_,to_type_,from_compare,to_compare,allocator_type_>::type
1887 public prebimap<from_type_,to_type_,from_compare,to_compare,allocator_type_>
1897 typedef typename super::to::key_type to_key_type;
1898 typedef typename super::to::value_type to_value_type;
1899 typedef typename super::to::iterator to_iterator;
1900 typedef typename super::to::const_iterator const_to_iterator;
1903 typedef typename super::from::key_type key_type;
1904 typedef typename super::from::mapped_type mapped_type;
1905 typedef typename super::from::referent_type referent_type;
1906 typedef typename super::from::data_type data_type;
1907 typedef typename super::from::key_compare key_compare;
1908 typedef typename super::from::allocator_type allocator_type;
1909 typedef typename super::from::value_type value_type;
1910 typedef typename super::from::value_compare value_compare;
1911 typedef typename super::from::size_type size_type;
1912 typedef typename super::from::difference_type difference_type;
1913 typedef typename super::from::pointer pointer;
1914 typedef typename super::from::const_pointer const_pointer;
1915 typedef typename super::from::reference reference;
1916 typedef typename super::from::const_reference const_reference;
1917 typedef typename super::from::iterator iterator;
1918 typedef typename super::from::const_iterator const_iterator;
1919 typedef typename super::from::reverse_iterator reverse_iterator;
1920 typedef typename super::from::const_reverse_iterator const_reverse_iterator;
1922 iterator begin(){
return from.begin();}
1923 const_iterator begin()
const{
return from.begin();}
1924 iterator end(){
return from.end();}
1925 const_iterator end()
const{
return from.end();}
1926 reverse_iterator rbegin(){
return from.rbegin();}
1927 const_reverse_iterator rbegin()
const{
return from.rbegin();}
1928 reverse_iterator rend(){
return from.rend();}
1929 const_reverse_iterator rend()
const{
return from.rend();}
1930 size_type size()
const{
return from.size();}
1931 size_type max_size()
const{
return from.max_size();}
1932 bool empty()
const{
return from.empty();}
1933 allocator_type get_allocator()
const{
return from.get_allocator();}
1934 from_binding_t operator[](
const key_type& key){
return from[key];}
1935 const_from_binding_t operator[](
const key_type& key)
const{
return from[key];}
1936 using super::insert;
1937 std::pair<iterator,bool> insert(
const value_type& x){
return from.insert(x);}
1938 iterator insert(iterator it,
const value_type& x){
return from.insert(it,x);}
1941 void insert(it_type first,it_type last){
from.insert(first,last);}
1944 iterator erase(iterator it){
return from.erase(it);}
1946 void erase(iterator it){
from.erase(it);}
1949 void erase(iterator first,iterator last){
from.erase(first,last);}
1950 size_type erase(
const key_type& key){
return from.erase(key);}
1951 void clear(){
from.clear();}
1955 key_compare key_comp()
const{
return from.key_comp();}
1956 value_compare value_comp()
const{
return from.value_comp();}
1957 iterator find(
const key_type& key){
return from.find(key);}
1958 const_iterator find(
const key_type& key)
const{
return from.find(key);}
1959 size_type count(
const key_type& key)
const{
return from.count(key);}
1960 iterator lower_bound(
const key_type& key){
return from.lower_bound(key);}
1961 const_iterator lower_bound(
const key_type& key)
const{
return from.lower_bound(key);}
1962 iterator upper_bound(
const key_type& key){
return from.upper_bound(key);}
1963 const_iterator upper_bound(
const key_type& key)
const{
return from.upper_bound(key);}
1966 iterator> equal_range(
const key_type& key){
return from.equal_range(key);}
1969 const_iterator> equal_range(
const key_type& key)
const{
return from.equal_range(key);}
1973 to_binding_t operator[](
const to_key_type& key){
return to[key];}
1974 const_to_binding_t operator[](
const to_key_type& key)
const{
return to[key];}
1977 bool> insert(
const to_value_type& x){
return to.insert(x);}
1978 to_iterator insert(to_iterator it,
const to_value_type& x){
return to.insert(it,x);}
1979 void insert(
const to_value_type *first,
const to_value_type *last)
1980 {
to.insert(first,last);}
1983 to_iterator erase(to_iterator it){
return to.erase(it);}
1985 void erase(to_iterator it){
to.erase(it);}
1988 void erase(to_iterator first,to_iterator last){
to.erase(first,last);}
1989 size_type erase(
const to_key_type& key){
return to.erase(key);}
1990 to_iterator find(
const to_key_type& key){
return to.find(key);}
1991 const_to_iterator find(
const to_key_type& key)
const{
return to.find(key);}
1992 size_type count(
const to_key_type& key)
const{
return to.count(key);}
1993 to_iterator lower_bound(
const to_key_type& key){
return to.lower_bound(key);}
1994 const_to_iterator lower_bound(
const to_key_type& key)
const{
return to.lower_bound(key);}
1995 to_iterator upper_bound(
const to_key_type& key){
return to.upper_bound(key);}
1996 const_to_iterator upper_bound(
const to_key_type& key)
const{
return to.upper_bound(key);}
1999 to_iterator> equal_range(
const to_key_type& key){
return to.equal_range(key);}
2002 const_to_iterator> equal_range(
const to_key_type& key)
const{
return to.equal_range(key);}
2006 const from_compare& from_comp,
2007 const to_compare& to_comp,
2008 const allocator_type_& al):
2009 super(from_comp,to_comp,al)
2021 typename from_type_,
typename to_type_,
2022 typename from_compare=std::less<from_type_>,
2023 typename to_compare=std::less<to_type_>,
2024 typename allocator_type=std::allocator<direct_pair<const from_type_,const to_type_> > >
2028 bimap_detail::equal_types<from_type_,to_type_>::value,
2030 from_type_,to_type_,
2031 from_compare,to_compare,allocator_type>,
2032 bimap_different_types<
2033 from_type_,to_type_,
2034 from_compare,to_compare,allocator_type>
2042 from_type_,to_type_,
2043 from_compare,to_compare,allocator_type>,
2045 from_type_,to_type_,
2046 from_compare,to_compare,allocator_type>
2052 const from_compare& from_comp=from_compare(),
2053 const to_compare& to_comp=to_compare(),
2054 const allocator_type& al=allocator_type()):
2055 super(from_comp,to_comp,al)
2070 #if defined(_MSC_VER)&&_MSC_VER==1200 2075 to_type_,from_type_,
2076 to_compare,from_compare,
2077 std::allocator<direct_pair<const to_type_,const from_type_> > >
2080 explicit bimap(
const inv_bimap& r):
2081 super(r.to.key_comp(),r.from.key_comp(),allocator_type())
2085 to_type_,from_type_,
2086 to_compare,from_compare,
2087 typename allocator_type::template rebind<
2091 explicit bimap(
const inv_bimap& r):
2092 super(r.to.key_comp(),r.from.key_comp(),r.get_allocator())
2100 #if defined(_MSC_VER)&&_MSC_VER==1200 2104 typename super::from::iterator fhint=from.end();
2105 typename super::to::iterator thint=to.end();
2106 for(
typename inv_bimap::to::const_iterator it=r.to.begin();it!=r.to.end();++it){
2107 insert(fhint,thint,*it);
2110 typename super::from::iterator fhint=from.end();
2111 typename super::to::iterator thint=to.end();
2112 for(
typename inv_bimap::to::const_iterator it=r.to.begin();it!=r.to.end();++it){
2113 std::pair<typename super::from::iterator,typename super::to::iterator>
2114 p=insert(fhint,thint,*it);
2126 template<
typename it_type>
2128 it_type first,it_type last,
2129 const from_compare& from_comp=from_compare(),
2130 const to_compare& to_comp=to_compare(),
2131 const allocator_type& al=allocator_type()):
2132 super(from_comp,to_comp,al)
2136 #if defined(_MSC_VER)&&_MSC_VER==1200 2141 typename super::from::iterator fhint=from.end();
2142 typename super::to::iterator thint=to.end();
2144 insert(fhint,thint,first++);
2147 typename super::from::iterator fhint=from.end();
2148 typename super::to::iterator thint=to.end();
2150 std::pair<typename super::from::iterator,typename super::to::iterator>
2151 p=insert(fhint,thint,first++);
2165 bool operator==(
const bimap& r)
const{
return from==r.from;}
2166 bool operator!=(
const bimap& r)
const{
return from!=r.from;}
2167 bool operator< (
const bimap& r)
const{
return from<r.from;}
2168 bool operator> (
const bimap& r)
const{
return from>r.from;}
2169 bool operator<=(
const bimap& r)
const{
return from<=r.from;}
2170 bool operator>=(
const bimap& r)
const{
return from>=r.from;}
2175 #elif VERSION_BIMAP_9B698EF9_C6E9_4BC4_A7D2_5B4D71155761!=0x00010002 2176 #error You have included two BIMAP.H with different version numbers
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: enum_maker.hpp:46