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
-----
Spot uses some C++11 features, and therefore requires a C++11
compiler. However (1) fully C++11-compliant compilers are
not yet well deployed, and (2) development tools have yet
to be updated to provide suitable C++11 support. For instance
Swig 2.0, which we use for the Python bindings, does not
understand C++11. The upcoming release of Swig 3 has better
support for C++11, we should switch to it as soon as possible.
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(...)
compiler. The code relies on features that are not available in
version of g++ older than 4.8, so this is our minimum requirement
for now. Avoid features that require 4.9.
Reasonably recent versions of clang should work as well. Our
build farm has clang++ 3.5.
Encoding
--------
......
......@@ -353,9 +353,7 @@ namespace spot
{
int enum_count = d->get_state_variable_type_value_count(i);
for (int j = 0; j < enum_count; ++j)
enum_map[i]
.insert(std::make_pair(d->get_state_variable_type_value(i, j),
j));
enum_map[i].emplace(d->get_state_variable_type_value(i, j), j);
}
for (ltl::atomic_prop_set::const_iterator ap = aps->begin();
......
......@@ -259,7 +259,7 @@ transitions:
| transitions NUMBER opt_eols
{
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)
i.first->second |= *result.cur_guard;
++result.cur_guard;
......
......@@ -175,8 +175,7 @@ namespace spot
build_state d(dlabel, pend);
// Have we already seen this destination?
int dest;
std::pair<bs2num_map::iterator, bool> dres =
bs2num.insert(bs2num_map::value_type(d, 0));
auto dres = bs2num.emplace(d, 0);
if (!dres.second)
{
dest = dres.first->second;
......@@ -199,8 +198,7 @@ namespace spot
build_state d(label(a, i->current_state()), pend);
// Have we already seen this destination?
int dest;
std::pair<bs2num_map::iterator, bool> dres =
bs2num.insert(bs2num_map::value_type(d, 0));
auto dres = bs2num.emplace(d, 0);
if (!dres.second)
{
dest = dres.first->second;
......
......@@ -64,7 +64,7 @@ namespace spot
template <typename... 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)
{
unsigned s = g_.new_state(std::forward<Args>(args)...);
......@@ -81,7 +81,7 @@ namespace spot
/// \return true iff the newname was already used.
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
......
......@@ -91,7 +91,7 @@ namespace spot
atomic_prop::instance(const std::string& name, environment& env)
{
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)
ap = ires.first->second;
else
......
......@@ -504,8 +504,7 @@ namespace spot
}
const binop* res;
auto ires = instances.insert(std::make_pair(key(op, first, second),
nullptr));
auto ires = instances.emplace(key(op, first, second), nullptr);
if (!ires.second)
{
// This instance already exists.
......
......@@ -237,8 +237,7 @@ namespace spot
}
const formula* res;
auto ires = instances.insert(std::make_pair(key(op, child, min, max),
nullptr));
auto ires = instances.emplace(key(op, child, min, max), nullptr);
if (!ires.second)
{
// This instance already exists.
......
......@@ -595,7 +595,7 @@ namespace spot
const multop* res;
// Insert the key with the dummy nullptr just
// 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)
{
// The instance did already exists. Free v.
......
......@@ -300,7 +300,7 @@ namespace spot
}
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)
{
// This instance already exists.
......
......@@ -114,8 +114,7 @@ namespace spot
switch (bo->op())
{
case binop::EConcatMarked:
empairs.insert(std::make_pair(bo->first(),
bo->second()));
empairs.emplace(bo->first(), bo->second());
// fall through
case binop::Xor:
case binop::Implies:
......
......@@ -110,8 +110,7 @@ namespace spot
const formula* rename(const formula* old)
{
std::pair<map::iterator, bool> r =
newname.insert(map::value_type(old, 0));
auto r = newname.emplace(old, nullptr);
if (!r.second)
{
return r.first->second->clone();
......@@ -327,9 +326,7 @@ namespace spot
void
recurse(const formula* f)
{
std::pair<fgraph::iterator, bool> i =
g.insert(fgraph::value_type(f, succ_vec()));
auto i = g.emplace(f, succ_vec());
if (!s.empty())
{
const formula* top = s.top();
......@@ -356,6 +353,10 @@ namespace spot
{
unsigned num; // serial number, in pre-order
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,
const formula_ptr_hash> fmap_t;
......@@ -410,9 +411,9 @@ namespace spot
// std::cerr << " grand parent is "
// << to_string(e.grand_parent)
// << "\n child is " << to_string(child) << '\n';
data_entry d = { num, num };
std::pair<fmap_t::iterator, bool> i =
data.insert(fmap_t::value_type(child, d));
auto i = data.emplace(std::piecewise_construct,
std::forward_as_tuple(child),
std::forward_as_tuple(num, num));
if (i.second) // New destination.
{
++num;
......
......@@ -106,7 +106,7 @@ namespace spot
state_ta_product* init = new state_ta_product(
(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();
continue;
......@@ -216,7 +216,7 @@ namespace spot
// We do not need SUCC from now on.
// 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)
{
// Number it, stack it, and register its successors
......@@ -427,7 +427,7 @@ namespace spot
state* init = ta_init_it_.front();
ta_init_it_.pop();
if (!h.insert(std::make_pair(init, num + 1)).second)
if (!h.emplace(init, num + 1).second)
{
init->destroy();
continue;
......
......@@ -193,7 +193,7 @@ namespace spot
down_cast<state_ta_explicit*> (init_set.top());
init_set.pop();
if (!h.insert(std::make_pair(init, num + 1)).second)
if (!h.emplace(init, num + 1).second)
{
init->destroy();
continue;
......
......@@ -431,7 +431,7 @@ namespace spot
last_dest = dest;
dmi = dm.find(dest);
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();
typename acc_map::iterator it = dmi->second.find(acc);
......@@ -460,8 +460,7 @@ namespace spot
if (j != alias_.end())
return j->second;
State* res =
&(ls_.insert(std::make_pair(name, State(name))).first->second);
State* res = &(ls_.emplace(name, State(name)).first->second);
sl_[res] = name;
// The first state we add is the initial state.
// It can also be overridden with set_init_state().
......
......@@ -386,7 +386,7 @@ namespace spot
}
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)
{
// A previous transitions exist for k, merge the
......
......@@ -1184,8 +1184,8 @@ namespace spot
p.second, false);
state_complement* s2 = new state_complement(e->clone(), e->clone(),
p.second, true);
succ_list.insert(std::make_pair(p.first, s1));
succ_list.insert(std::make_pair(p.first, s2));
succ_list.emplace(p.first, s1);
succ_list.emplace(p.first, s2);
}
}
else
......@@ -1210,7 +1210,7 @@ namespace spot
{
st = new state_complement(e->clone(), e->clone(),
p.second, true);
succ_list.insert(std::make_pair(p.first, st));
succ_list.emplace(p.first, st);
}
condition = the_acceptance_cond_;
}
......@@ -1219,7 +1219,7 @@ namespace spot
for (auto& p: tr->second)
{
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;
......@@ -1234,7 +1234,7 @@ namespace spot
{
st = new state_complement(pending->clone(), e->clone(),
p.second, true);
succ_list.insert(std::make_pair(p.first, st));
succ_list.emplace(p.first, st);
}
delete pending;
......
......@@ -315,8 +315,8 @@ namespace spot
transmap_t::iterator id = transmap_.find(key);
if (id == transmap_.end()) // No
{
mapit_t pos = transmap_
.insert(std::make_pair(key, it->current_condition())).first;
mapit_t pos =
transmap_.emplace(key, it->current_condition()).first;
// Keep the order of the transitions in the
// degeneralized automaton related to the order of the
// transitions in the input automaton: in the past we
......
......@@ -66,8 +66,7 @@ namespace spot
enumerate_cycles::tagged_state
enumerate_cycles::tag_state(const state* s)
{
std::pair<tagged_state, bool> p =
tags_.insert(std::make_pair(s, state_info()));
auto p = tags_.emplace(s, state_info());
if (!p.second)
s->destroy();
return p.first;
......
......@@ -103,7 +103,7 @@ namespace spot
union_ |= set;
}
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
......@@ -144,8 +144,7 @@ namespace spot
bool check(const state* s)
{
std::pair<cache_t::iterator, bool> p =
cache_.insert(std::make_pair(s, false));
auto p = cache_.emplace(s, false);
if (p.second)
{
bdd all = a_->all_acceptance_conditions();
......@@ -569,9 +568,7 @@ namespace spot
if (use_lvl_cache)
{
std::pair<lvl_cache_t::iterator, bool> res =
lvl_cache.insert(lvl_cache_t::value_type(d.first,
d.second));
auto res = lvl_cache.emplace(d.first, d.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