X-Git-Url: http://plrg.eecs.uci.edu/git/?p=cdsspec-compiler.git;a=blobdiff_plain;f=notes%2Fdefinition.cc;h=fda4ebac8765b298d3726e669281bf32882f8145;hp=0c5b7965174727e5414f005c0421f33188937e35;hb=007d42509b6f84500bd65ffe710773117cb3d77f;hpb=189207ea1c47667cd77bcd5a41b37ff023a48315;ds=sidebyside diff --git a/notes/definition.cc b/notes/definition.cc index 0c5b796..fda4eba 100644 --- a/notes/definition.cc +++ b/notes/definition.cc @@ -127,6 +127,21 @@ inline set* Subset(set *original, std::function condition) { return res; } +/** + A general set operation that takes a condition and returns if there exists + any item for which the boolean guard holds. +*/ +template +inline bool HasItem(set *original, std::function 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. @@ -313,9 +328,10 @@ int main() { 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) { - cout << "elem: " << i << endl; + //cout << "elem: " << i << endl; }