1 /********************* */
4 ** Original author: Morgan Deters
5 ** Major contributors: none
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2014 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
12 ** \brief Some standard STL-related utility functions for CVC4
14 ** Some standard STL-related utility functions for CVC4.
17 #include "cvc4_private.h"
19 #ifndef __CVC4__UTILITY_H
20 #define __CVC4__UTILITY_H
29 * Like std::equal_to<>, but tests equality between the first element
30 * of a pair and an element.
32 template <class T
, class U
>
33 struct first_equal_to
: std::binary_function
<std::pair
<T
, U
>, T
, bool> {
34 bool operator()(const std::pair
<T
, U
>& pr
, const T
& x
) const {
37 };/* struct first_equal_to<T> */
41 * Like std::equal_to<>, but tests equality between the second element
42 * of a pair and an element.
44 template <class T
, class U
>
45 struct second_equal_to
: std::binary_function
<std::pair
<T
, U
>, U
, bool> {
46 bool operator()(const std::pair
<T
, U
>& pr
, const U
& x
) const {
47 return pr
.second
== x
;
49 };/* struct first_equal_to<T> */
53 * Using std::find_if(), finds the first iterator in [first,last)
54 * range that satisfies predicate. If none, return last; otherwise,
55 * search for a second one. If there IS a second one, return last,
56 * otherwise return the first (and unique) iterator satisfying pred().
58 template <class InputIterator
, class Predicate
>
59 inline InputIterator
find_if_unique(InputIterator first
, InputIterator last
, Predicate pred
) {
60 InputIterator match
= std::find_if(first
, last
, pred
);
65 InputIterator match2
= match
;
66 match2
= std::find_if(++match2
, last
, pred
);
67 return (match2
== last
) ? match
: last
;
72 #endif /* __CVC4__UTILITY_H */