diff options
author | Morgan Deters <mdeters@gmail.com> | 2011-05-05 22:23:50 +0000 |
---|---|---|
committer | Morgan Deters <mdeters@gmail.com> | 2011-05-05 22:23:50 +0000 |
commit | fef0f8190fc7e5f3b88b33e7574b7df1e629e80f (patch) | |
tree | dfdda739bf5008096860e19f6b9275fb2a257960 /src/util/utility.h | |
parent | 90d8205a86b698c2548108ca4db124fe9c3f738a (diff) |
Merge from nonclausal-simplification-v2 branch:
* Preprocessing-time, non-clausal, Boolean simplification round to
support "quasi-non-linear rewrites" as discussed at last few meetings.
* --simplification=none is the default for now, but we'll probably
change that to --simplification=incremental. --simplification=batch
is also a possibility. See --simplification=help for details.
* RecursionBreaker<T> now uses a hash set for the seen trail.
* Fixes to TLS stuff to support that.
* Fixes to theory and SmtEngine documentation.
* Fixes to stream indentation.
* Other miscellaneous stuff.
Diffstat (limited to 'src/util/utility.h')
-rw-r--r-- | src/util/utility.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/util/utility.h b/src/util/utility.h new file mode 100644 index 000000000..9aa4c1158 --- /dev/null +++ b/src/util/utility.h @@ -0,0 +1,75 @@ +/********************* */ +/*! \file utility.h + ** \verbatim + ** Original author: mdeters + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 prototype. + ** Copyright (c) 2009, 2010, 2011 The Analysis of Computer Systems Group (ACSys) + ** Courant Institute of Mathematical Sciences + ** New York University + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Some standard STL-related utility functions for CVC4 + ** + ** Some standard STL-related utility functions for CVC4. + **/ + +#include "cvc4_private.h" + +#ifndef __CVC4__UTILITY_H +#define __CVC4__UTILITY_H + +#include <utility> +#include <functional> + +namespace CVC4 { + + +/** + * Like std::equal_to<>, but tests equality between the first element + * of a pair and an element. + */ +template <class T, class U> +struct first_equal_to : std::binary_function<std::pair<T, U>, T, bool> { + bool operator()(const std::pair<T, U>& pr, const T& x) const { + return pr.first == x; + } +};/* struct first_equal_to<T> */ + + +/** + * Like std::equal_to<>, but tests equality between the second element + * of a pair and an element. + */ +template <class T, class U> +struct second_equal_to : std::binary_function<std::pair<T, U>, U, bool> { + bool operator()(const std::pair<T, U>& pr, const U& x) const { + return pr.second == x; + } +};/* struct first_equal_to<T> */ + + +/** + * Using std::find_if(), finds the first iterator in [first,last) + * range that satisfies predicate. If none, return last; otherwise, + * search for a second one. If there IS a second one, return last, + * otherwise return the first (and unique) iterator satisfying pred(). + */ +template <class InputIterator, class Predicate> +inline InputIterator find_if_unique(InputIterator first, InputIterator last, Predicate pred) { + InputIterator match = std::find_if(first, last, pred); + if(match == last) { + return last; + } + + InputIterator match2 = match; + match2 = std::find_if(++match2, last, pred); + return (match2 == last) ? match : last; +} + + +}/* CVC4 namespace */ + +#endif /* __CVC4__UTILITY_H */ |