From: Aina Niemetz Date: Wed, 7 Feb 2018 08:55:44 +0000 (-0800) Subject: Use template for bv::utils::mkAnd. (#1569) X-Git-Tag: cvc5-1.0.0~5318 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=82066be04ce068b59b24526fbc8c9b4188503cae;p=cvc5.git Use template for bv::utils::mkAnd. (#1569) --- diff --git a/src/theory/bv/theory_bv_utils.cpp b/src/theory/bv/theory_bv_utils.cpp index da3822aa6..7df575ece 100644 --- a/src/theory/bv/theory_bv_utils.cpp +++ b/src/theory/bv/theory_bv_utils.cpp @@ -370,62 +370,6 @@ Node mkAnd(TNode node1, TNode node2) return NodeManager::currentNM()->mkNode(kind::AND, node1, node2); } -Node mkAnd(const std::vector& conjunctions) -{ - std::set all; - all.insert(conjunctions.begin(), conjunctions.end()); - - if (all.size() == 0) - { - return mkTrue(); - } - - if (all.size() == 1) - { - // All the same, or just one - return conjunctions[0]; - } - - NodeBuilder<> conjunction(kind::AND); - std::set::const_iterator it = all.begin(); - std::set::const_iterator it_end = all.end(); - while (it != it_end) - { - conjunction << *it; - ++it; - } - - return conjunction; -} - -Node mkAnd(const std::vector& conjunctions) -{ - std::set all; - all.insert(conjunctions.begin(), conjunctions.end()); - - if (all.size() == 0) - { - return mkTrue(); - } - - if (all.size() == 1) - { - // All the same, or just one - return conjunctions[0]; - } - - NodeBuilder<> conjunction(kind::AND); - std::set::const_iterator it = all.begin(); - std::set::const_iterator it_end = all.end(); - while (it != it_end) - { - conjunction << *it; - ++it; - } - - return conjunction; -} - Node mkOr(TNode node1, TNode node2) { return NodeManager::currentNM()->mkNode(kind::OR, node1, node2); diff --git a/src/theory/bv/theory_bv_utils.h b/src/theory/bv/theory_bv_utils.h index 6115a7e96..6e6cdcabe 100644 --- a/src/theory/bv/theory_bv_utils.h +++ b/src/theory/bv/theory_bv_utils.h @@ -127,8 +127,21 @@ Node mkSortedNode(Kind kind, std::vector& children); Node mkNot(Node child); /* Create node of kind AND. */ Node mkAnd(TNode node1, TNode node2); -Node mkAnd(const std::vector& conjunctions); -Node mkAnd(const std::vector& conjunctions); +/* Create n-ary node of kind AND. */ +template +Node mkAnd(const std::vector>& conjunctions) +{ + std::set all(conjunctions.begin(), conjunctions.end()); + + if (all.size() == 0) { return mkTrue(); } + + /* All the same, or just one */ + if (all.size() == 1) { return conjunctions[0]; } + + NodeBuilder<> conjunction(kind::AND); + for (const Node& n : all) { conjunction << n; } + return conjunction; +} /* Create node of kind OR. */ Node mkOr(TNode node1, TNode node2); Node mkOr(const std::vector& nodes);