DGtal  1.5.beta
SetFunctions.h
1 
17 #pragma once
18 
31 #if defined(SetFunctions_RECURSES)
32 #error Recursive header files inclusion detected in SetFunctions.h
33 #else // defined(SetFunctions_RECURSES)
35 #define SetFunctions_RECURSES
36 
37 #if !defined SetFunctions_h
39 #define SetFunctions_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/ContainerTraits.h"
47 
48 namespace DGtal
49 {
50 
51  namespace detail {
52  template <typename LessThan, typename T>
54  LessThan compare;
56  : compare( aCompare ) {}
57  bool operator()( const T& t1, const T& t2 ) const
58  {
59  return ( ! compare( t1, t2 ) ) && ( ! compare( t2, t1 ) );
60  }
61  };
62  template <typename KeyComparator, typename PairKeyData>
64  KeyComparator compare;
65  KeyComparatorForPairKeyData( KeyComparator aCompare )
66  : compare( aCompare ) {}
67  bool operator()( const PairKeyData& t1, const PairKeyData& t2 ) const
68  {
69  return compare( t1.first, t2.first );
70  }
71  };
72 
75  template <typename Container, bool associative, bool ordered, bool pair>
77  {
78  typedef typename Container::value_type value_type;
79  typedef std::less< value_type > LessThanPredicate;
80  typedef std::equal_to< value_type > EqualPredicate;
81  static LessThanPredicate less( const Container& /* C */ )
82  {
83  return LessThanPredicate();
84  }
85  static EqualPredicate equal_to( const Container& /* C */ )
86  {
87  return EqualPredicate();
88  }
89  static inline const value_type& key( const value_type& value )
90  {
91  return value;
92  }
93 
94  };
95 
97  template <typename Container>
98  struct ComparatorAdapter< Container, true, true, false >
99  {
100  typedef typename Container::value_type value_type;
101  typedef typename Container::key_type key_type;
102  typedef typename Container::key_compare key_compare;
106  static LessThanPredicate less( const Container& C )
107  {
108  return C.key_comp();
109  }
110  static EqualPredicate equal_to( const Container& C )
111  {
112  return EqualPredicate( C.key_comp() );
113  }
114  static inline const key_type& key( const value_type& value )
115  {
116  return value;
117  }
118  };
119 
121  template <typename Container>
122  struct ComparatorAdapter< Container, true, true, true >
123  {
124  typedef typename Container::value_type value_type;
125  typedef typename Container::key_type key_type;
126  typedef typename Container::key_compare key_compare;
131  static LessThanPredicate less( const Container& C )
132  {
133  return LessThanPredicate( C.key_comp() );
134  }
135  static EqualPredicate equal_to( const Container& C )
136  {
137  return EqualPredicate( less( C ) );
138  }
139  static inline const key_type& key( const value_type& value )
140  {
141  return value.first;
142  }
143  };
144 
146  template <typename Container>
147  struct ComparatorAdapter< Container, true, false, false >
148  {
149  typedef typename Container::value_type value_type;
150  typedef typename Container::key_type key_type;
151  typedef std::less< key_type > LessThanPredicate;
152  typedef std::equal_to< key_type > EqualPredicate;
153  static LessThanPredicate less( const Container& /* C */ )
154  {
155  return LessThanPredicate();
156  }
157  static EqualPredicate equal_to( const Container& /* C */ )
158  {
159  return EqualPredicate();
160  }
161  static inline const key_type& key( const value_type& value )
162  {
163  return value;
164  }
165  };
166 
168  template <typename Container>
169  struct ComparatorAdapter< Container, true, false, true >
170  {
171  typedef typename Container::value_type value_type;
172  typedef typename Container::key_type key_type;
174  < std::less< key_type >, value_type > LessThanPredicate;
176  < std::equal_to< key_type >, value_type > EqualPredicate;
177 
178  static LessThanPredicate less( const Container& /* C */ )
179  {
180  return LessThanPredicate( std::less< key_type >() );
181  }
182  static EqualPredicate equal_to( const Container& /* C */ )
183  {
184  return EqualPredicate( std::equal_to< key_type >() );
185  }
186  static inline const key_type& key( const value_type& value )
187  {
188  return value.first;
189  }
190 
191  };
192 
193 
194 
233  template <typename Container, bool associative, bool ordered>
235  {
243  static bool isEqual( const Container& S1, const Container& S2 )
244  {
245  // Checks size first.
246  if ( S1.size() != S2.size() ) return false;
247  typedef typename Container::value_type value_type;
248  typedef std::vector<value_type> Vector;
249  typedef ComparatorAdapter< Container, associative, ordered,
251  CompAdapter;
252 
253  Vector V1( S1.begin(), S1.end() );
254  Vector V2( S2.begin(), S2.end() );
255  std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
256  std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
257  return std::equal( V1.begin(), V1.end(), V2.begin(),
258  CompAdapter::equal_to( S1 ) );
259  }
260 
268  static bool isSubset( const Container& S1, const Container& S2 )
269  {
270  // Checks size first.
271  if ( S1.size() > S2.size() ) return false;
272  typedef typename Container::value_type value_type;
273  typedef std::vector<value_type> Vector;
274  typedef ComparatorAdapter< Container, associative, ordered,
276  CompAdapter;
277 
278  Vector V1( S1.begin(), S1.end() );
279  Vector V2( S2.begin(), S2.end() );
280  std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
281  std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
282  return std::includes( V2.begin(), V2.end(), V1.begin(), V1.end(),
283  CompAdapter::less( S1 ) );
284  }
285 
292  static Container& assignDifference( Container& S1, const Container& S2 )
293  {
294  typedef typename Container::value_type value_type;
295  typedef std::vector<value_type> Vector;
296  typedef ComparatorAdapter< Container, associative, ordered,
298  CompAdapter;
299 
300  Vector V1( S1.begin(), S1.end() );
301  Vector V2( S2.begin(), S2.end() );
302  std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
303  std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
304  S1.clear();
305  std::set_difference( V1.begin(), V1.end(), V2.begin(), V2.end(),
306  std::inserter( S1, S1.end() ), CompAdapter::less( S1 ) );
307  return S1;
308  }
309 
316  static Container& assignUnion( Container& S1, const Container& S2 )
317  {
318  typedef typename Container::value_type value_type;
319  typedef std::vector<value_type> Vector;
320  typedef ComparatorAdapter< Container, associative, ordered,
322  CompAdapter;
323 
324  Vector V1( S1.begin(), S1.end() );
325  Vector V2( S2.begin(), S2.end() );
326  std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
327  std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
328  S1.clear();
329  std::set_union( V1.begin(), V1.end(), V2.begin(), V2.end(),
330  std::inserter( S1, S1.end() ), CompAdapter::less( S1 ) );
331  return S1;
332  }
333 
340  static Container& assignIntersection( Container& S1, const Container& S2 )
341  {
342  typedef typename Container::value_type value_type;
343  typedef std::vector<value_type> Vector;
344  typedef ComparatorAdapter< Container, associative, ordered,
346  CompAdapter;
347 
348  Vector V1( S1.begin(), S1.end() );
349  Vector V2( S2.begin(), S2.end() );
350  std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
351  std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
352  S1.clear();
353  std::set_intersection( V1.begin(), V1.end(), V2.begin(), V2.end(),
354  std::inserter( S1, S1.end() ),
355  CompAdapter::less( S1 ) );
356  return S1;
357  }
358 
365  static Container& assignSymmetricDifference( Container& S1, const Container& S2 )
366  {
367  typedef typename Container::value_type value_type;
368  typedef std::vector<value_type> Vector;
369  typedef ComparatorAdapter< Container, associative, ordered,
371  CompAdapter;
372 
373  Vector V1( S1.begin(), S1.end() );
374  Vector V2( S2.begin(), S2.end() );
375  std::sort( V1.begin(), V1.end(), CompAdapter::less( S1 ) );
376  std::sort( V2.begin(), V2.end(), CompAdapter::less( S1 ) );
377  S1.clear();
378  std::set_symmetric_difference( V1.begin(), V1.end(), V2.begin(), V2.end(),
379  std::inserter( S1, S1.end() ),
380  CompAdapter::less( S1 ) );
381  return S1;
382  }
383 
384 
385  };
386 
391  template <typename Container>
392  struct SetFunctionsImpl<Container, true, false>
393  {
394 
402  static bool isEqual( const Container& S1, const Container& S2 )
403  {
404  typedef ComparatorAdapter< Container, true, false,
406  CompAdapter;
407 
408  // Checks size first.
409  if ( S1.size() != S2.size() ) return false;
410  // Note that it is critical here that all elements are distinct.
411  for ( typename Container::const_iterator it = S1.begin(),
412  itE = S1.end(); it != itE; ++it )
413  if ( S2.find( CompAdapter::key( *it ) ) == S2.end() ) return false;
414  return true;
415  }
416 
424  static bool isSubset( const Container& S1, const Container& S2 )
425  {
426  typedef ComparatorAdapter< Container, true, false,
428  CompAdapter;
429 
430  // Checks size first.
431  if ( S1.size() > S2.size() ) return false;
432  for ( typename Container::const_iterator it = S1.begin(),
433  itE = S1.end(); it != itE; ++it )
434  if ( S2.find( CompAdapter::key( *it ) ) == S2.end() ) return false;
435  return true;
436  }
437 
444  static Container& assignDifference( Container& S1, const Container& S2 )
445  {
446  typedef ComparatorAdapter< Container, true, false,
448  CompAdapter;
449 
450  for ( typename Container::const_iterator it = S2.begin(),
451  itE = S2.end(); it != itE; ++it )
452  S1.erase( CompAdapter::key( *it ) );
453  return S1;
454  }
455 
462  static Container& assignUnion( Container& S1, const Container& S2 )
463  {
464  typename Container::iterator itS1 = S1.end();
465  for ( typename Container::const_iterator it = S2.begin(),
466  itE = S2.end(); it != itE; ++it )
467  itS1 = S1.insert( itS1, *it );
468  return S1;
469  }
470 
477  static Container& assignIntersection( Container& S1, const Container& S2 )
478  {
479  typedef ComparatorAdapter< Container, true, false,
481  CompAdapter;
482 
483  for ( typename Container::iterator it = S1.begin(),
484  itE = S1.end(); it != itE; )
485  {
486  typename Container::iterator itNext = it; ++itNext;
487  if ( S2.find( CompAdapter::key( *it ) ) == S2.end() )
488  S1.erase( CompAdapter::key( *it ) );
489  it = itNext;
490  }
491  return S1;
492  }
493 
500  static Container& assignSymmetricDifference( Container& S1, const Container& S2 )
501  {
502  Container S12( S1 );
503  assignIntersection( S12, S2 );
504  assignUnion( S1, S2 );
505  return assignDifference( S1, S12 );
506  }
507 
508  };
509 
513  template <typename Container>
514  struct SetFunctionsImpl<Container, true, true >
515  {
516 
524  static bool isEqual( const Container& S1, const Container& S2 )
525  {
526  // Checks size first.
527  if ( S1.size() != S2.size() ) return false;
528  // One has to be careful for comparing keys in set-like
529  // structure, we only have an operator<. Hence a == b is defined as
530  // ( ! a<b ) && ( ! b<a ).
531  typedef ComparatorAdapter< Container, true, true,
533  CompAdapter;
534 
535  return std::equal( S1.begin(), S1.end(), S2.begin(),
536  CompAdapter::equal_to( S1 ) );
537  }
538 
547  static bool isSubset( const Container& S1, const Container& S2 )
548  {
549  // Checks size first.
550  if ( S1.size() > S2.size() ) return false;
551  typedef ComparatorAdapter< Container, true, true,
553  CompAdapter;
554 
555  return std::includes( S2.begin(), S2.end(),
556  S1.begin(), S1.end(), CompAdapter::less( S1 ) );
557  }
558 
559 
566  static Container& assignDifference( Container& S1, const Container& S2 )
567  {
568  typedef ComparatorAdapter< Container, true, true,
570  CompAdapter;
571 
572  Container S;
573  std::swap( S, S1 );
574  std::set_difference( S.begin(), S.end(), S2.begin(), S2.end(),
575  std::inserter( S1, S1.end() ),
576  CompAdapter::less( S1 ) );
577  return S1;
578  }
579 
586  static Container& assignUnion( Container& S1, const Container& S2 )
587  {
588  typedef ComparatorAdapter< Container, true, true,
590  CompAdapter;
591 
592  Container S;
593  std::swap( S, S1 );
594  std::set_union( S.begin(), S.end(), S2.begin(), S2.end(),
595  std::inserter( S1, S1.end() ),
596  CompAdapter::less( S1 ) );
597  return S1;
598  }
599 
606  static Container& assignIntersection( Container& S1, const Container& S2 )
607  {
608  typedef ComparatorAdapter< Container, true, true,
610  CompAdapter;
611 
612  Container S;
613  std::swap( S, S1 );
614  std::set_intersection( S.begin(), S.end(), S2.begin(), S2.end(),
615  std::inserter( S1, S1.end() ),
616  CompAdapter::less( S1 ) );
617  return S1;
618  }
619 
626  static Container& assignSymmetricDifference( Container& S1, const Container& S2 )
627  {
628  typedef ComparatorAdapter< Container, true, true,
630  CompAdapter;
631 
632  Container S;
633  std::swap( S, S1 );
634  std::set_symmetric_difference( S.begin(), S.end(), S2.begin(), S2.end(),
635  std::inserter( S1, S1.end() ),
636  CompAdapter::less( S1 ) );
637  return S1;
638  }
639  };
640 
645  template <typename Container >
646  struct SetFunctionsImpl< Container, false, true >
647  {
655  static bool isEqual( const Container& S1, const Container& S2 )
656  {
658  CompAdapter;
659 
660  // Checks size first.
661  if ( S1.size() != S2.size() ) return false;
662  return std::equal( S1.begin(), S1.end(), S2.begin(),
663  CompAdapter::equal_to( S1 ) );
664  }
665 
674  static bool isSubset( const Container& S1, const Container& S2 )
675  {
677  CompAdapter;
678 
679  // Checks size first.
680  if ( S1.size() > S2.size() ) return false;
681  return std::includes( S2.begin(), S2.end(), S1.begin(), S1.end(),
682  CompAdapter::less( S1 ) );
683  }
684 
691  static Container& assignDifference( Container& S1, const Container& S2 )
692  {
694  CompAdapter;
695 
696  Container S;
697  std::swap( S, S1 );
698  std::set_difference( S.begin(), S.end(), S2.begin(), S2.end(),
699  std::inserter( S1, S1.end() ),
700  CompAdapter::less( S1 ) );
701  return S1;
702  }
703 
710  static Container& assignUnion( Container& S1, const Container& S2 )
711  {
713  CompAdapter;
714 
715  Container S;
716  std::swap( S, S1 );
717  std::set_union( S.begin(), S.end(), S2.begin(), S2.end(),
718  std::inserter( S1, S1.end() ),
719  CompAdapter::less( S1 ) );
720  return S1;
721  }
722 
729  static Container& assignIntersection( Container& S1, const Container& S2 )
730  {
732  CompAdapter;
733 
734  Container S;
735  std::swap( S, S1 );
736  std::set_intersection( S.begin(), S.end(), S2.begin(), S2.end(),
737  std::inserter( S1, S1.end() ),
738  CompAdapter::less( S1 ) );
739  return S1;
740  }
741 
748  static Container& assignSymmetricDifference( Container& S1, const Container& S2 )
749  {
751  CompAdapter;
752 
753  Container S;
754  std::swap( S, S1 );
755  std::set_symmetric_difference( S.begin(), S.end(), S2.begin(), S2.end(),
756  std::inserter( S1, S1.end() ),
757  CompAdapter::less( S1 ) );
758  return S1;
759  }
760 
761  };
762 
763  } // detail
764 
766  // template class SetFunctions
767 
768  namespace functions {
769 
771 
788  template <typename Container, bool ordered>
789  bool isEqual( const Container& S1, const Container& S2 )
790  {
791  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
792  BOOST_STATIC_CONSTANT
793  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
794  BOOST_STATIC_CONSTANT
795  ( bool, isOrdered = ordered
796  || ( isAssociative && IsOrderedAssociativeContainer< Container >::value ) );
797 
799  ::isEqual( S1, S2 );
800  }
801 
814  template <typename Container>
815  bool isEqual( const Container& S1, const Container& S2 )
816  {
817  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
818  BOOST_STATIC_CONSTANT
819  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
820  BOOST_STATIC_CONSTANT
821  ( bool, isOrdered = isAssociative && IsOrderedAssociativeContainer< Container >::value );
822 
824  ::isEqual( S1, S2 );
825  }
826 
827 
829 
844  template <typename Container, bool ordered>
845  bool isSubset( const Container& S1, const Container& S2 )
846  {
847  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
848  BOOST_STATIC_CONSTANT
849  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
850  BOOST_STATIC_CONSTANT
851  ( bool, isOrdered = ordered
852  || ( isAssociative && IsOrderedAssociativeContainer< Container >::value ) );
853 
855  ::isSubset( S1, S2 );
856  }
857 
868  template <typename Container>
869  bool isSubset( const Container& S1, const Container& S2 )
870  {
871  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
872  BOOST_STATIC_CONSTANT
873  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
874  BOOST_STATIC_CONSTANT
875  ( bool, isOrdered = isAssociative && IsOrderedAssociativeContainer< Container >::value );
876 
878  ::isSubset( S1, S2 );
879  }
880 
882 
895  template <typename Container, bool ordered>
896  Container& assignDifference( Container& S1, const Container& S2 )
897  {
898  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
899  BOOST_STATIC_CONSTANT
900  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
901  BOOST_STATIC_CONSTANT
902  ( bool, isOrdered = ordered
903  || ( isAssociative && IsOrderedAssociativeContainer< Container >::value ) );
904 
906  ::assignDifference( S1, S2 );
907  }
908 
917  template <typename Container>
918  Container& assignDifference( Container& S1, const Container& S2 )
919  {
920  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
921  BOOST_STATIC_CONSTANT
922  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
923  BOOST_STATIC_CONSTANT
924  ( bool, isOrdered = isAssociative && IsOrderedAssociativeContainer< Container >::value );
925 
927  ::assignDifference( S1, S2 );
928  }
929 
945  template <typename Container, bool ordered>
946  Container makeDifference( const Container& S1, const Container& S2 )
947  {
948  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
949  Container S( S1 );
950  assignDifference<Container, ordered>( S, S2 );
951  return S;
952  }
953 
964  template <typename Container>
965  Container makeDifference( const Container& S1, const Container& S2 )
966  {
967  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
968  Container S( S1 );
969  assignDifference( S, S2 );
970  return S;
971  }
972 
973 
975 
989  template <typename Container, bool ordered>
990  Container& assignUnion( Container& S1, const Container& S2 )
991  {
992  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
993  BOOST_STATIC_CONSTANT
994  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
995  BOOST_STATIC_CONSTANT
996  ( bool, isOrdered = ordered
997  || ( isAssociative && IsOrderedAssociativeContainer< Container >::value ) );
998 
1000  ::assignUnion( S1, S2 );
1001  }
1002 
1011  template <typename Container>
1012  Container& assignUnion( Container& S1, const Container& S2 )
1013  {
1014  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1015  BOOST_STATIC_CONSTANT
1016  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
1017  BOOST_STATIC_CONSTANT
1018  ( bool, isOrdered = isAssociative && IsOrderedAssociativeContainer< Container >::value );
1019 
1021  ::assignUnion( S1, S2 );
1022  }
1023 
1038  template <typename Container, bool ordered>
1039  Container makeUnion( const Container& S1, const Container& S2 )
1040  {
1041  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1042  Container S( S1 );
1043  assignUnion<Container, ordered>( S, S2 );
1044  return S;
1045  }
1046 
1056  template <typename Container>
1057  Container makeUnion( const Container& S1, const Container& S2 )
1058  {
1059  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1060  Container S( S1 );
1061  assignUnion( S, S2 );
1062  return S;
1063  }
1064 
1065 
1067 
1081  template <typename Container, bool ordered>
1082  Container& assignIntersection( Container& S1, const Container& S2 )
1083  {
1084  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1085  BOOST_STATIC_CONSTANT
1086  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
1087  BOOST_STATIC_CONSTANT
1088  ( bool, isOrdered = ordered
1089  || ( isAssociative && IsOrderedAssociativeContainer< Container >::value ) );
1090 
1092  ::assignIntersection( S1, S2 );
1093  }
1094 
1103  template <typename Container>
1104  Container& assignIntersection( Container& S1, const Container& S2 )
1105  {
1106  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1107  BOOST_STATIC_CONSTANT
1108  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
1109  BOOST_STATIC_CONSTANT
1110  ( bool, isOrdered = isAssociative && IsOrderedAssociativeContainer< Container >::value );
1111 
1113  ::assignIntersection( S1, S2 );
1114  }
1115 
1130  template <typename Container, bool ordered>
1131  Container makeIntersection( const Container& S1, const Container& S2 )
1132  {
1133  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1134  Container S( S1 );
1135  assignIntersection<Container, ordered>( S, S2 );
1136  return S;
1137  }
1138 
1148  template <typename Container>
1149  Container makeIntersection( const Container& S1, const Container& S2 )
1150  {
1151  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1152  Container S( S1 );
1153  assignIntersection( S, S2 );
1154  return S;
1155  }
1156 
1157 
1159 
1175  template <typename Container, bool ordered>
1176  Container& assignSymmetricDifference( Container& S1, const Container& S2 )
1177  {
1178  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1179  BOOST_STATIC_CONSTANT
1180  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
1181  BOOST_STATIC_CONSTANT
1182  ( bool, isOrdered = ordered
1183  || ( isAssociative && IsOrderedAssociativeContainer< Container >::value ) );
1184 
1187  }
1188 
1197  template <typename Container>
1198  Container& assignSymmetricDifference( Container& S1, const Container& S2 )
1199  {
1200  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1201  BOOST_STATIC_CONSTANT
1202  ( bool, isAssociative = IsAssociativeContainer< Container >::value );
1203  BOOST_STATIC_CONSTANT
1204  ( bool, isOrdered = isAssociative && IsOrderedAssociativeContainer< Container >::value );
1205 
1208  }
1209 
1224  template <typename Container, bool ordered>
1225  Container makeSymmetricDifference( const Container& S1, const Container& S2 )
1226  {
1227  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1228  Container S( S1 );
1229  assignSymmetricDifference<Container, ordered>( S, S2 );
1230  return S;
1231  }
1232 
1242  template <typename Container>
1243  Container makeSymmetricDifference( const Container& S1, const Container& S2 )
1244  {
1245  BOOST_STATIC_ASSERT( IsContainer< Container >::value );
1246  Container S( S1 );
1247  assignSymmetricDifference( S, S2 );
1248  return S;
1249  }
1250 
1251 
1252 
1254  // OVERLOADING SET OPERATIONS
1256 
1261  namespace setops {
1262 
1271  template <typename Container>
1272  inline Container& operator-=( Container& S1, const Container& S2 )
1273  {
1274  return assignDifference( S1, S2 );
1275  }
1276 
1287  template <typename Container>
1288  inline Container operator-( const Container& S1, const Container& S2 )
1289  {
1290  return makeDifference( S1, S2 );
1291  }
1292 
1302  template <typename Container>
1303  inline Container operator|( const Container& S1, const Container& S2 )
1304  {
1305  return makeUnion( S1, S2 );
1306  }
1307 
1316  template <typename Container>
1317  inline Container& operator|=( Container& S1, const Container& S2 )
1318  {
1319  return assignUnion( S1, S2 );
1320  }
1321 
1331  template <typename Container>
1332  inline Container operator&( const Container& S1, const Container& S2 )
1333  {
1334  return makeIntersection( S1, S2 );
1335  }
1336 
1345  template <typename Container>
1346  inline Container& operator&=( Container& S1, const Container& S2 )
1347  {
1348  return assignIntersection( S1, S2 );
1349  }
1350 
1361  template <typename Container>
1362  inline Container operator^( const Container& S1, const Container& S2 )
1363  {
1364  return makeSymmetricDifference( S1, S2 );
1365  }
1366 
1377  template <typename Container>
1378  inline Container& operator^=( Container& S1, const Container& S2 )
1379  {
1380  return assignSymmetricDifference( S1, S2 );
1381  }
1382 
1383  }
1384  }
1385 
1386 
1387 
1388 } // namespace DGtal
1389 
1390 
1392 // Includes inline functions.
1393 #include "DGtal/base/SetFunctions.ih"
1394 
1395 // //
1397 
1398 #endif // !defined SetFunctions_h
1399 
1400 #undef SetFunctions_RECURSES
1401 #endif // else defined(SetFunctions_RECURSES)
DigitalPlane::Point Vector
Container operator-(const Container &S1, const Container &S2)
Container & operator|=(Container &S1, const Container &S2)
Container operator^(const Container &S1, const Container &S2)
Container operator&(const Container &S1, const Container &S2)
Container operator|(const Container &S1, const Container &S2)
Container & operator-=(Container &S1, const Container &S2)
Container & operator^=(Container &S1, const Container &S2)
Container & operator&=(Container &S1, const Container &S2)
Container makeSymmetricDifference(const Container &S1, const Container &S2)
Container & assignSymmetricDifference(Container &S1, const Container &S2)
bool isEqual(const Container &S1, const Container &S2)
Definition: SetFunctions.h:789
Container makeIntersection(const Container &S1, const Container &S2)
Container & assignUnion(Container &S1, const Container &S2)
Definition: SetFunctions.h:990
bool isSubset(const Container &S1, const Container &S2)
Definition: SetFunctions.h:845
Container & assignDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:896
Container makeDifference(const Container &S1, const Container &S2)
Definition: SetFunctions.h:946
Container & assignIntersection(Container &S1, const Container &S2)
Container makeUnion(const Container &S1, const Container &S2)
DGtal is the top-level namespace which contains all DGtal functions and types.
static const key_type & key(const value_type &value)
Definition: SetFunctions.h:161
static LessThanPredicate less(const Container &)
Definition: SetFunctions.h:153
static LessThanPredicate less(const Container &)
Definition: SetFunctions.h:178
KeyComparatorForPairKeyData< std::less< key_type >, value_type > LessThanPredicate
Definition: SetFunctions.h:174
KeyComparatorForPairKeyData< std::equal_to< key_type >, value_type > EqualPredicate
Definition: SetFunctions.h:176
static const key_type & key(const value_type &value)
Definition: SetFunctions.h:186
static const key_type & key(const value_type &value)
Definition: SetFunctions.h:114
EqualPredicateFromLessThanComparator< LessThanPredicate, value_type > EqualPredicate
Definition: SetFunctions.h:105
static LessThanPredicate less(const Container &C)
Definition: SetFunctions.h:106
static EqualPredicate equal_to(const Container &C)
Definition: SetFunctions.h:110
static LessThanPredicate less(const Container &C)
Definition: SetFunctions.h:131
KeyComparatorForPairKeyData< key_compare, value_type > LessThanPredicate
Definition: SetFunctions.h:128
static const key_type & key(const value_type &value)
Definition: SetFunctions.h:139
EqualPredicateFromLessThanComparator< LessThanPredicate, value_type > EqualPredicate
Definition: SetFunctions.h:130
static EqualPredicate equal_to(const Container &C)
Definition: SetFunctions.h:135
Container::value_type value_type
Definition: SetFunctions.h:78
static EqualPredicate equal_to(const Container &)
Definition: SetFunctions.h:85
static LessThanPredicate less(const Container &)
Definition: SetFunctions.h:81
std::less< value_type > LessThanPredicate
Definition: SetFunctions.h:79
static const value_type & key(const value_type &value)
Definition: SetFunctions.h:89
std::equal_to< value_type > EqualPredicate
Definition: SetFunctions.h:80
bool operator()(const T &t1, const T &t2) const
Definition: SetFunctions.h:57
KeyComparatorForPairKeyData(KeyComparator aCompare)
Definition: SetFunctions.h:65
bool operator()(const PairKeyData &t1, const PairKeyData &t2) const
Definition: SetFunctions.h:67
static bool isSubset(const Container &S1, const Container &S2)
Definition: SetFunctions.h:674
static Container & assignUnion(Container &S1, const Container &S2)
Definition: SetFunctions.h:710
static Container & assignSymmetricDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:748
static Container & assignDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:691
static Container & assignIntersection(Container &S1, const Container &S2)
Definition: SetFunctions.h:729
static bool isEqual(const Container &S1, const Container &S2)
Definition: SetFunctions.h:655
static bool isEqual(const Container &S1, const Container &S2)
Definition: SetFunctions.h:402
static Container & assignIntersection(Container &S1, const Container &S2)
Definition: SetFunctions.h:477
static Container & assignSymmetricDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:500
static bool isSubset(const Container &S1, const Container &S2)
Definition: SetFunctions.h:424
static Container & assignDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:444
static Container & assignUnion(Container &S1, const Container &S2)
Definition: SetFunctions.h:462
static Container & assignSymmetricDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:626
static Container & assignIntersection(Container &S1, const Container &S2)
Definition: SetFunctions.h:606
static bool isSubset(const Container &S1, const Container &S2)
Definition: SetFunctions.h:547
static bool isEqual(const Container &S1, const Container &S2)
Definition: SetFunctions.h:524
static Container & assignDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:566
static Container & assignUnion(Container &S1, const Container &S2)
Definition: SetFunctions.h:586
Aim: Specialize set operations (union, intersection, difference, symmetric_difference) according to t...
Definition: SetFunctions.h:235
static bool isEqual(const Container &S1, const Container &S2)
Definition: SetFunctions.h:243
static bool isSubset(const Container &S1, const Container &S2)
Definition: SetFunctions.h:268
static Container & assignSymmetricDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:365
static Container & assignDifference(Container &S1, const Container &S2)
Definition: SetFunctions.h:292
static Container & assignUnion(Container &S1, const Container &S2)
Definition: SetFunctions.h:316
static Container & assignIntersection(Container &S1, const Container &S2)
Definition: SetFunctions.h:340