Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00024
00025 #ifndef ICL_CORE_SET_HELPER_H_INCLUDED
00026 #define ICL_CORE_SET_HELPER_H_INCLUDED
00027
00028 #include <set>
00029
00030 namespace icl_core {
00031
00033 enum SetRelation
00034 {
00035 eSR_EQUAL,
00036 eSR_PROPER_SUPERSET,
00037 eSR_PROPER_SUBSET,
00038 eSR_INTERSECTION_NONEMPTY,
00039 eSR_DISJUNCT
00040 };
00041
00042 typedef ICL_CORE_VC_DEPRECATE SetRelation tSetRelation ICL_CORE_GCC_DEPRECATE;
00043
00046 template <typename T, typename TCompare>
00047 SetRelation setRelation(const std::set<T, TCompare>& s1, const std::set<T, TCompare>& s2)
00048 {
00049 bool equal = true;
00050 bool super = true;
00051 bool sub = true;
00052 bool inter = false;
00053 TCompare compare;
00054 typename std::set<T, TCompare>::const_iterator i1 = s1.begin(), i2 = s2.begin();
00055 while (i1 != s1.end() && i2 != s2.end())
00056 {
00057 if ((*i1) == (*i2))
00058 {
00059 inter = true;
00060 ++i1, ++i2;
00061 }
00062 else
00063 {
00064 equal = false;
00065 if (compare(*i1, *i2))
00066 {
00067 sub = false;
00068 ++i1;
00069 }
00070 else
00071 {
00072 super = false;
00073 ++i2;
00074 }
00075 }
00076 }
00077 if (i1 != s1.end())
00078 {
00079 equal = false;
00080 sub = false;
00081 }
00082 if (i2 != s2.end())
00083 {
00084 equal = false;
00085 super = false;
00086 }
00087 if (equal) { return eSR_EQUAL; }
00088 if (super) { return eSR_PROPER_SUPERSET; }
00089 if (sub) { return eSR_PROPER_SUBSET; }
00090 if (inter) { return eSR_INTERSECTION_NONEMPTY; }
00091 return eSR_DISJUNCT;
00092 }
00093
00094 }
00095
00096 #endif