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

Prefer using empty rather than size comparisons.

This commit is contained in:
Bruce Mitchener 2018-11-27 21:42:04 +07:00
parent a83097d5cc
commit e570940662
56 changed files with 104 additions and 104 deletions

View file

@ -35,7 +35,7 @@ static void tst1() {
}
else if (op <= 3) {
ENSURE(v1.size() == v2.size());
if (v1.size() > 0) {
if (!v1.empty()) {
bool val = (rand()%2) != 0;
unsigned idx = rand()%v1.size();
ENSURE(v1.get(idx) == v2[idx]);
@ -46,7 +46,7 @@ static void tst1() {
}
else if (op <= 4) {
ENSURE(v1.size() == v2.size());
if (v1.size() > 0) {
if (!v1.empty()) {
unsigned idx = rand()%v1.size();
VERIFY(v1.get(idx) == v2[idx]);
}

View file

@ -102,7 +102,7 @@ static void tst3() {
ENSURE(t.contains(12));
t.erase(12);
t.erase(10);
ENSURE(t.size() == 0);
ENSURE(t.empty());
ENSURE(t.empty());
ENSURE(t.used_slots() == 0);
t.insert(10);

View file

@ -117,7 +117,7 @@ public:
unknown_options.push_back(t);
}
}
if (unknown_options.size()) {
if (!unknown_options.empty()) {
ret = "Unknown options:";
}
for (const auto & unknownOption : unknown_options) {
@ -127,15 +127,15 @@ public:
ret += "\n";
ret += "Usage:\n";
for (auto allowed_option : m_options)
ret += allowed_option.first + " " + (allowed_option.second.size() == 0 ? std::string("") : std::string("/") + allowed_option.second) + std::string("\n");
ret += allowed_option.first + " " + (allowed_option.second.empty() ? std::string("") : std::string("/") + allowed_option.second) + std::string("\n");
for (auto s : m_options_with_after_string) {
ret += s.first + " " + (s.second.size() == 0? " \"option value\"":("\""+ s.second+"\"")) + "\n";
ret += s.first + " " + (s.second.empty()? " \"option value\"":("\""+ s.second+"\"")) + "\n";
}
return ret;
}
void print() {
if (m_used_options.size() == 0 && m_used_options_with_after_string.size() == 0 && m_free_args.size() == 0) {
if (m_used_options.empty() && m_used_options_with_after_string.empty() && m_free_args.empty()) {
std::cout << "no options are given" << std::endl;
return;
}
@ -146,7 +146,7 @@ public:
for (auto & t : m_used_options_with_after_string) {
std::cout << t.first << " " << t.second << std::endl;
}
if (m_free_args.size() > 0) {
if (!m_free_args.empty()) {
std::cout << "free arguments are: " << std::endl;
for (auto & t : m_free_args) {
std::cout << t << " " << std::endl;

View file

@ -1091,7 +1091,7 @@ void lp_solver_test() {
bool get_int_from_args_parser(const char * option, argument_parser & args_parser, unsigned & n) {
std::string s = args_parser.get_option_value(option);
if (s.size() > 0) {
if (!s.empty()) {
n = atoi(s.c_str());
return true;
}
@ -1100,7 +1100,7 @@ bool get_int_from_args_parser(const char * option, argument_parser & args_parser
bool get_double_from_args_parser(const char * option, argument_parser & args_parser, double & n) {
std::string s = args_parser.get_option_value(option);
if (s.size() > 0) {
if (!s.empty()) {
n = atof(s.c_str());
return true;
}
@ -1830,7 +1830,7 @@ std::unordered_map<std::string, double> * get_solution_from_glpsol_output(std::s
return nullptr;
}
auto split = string_split(s, " \t", false);
if (split.size() == 0) {
if (split.empty()) {
return ret;
}
@ -2050,14 +2050,14 @@ void finalize(unsigned ret) {
void get_time_limit_and_max_iters_from_parser(argument_parser & args_parser, unsigned & time_limit, unsigned & max_iters) {
std::string s = args_parser.get_option_value("--max_iters");
if (s.size() > 0) {
if (!s.empty()) {
max_iters = atoi(s.c_str());
} else {
max_iters = 0;
}
std::string time_limit_string = args_parser.get_option_value("--time_limit");
if (time_limit_string.size() > 0) {
if (!time_limit_string.empty()) {
time_limit = atoi(time_limit_string.c_str());
} else {
time_limit = 0;
@ -2156,7 +2156,7 @@ double get_lp_tst_cost(std::string file_name) {
cost_string = str;
}
}
if (cost_string.size() == 0) {
if (cost_string.empty()) {
std::cout << "cannot find the cost line in " << file_name << std::endl;
throw 0;
}
@ -2377,7 +2377,7 @@ std::unordered_map<std::string, lp::mpq> get_solution_map(lp_solver<lp::mpq, lp:
void run_lar_solver(argument_parser & args_parser, lar_solver * solver, mps_reader<lp::mpq, lp::mpq> * reader) {
std::string maxng = args_parser.get_option_value("--maxng");
if (maxng.size() > 0) {
if (!maxng.empty()) {
solver->settings().max_number_of_iterations_with_no_improvements = atoi(maxng.c_str());
}
if (args_parser.option_is_used("-pd")){
@ -2385,7 +2385,7 @@ void run_lar_solver(argument_parser & args_parser, lar_solver * solver, mps_read
}
std::string iter = args_parser.get_option_value("--max_iters");
if (iter.size() > 0) {
if (!iter.empty()) {
solver->settings().max_total_number_of_iterations = atoi(iter.c_str());
}
if (args_parser.option_is_used("--compare_with_primal")){
@ -2470,7 +2470,7 @@ vector<std::string> get_file_names_from_file_list(std::string filelist) {
std::string s = read_line(end, file);
if (end)
break;
if (s.size() == 0)
if (s.empty())
break;
ret.push_back(s);
} while (true);
@ -2480,13 +2480,13 @@ vector<std::string> get_file_names_from_file_list(std::string filelist) {
void test_lar_solver(argument_parser & args_parser) {
std::string file_name = args_parser.get_option_value("--file");
if (file_name.size() > 0) {
if (!file_name.empty()) {
test_lar_on_file(file_name, args_parser);
return;
}
std::string file_list = args_parser.get_option_value("--filelist");
if (file_list.size() > 0) {
if (!file_list.empty()) {
for (const std::string & fn : get_file_names_from_file_list(file_list))
test_lar_on_file(fn, args_parser);
return;
@ -3600,7 +3600,7 @@ void test_lp_local(int argn, char**argv) {
std::string lufile = args_parser.get_option_value("--checklu");
if (lufile.size()) {
if (!lufile.empty()) {
check_lu_from_file(lufile);
return finalize(0);
}
@ -3623,7 +3623,7 @@ void test_lp_local(int argn, char**argv) {
return finalize(0);
}
std::string file_list = args_parser.get_option_value("--filelist");
if (file_list.size() > 0) {
if (!file_list.empty()) {
for (const std::string & fn : get_file_names_from_file_list(file_list))
solve_mps(fn, args_parser);
return finalize(0);
@ -3704,7 +3704,7 @@ void test_lp_local(int argn, char**argv) {
bool dual = args_parser.option_is_used("--dual");
bool solve_for_rational = args_parser.option_is_used("--mpq");
std::string file_name = args_parser.get_option_value("--file");
if (file_name.size() > 0) {
if (!file_name.empty()) {
solve_mps(file_name, args_parser.option_is_used("--min"), max_iters, time_limit, solve_for_rational, dual, args_parser.option_is_used("--compare_with_primal"), args_parser);
ret = 0;
return finalize(ret);

View file

@ -52,7 +52,7 @@ namespace lp {
std::string m_head;
std::vector<lisp_elem> m_elems;
void print() {
if (m_elems.size()) {
if (!m_elems.empty()) {
std::cout << '(';
std::cout << m_head << ' ';
for (auto & el : m_elems)
@ -133,7 +133,7 @@ namespace lp {
lm.m_head = m_line.substr(0, separator);
m_line = m_line.substr(lm.m_head.size());
eat_blanks();
while (m_line.size()) {
while (!m_line.empty()) {
if (m_line[0] == '(') {
lisp_elem el;
fill_nested_elem(el);
@ -152,7 +152,7 @@ namespace lp {
}
void eat_blanks() {
while (m_line.size()) {
while (!m_line.empty()) {
if (m_line[0] == ' ')
m_line = m_line.substr(1);
else
@ -205,7 +205,7 @@ namespace lp {
bool is_integer(std::string & s) {
if (s.size() == 0) return false;
if (s.empty()) return false;
return atoi(s.c_str()) != 0 || isdigit(s.c_str()[0]);
}

View file

@ -41,7 +41,7 @@ static void tst1() {
v1.pop_back();
}
ENSURE(v1.empty());
ENSURE(v1.size() == 0);
ENSURE(v1.empty());
unsigned i = 1000000000;
while (true) {
std::cout << "resize " << i << "\n";