Commit fd5fbda4 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Use emplace() for associative containers.

* HACKING: Adjust requirements.  g++4.8 is now OK
for all our targets.
* iface/dve2/dve2.cc, src/dstarparse/dstarparse.yy
src/dstarparse/nsa2tgba.cc, src/graph/ngraph.hh,
src/ltlast/atomic_prop.cc, src/ltlast/binop.cc, src/ltlast/bunop.cc,
src/ltlast/multop.cc, src/ltlast/unop.cc, src/ltlvisit/mark.cc,
src/ltlvisit/relabel.cc, src/taalgos/emptinessta.cc,
src/taalgos/tgba2ta.cc, src/tgba/tgbaexplicit.hh, src/tgba/tgbagraph.hh,
src/tgba/tgbasafracomplement.cc, src/tgba/tgbatba.cc,
src/tgbaalgos/cycles.cc, src/tgbaalgos/degen.cc,
src/tgbaalgos/dtbasat.cc, src/tgbaalgos/dtgbasat.cc,
src/tgbaalgos/emptiness.cc, src/tgbaalgos/gtec/gtec.cc,
src/tgbaalgos/ltl2tgba_fm.cc, src/tgbaalgos/magic.cc,
src/tgbaalgos/ndfs_result.hxx, src/tgbaalgos/reachiter.cc,
src/tgbaalgos/scc.cc, src/tgbaalgos/sccfilter.cc, src/tgbaalgos/se05.cc,
src/tgbaalgos/simulation.cc, src/tgbaalgos/tau03.cc,
src/tgbaalgos/tau03opt.cc, src/tgbaalgos/weight.cc: Use emplace()
instead of insert(make_pair(...)) or insert(...::value_type(...)).
parent 1eaaf883
...@@ -229,25 +229,12 @@ C++11 ...@@ -229,25 +229,12 @@ C++11
----- -----
Spot uses some C++11 features, and therefore requires a C++11 Spot uses some C++11 features, and therefore requires a C++11
compiler. However (1) fully C++11-compliant compilers are compiler. The code relies on features that are not available in
not yet well deployed, and (2) development tools have yet version of g++ older than 4.8, so this is our minimum requirement
to be updated to provide suitable C++11 support. For instance for now. Avoid features that require 4.9.
Swig 2.0, which we use for the Python bindings, does not
understand C++11. The upcoming release of Swig 3 has better Reasonably recent versions of clang should work as well. Our
support for C++11, we should switch to it as soon as possible. build farm has clang++ 3.5.
In the meantime, try to keep the C++11-specific syntax in the *.cc
files as much as possible.
Use only C++11 features that are available in clang 3.1 and g++ 4.6:
- http://gcc.gnu.org/projects/cxx0x.html
- http://clang.llvm.org/cxx_status.html
Library interfaces that should not be used:
- emplace() is not implemented for associative containers
(std::map, std::set, and their unordered ffriends) is
before g++ 4.8. Use
x.insert(std::make_pair(...)) instead of x.emplace(...)
Encoding Encoding
-------- --------
......
...@@ -353,9 +353,7 @@ namespace spot ...@@ -353,9 +353,7 @@ namespace spot
{ {
int enum_count = d->get_state_variable_type_value_count(i); int enum_count = d->get_state_variable_type_value_count(i);
for (int j = 0; j < enum_count; ++j) for (int j = 0; j < enum_count; ++j)
enum_map[i] enum_map[i].emplace(d->get_state_variable_type_value(i, j), j);
.insert(std::make_pair(d->get_state_variable_type_value(i, j),
j));
} }
for (ltl::atomic_prop_set::const_iterator ap = aps->begin(); for (ltl::atomic_prop_set::const_iterator ap = aps->begin();
......
...@@ -259,7 +259,7 @@ transitions: ...@@ -259,7 +259,7 @@ transitions:
| transitions NUMBER opt_eols | transitions NUMBER opt_eols
{ {
std::pair<map_t::iterator, bool> i = std::pair<map_t::iterator, bool> i =
result.dest_map.insert(std::make_pair($2, *result.cur_guard)); result.dest_map.emplace($2, *result.cur_guard);
if (!i.second) if (!i.second)
i.first->second |= *result.cur_guard; i.first->second |= *result.cur_guard;
++result.cur_guard; ++result.cur_guard;
......
...@@ -175,8 +175,7 @@ namespace spot ...@@ -175,8 +175,7 @@ namespace spot
build_state d(dlabel, pend); build_state d(dlabel, pend);
// Have we already seen this destination? // Have we already seen this destination?
int dest; int dest;
std::pair<bs2num_map::iterator, bool> dres = auto dres = bs2num.emplace(d, 0);
bs2num.insert(bs2num_map::value_type(d, 0));
if (!dres.second) if (!dres.second)
{ {
dest = dres.first->second; dest = dres.first->second;
...@@ -199,8 +198,7 @@ namespace spot ...@@ -199,8 +198,7 @@ namespace spot
build_state d(label(a, i->current_state()), pend); build_state d(label(a, i->current_state()), pend);
// Have we already seen this destination? // Have we already seen this destination?
int dest; int dest;
std::pair<bs2num_map::iterator, bool> dres = auto dres = bs2num.emplace(d, 0);
bs2num.insert(bs2num_map::value_type(d, 0));
if (!dres.second) if (!dres.second)
{ {
dest = dres.first->second; dest = dres.first->second;
......
...@@ -64,7 +64,7 @@ namespace spot ...@@ -64,7 +64,7 @@ namespace spot
template <typename... Args> template <typename... Args>
state new_state(name n, Args&&... args) state new_state(name n, Args&&... args)
{ {
auto p = name_to_state.insert(std::make_pair(n, 0U)); auto p = name_to_state.emplace(n, 0U);
if (p.second) if (p.second)
{ {
unsigned s = g_.new_state(std::forward<Args>(args)...); unsigned s = g_.new_state(std::forward<Args>(args)...);
...@@ -81,7 +81,7 @@ namespace spot ...@@ -81,7 +81,7 @@ namespace spot
/// \return true iff the newname was already used. /// \return true iff the newname was already used.
bool alias_state(state s, name newname) bool alias_state(state s, name newname)
{ {
return !name_to_state.insert(std::make_pair(newname, s)).second; return !name_to_state.emplace(newname, s).second;
} }
state get_state(name n) const state get_state(name n) const
......
...@@ -91,7 +91,7 @@ namespace spot ...@@ -91,7 +91,7 @@ namespace spot
atomic_prop::instance(const std::string& name, environment& env) atomic_prop::instance(const std::string& name, environment& env)
{ {
const atomic_prop* ap; const atomic_prop* ap;
auto ires = instances.insert(std::make_pair(key(name, &env), nullptr)); auto ires = instances.emplace(key(name, &env), nullptr);
if (!ires.second) if (!ires.second)
ap = ires.first->second; ap = ires.first->second;
else else
......
...@@ -504,8 +504,7 @@ namespace spot ...@@ -504,8 +504,7 @@ namespace spot
} }
const binop* res; const binop* res;
auto ires = instances.insert(std::make_pair(key(op, first, second), auto ires = instances.emplace(key(op, first, second), nullptr);
nullptr));
if (!ires.second) if (!ires.second)
{ {
// This instance already exists. // This instance already exists.
......
...@@ -237,8 +237,7 @@ namespace spot ...@@ -237,8 +237,7 @@ namespace spot
} }
const formula* res; const formula* res;
auto ires = instances.insert(std::make_pair(key(op, child, min, max), auto ires = instances.emplace(key(op, child, min, max), nullptr);
nullptr));
if (!ires.second) if (!ires.second)
{ {
// This instance already exists. // This instance already exists.
......
...@@ -595,7 +595,7 @@ namespace spot ...@@ -595,7 +595,7 @@ namespace spot
const multop* res; const multop* res;
// Insert the key with the dummy nullptr just // Insert the key with the dummy nullptr just
// to check if p already exists. // to check if p already exists.
auto ires = instances.insert(std::make_pair(key(op, v), nullptr)); auto ires = instances.emplace(key(op, v), nullptr);
if (!ires.second) if (!ires.second)
{ {
// The instance did already exists. Free v. // The instance did already exists. Free v.
......
...@@ -300,7 +300,7 @@ namespace spot ...@@ -300,7 +300,7 @@ namespace spot
} }
const unop* res; const unop* res;
auto ires = instances.insert(std::make_pair(key(op, child), nullptr)); auto ires = instances.emplace(key(op, child), nullptr);
if (!ires.second) if (!ires.second)
{ {
// This instance already exists. // This instance already exists.
......
...@@ -114,8 +114,7 @@ namespace spot ...@@ -114,8 +114,7 @@ namespace spot
switch (bo->op()) switch (bo->op())
{ {
case binop::EConcatMarked: case binop::EConcatMarked:
empairs.insert(std::make_pair(bo->first(), empairs.emplace(bo->first(), bo->second());
bo->second()));
// fall through // fall through
case binop::Xor: case binop::Xor:
case binop::Implies: case binop::Implies:
......
...@@ -110,8 +110,7 @@ namespace spot ...@@ -110,8 +110,7 @@ namespace spot
const formula* rename(const formula* old) const formula* rename(const formula* old)
{ {
std::pair<map::iterator, bool> r = auto r = newname.emplace(old, nullptr);
newname.insert(map::value_type(old, 0));
if (!r.second) if (!r.second)
{ {
return r.first->second->clone(); return r.first->second->clone();
...@@ -327,9 +326,7 @@ namespace spot ...@@ -327,9 +326,7 @@ namespace spot
void void
recurse(const formula* f) recurse(const formula* f)
{ {
std::pair<fgraph::iterator, bool> i = auto i = g.emplace(f, succ_vec());
g.insert(fgraph::value_type(f, succ_vec()));
if (!s.empty()) if (!s.empty())
{ {
const formula* top = s.top(); const formula* top = s.top();
...@@ -356,6 +353,10 @@ namespace spot ...@@ -356,6 +353,10 @@ namespace spot
{ {
unsigned num; // serial number, in pre-order unsigned num; // serial number, in pre-order
unsigned low; // lowest number accessible via unstacked descendants unsigned low; // lowest number accessible via unstacked descendants
data_entry(unsigned num = 0, unsigned low = 0)
: num(num), low(low)
{
}
}; };
typedef std::unordered_map<const formula*, data_entry, typedef std::unordered_map<const formula*, data_entry,
const formula_ptr_hash> fmap_t; const formula_ptr_hash> fmap_t;
...@@ -410,9 +411,9 @@ namespace spot ...@@ -410,9 +411,9 @@ namespace spot
// std::cerr << " grand parent is " // std::cerr << " grand parent is "
// << to_string(e.grand_parent) // << to_string(e.grand_parent)
// << "\n child is " << to_string(child) << '\n'; // << "\n child is " << to_string(child) << '\n';
data_entry d = { num, num }; auto i = data.emplace(std::piecewise_construct,
std::pair<fmap_t::iterator, bool> i = std::forward_as_tuple(child),
data.insert(fmap_t::value_type(child, d)); std::forward_as_tuple(num, num));
if (i.second) // New destination. if (i.second) // New destination.
{ {
++num; ++num;
......
...@@ -106,7 +106,7 @@ namespace spot ...@@ -106,7 +106,7 @@ namespace spot
state_ta_product* init = new state_ta_product( state_ta_product* init = new state_ta_product(
(ta_init_it_->current_state()), kripke_init_state->clone()); (ta_init_it_->current_state()), kripke_init_state->clone());
if (!h.insert(std::make_pair(init, num + 1)).second) if (!h.emplace(init, num + 1).second)
{ {
init->destroy(); init->destroy();
continue; continue;
...@@ -216,7 +216,7 @@ namespace spot ...@@ -216,7 +216,7 @@ namespace spot
// We do not need SUCC from now on. // We do not need SUCC from now on.
// Are we going to a new state? // Are we going to a new state?
auto p = h.insert(std::make_pair(dest, num + 1)); auto p = h.emplace(dest, num + 1);
if (p.second) if (p.second)
{ {
// Number it, stack it, and register its successors // Number it, stack it, and register its successors
...@@ -427,7 +427,7 @@ namespace spot ...@@ -427,7 +427,7 @@ namespace spot
state* init = ta_init_it_.front(); state* init = ta_init_it_.front();
ta_init_it_.pop(); ta_init_it_.pop();
if (!h.insert(std::make_pair(init, num + 1)).second) if (!h.emplace(init, num + 1).second)
{ {
init->destroy(); init->destroy();
continue; continue;
......
...@@ -193,7 +193,7 @@ namespace spot ...@@ -193,7 +193,7 @@ namespace spot
down_cast<state_ta_explicit*> (init_set.top()); down_cast<state_ta_explicit*> (init_set.top());
init_set.pop(); init_set.pop();
if (!h.insert(std::make_pair(init, num + 1)).second) if (!h.emplace(init, num + 1).second)
{ {
init->destroy(); init->destroy();
continue; continue;
......
...@@ -431,7 +431,7 @@ namespace spot ...@@ -431,7 +431,7 @@ namespace spot
last_dest = dest; last_dest = dest;
dmi = dm.find(dest); dmi = dm.find(dest);
if (dmi == dm.end()) if (dmi == dm.end())
dmi = dm.insert(std::make_pair(dest, acc_map())).first; dmi = dm.emplace(dest, acc_map()).first;
} }
int acc = t1->acceptance_conditions.id(); int acc = t1->acceptance_conditions.id();
typename acc_map::iterator it = dmi->second.find(acc); typename acc_map::iterator it = dmi->second.find(acc);
...@@ -460,8 +460,7 @@ namespace spot ...@@ -460,8 +460,7 @@ namespace spot
if (j != alias_.end()) if (j != alias_.end())
return j->second; return j->second;
State* res = State* res = &(ls_.emplace(name, State(name)).first->second);
&(ls_.insert(std::make_pair(name, State(name))).first->second);
sl_[res] = name; sl_[res] = name;
// The first state we add is the initial state. // The first state we add is the initial state.
// It can also be overridden with set_init_state(). // It can also be overridden with set_init_state().
......
...@@ -386,7 +386,7 @@ namespace spot ...@@ -386,7 +386,7 @@ namespace spot
} }
key_t k(t->dst, t->acc.id()); key_t k(t->dst, t->acc.id());
auto p = trmap.insert(make_pair(k, t.trans())); auto p = trmap.emplace(k, t.trans());
if (!p.second) if (!p.second)
{ {
// A previous transitions exist for k, merge the // A previous transitions exist for k, merge the
......
...@@ -1184,8 +1184,8 @@ namespace spot ...@@ -1184,8 +1184,8 @@ namespace spot
p.second, false); p.second, false);
state_complement* s2 = new state_complement(e->clone(), e->clone(), state_complement* s2 = new state_complement(e->clone(), e->clone(),
p.second, true); p.second, true);
succ_list.insert(std::make_pair(p.first, s1)); succ_list.emplace(p.first, s1);
succ_list.insert(std::make_pair(p.first, s2)); succ_list.emplace(p.first, s2);
} }
} }
else else
...@@ -1210,7 +1210,7 @@ namespace spot ...@@ -1210,7 +1210,7 @@ namespace spot
{ {
st = new state_complement(e->clone(), e->clone(), st = new state_complement(e->clone(), e->clone(),
p.second, true); p.second, true);
succ_list.insert(std::make_pair(p.first, st)); succ_list.emplace(p.first, st);
} }
condition = the_acceptance_cond_; condition = the_acceptance_cond_;
} }
...@@ -1219,7 +1219,7 @@ namespace spot ...@@ -1219,7 +1219,7 @@ namespace spot
for (auto& p: tr->second) for (auto& p: tr->second)
{ {
st = new state_complement(newI, newJ, p.second, true); st = new state_complement(newI, newJ, p.second, true);
succ_list.insert(std::make_pair(p.first, st)); succ_list.emplace(p.first, st);
} }
} }
delete newI; delete newI;
...@@ -1234,7 +1234,7 @@ namespace spot ...@@ -1234,7 +1234,7 @@ namespace spot
{ {
st = new state_complement(pending->clone(), e->clone(), st = new state_complement(pending->clone(), e->clone(),
p.second, true); p.second, true);
succ_list.insert(std::make_pair(p.first, st)); succ_list.emplace(p.first, st);
} }
delete pending; delete pending;
......
...@@ -315,8 +315,8 @@ namespace spot ...@@ -315,8 +315,8 @@ namespace spot
transmap_t::iterator id = transmap_.find(key); transmap_t::iterator id = transmap_.find(key);
if (id == transmap_.end()) // No if (id == transmap_.end()) // No
{ {
mapit_t pos = transmap_ mapit_t pos =
.insert(std::make_pair(key, it->current_condition())).first; transmap_.emplace(key, it->current_condition()).first;
// Keep the order of the transitions in the // Keep the order of the transitions in the
// degeneralized automaton related to the order of the // degeneralized automaton related to the order of the
// transitions in the input automaton: in the past we // transitions in the input automaton: in the past we
......
...@@ -66,8 +66,7 @@ namespace spot ...@@ -66,8 +66,7 @@ namespace spot
enumerate_cycles::tagged_state enumerate_cycles::tagged_state
enumerate_cycles::tag_state(const state* s) enumerate_cycles::tag_state(const state* s)
{ {
std::pair<tagged_state, bool> p = auto p = tags_.emplace(s, state_info());
tags_.insert(std::make_pair(s, state_info()));
if (!p.second) if (!p.second)
s->destroy(); s->destroy();
return p.first; return p.first;
......
...@@ -103,7 +103,7 @@ namespace spot ...@@ -103,7 +103,7 @@ namespace spot
union_ |= set; union_ |= set;
} }
cache_entry e(common, union_); cache_entry e(common, union_);
return cache_.insert(std::make_pair(s, e)).first; return cache_.emplace(s, e).first;
} }
// Intersection of all outgoing acceptance sets // Intersection of all outgoing acceptance sets
...@@ -144,8 +144,7 @@ namespace spot ...@@ -144,8 +144,7 @@ namespace spot
bool check(const state* s) bool check(const state* s)
{ {
std::pair<cache_t::iterator, bool> p = auto p = cache_.emplace(s, false);
cache_.insert(std::make_pair(s, false));
if (p.second) if (p.second)
{ {
bdd all = a_->all_acceptance_conditions(); bdd all = a_->all_acceptance_conditions();
...@@ -569,9 +568,7 @@ namespace spot ...@@ -569,9 +568,7 @@ namespace spot
if (use_lvl_cache) if (use_lvl_cache)
{ {
std::pair<lvl_cache_t::iterator, bool> res = auto res = lvl_cache.emplace(d.first, d.second);
lvl_cache.insert(lvl_cache_t::value_type(d.first,
d.second));
if (!res.second) if (!res.second)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment