edits
[cdsspec-compiler.git] / notes / definition.cc
index 0c5b7965174727e5414f005c0421f33188937e35..fda4ebac8765b298d3726e669281bf32882f8145 100644 (file)
@@ -127,6 +127,21 @@ inline set<T>* Subset(set<T> *original, std::function<bool(T)> condition) {
        return res;
 }
 
        return res;
 }
 
+/**
+       A general set operation that takes a condition and returns if there exists
+       any item for which the boolean guard holds.
+*/
+template <class T>
+inline bool HasItem(set<T> *original, std::function<bool(T)> condition) {
+       ForEach (_M, original) {
+               if (condition(_M))
+                       return true;
+       }
+       return false;
+}
+
+
+
 /**
        A general sublist operation that takes a condition and returns all the item
        for which the boolean guard holds in the same order as in the old list.
 /**
        A general sublist operation that takes a condition and returns all the item
        for which the boolean guard holds in the same order as in the old list.
@@ -313,9 +328,10 @@ int main() {
        ms->insert(m);
 
        MakeSet(int, ms, newis, STATE(x));
        ms->insert(m);
 
        MakeSet(int, ms, newis, STATE(x));
-       cout << "Size=" << Size(newis) << " | val= " << Belong(newis, 2) << endl;
+       //cout << "Size=" << Size(newis) << " | val= " << Belong(newis, 2) << endl;
+       cout << "HasItem=" << HasItem(ms, Guard(STATE(x) == 2)) << endl;
        ForEach (i, newis) {
        ForEach (i, newis) {
-               cout << "elem: " << i << endl;
+               //cout << "elem: " << i << endl;
        }
 
 
        }