3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00

Add compact version of std::all_of

This commit is contained in:
Jakob Rath 2022-10-03 10:55:13 +02:00
parent 0bea276e82
commit cd2d197bb9
3 changed files with 18 additions and 8 deletions

View file

@ -29,14 +29,14 @@ namespace polysat {
}
bool clause::is_always_false(solver& s) const {
return std::all_of(m_literals.begin(), m_literals.end(), [&s](sat::literal lit) {
return all_of(m_literals, [&s](sat::literal lit) {
signed_constraint c = s.m_constraints.lookup(lit);
return c.is_always_false();
});
}
bool clause::is_currently_false(solver& s) const {
return std::all_of(m_literals.begin(), m_literals.end(), [&s](sat::literal lit) {
return all_of(m_literals, [&s](sat::literal lit) {
signed_constraint c = s.m_constraints.lookup(lit);
return c.is_currently_false(s);
});

View file

@ -630,7 +630,7 @@ namespace polysat {
SASSERT(j.is_decision() || j.is_propagation());
SASSERT(j.level() == m_level);
SASSERT(!is_assigned(v));
SASSERT(std::all_of(assignment().begin(), assignment().end(), [v](auto p) { return p.first != v; }));
SASSERT(all_of(assignment(), [v](auto p) { return p.first != v; }));
m_value[v] = val;
m_search.push_assignment(v, val);
m_trail.push_back(trail_instr_t::assign_i);
@ -1154,7 +1154,7 @@ namespace polysat {
for (sat::bool_var v = m_bvars.size(); v-- > 0; ) {
sat::literal lit(v);
auto c = lit2cnstr(lit);
if (!std::all_of(c->vars().begin(), c->vars().end(), [&](auto v) { return is_assigned(v); }))
if (!all_of(c->vars(), [this](auto w) { return is_assigned(w); }))
continue;
ok &= (m_bvars.value(lit) != l_true) || !c.is_currently_false(*this);
ok &= (m_bvars.value(lit) != l_false) || !c.is_currently_true(*this);

View file

@ -20,11 +20,13 @@ Revision History:
#include "util/debug.h"
#include "util/memory_manager.h"
#include<ostream>
#include<climits>
#include<limits>
#include<stdint.h>
#include <ostream>
#include <climits>
#include <limits>
#include <stdint.h>
#include <string>
#include <algorithm>
#include <iterator>
#ifndef SIZE_MAX
#define SIZE_MAX std::numeric_limits<std::size_t>::max()
@ -374,3 +376,11 @@ inline size_t megabytes_to_bytes(unsigned mb) {
r = SIZE_MAX;
return r;
}
/** Compact version of std::all_of */
template <typename Container, typename Predicate>
bool all_of(Container const& c, Predicate f)
{
using std::begin, std::end; // allows begin(c) to also find c.begin()
return std::all_of(begin(c), end(c), std::forward<Predicate>(f));
}