Avoid importing the std namespace
This commit is contained in:
@@ -17,8 +17,6 @@
|
||||
|
||||
#include "Horus.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -29,43 +27,52 @@ const double NEG_INF = -std::numeric_limits<double>::infinity();
|
||||
|
||||
namespace Util {
|
||||
|
||||
template <typename T> void addToVector (vector<T>&, const vector<T>&);
|
||||
template <typename T> void
|
||||
addToVector (std::vector<T>&, const std::vector<T>&);
|
||||
|
||||
template <typename T> void addToSet (set<T>&, const vector<T>&);
|
||||
template <typename T> void
|
||||
addToSet (std::set<T>&, const std::vector<T>&);
|
||||
|
||||
template <typename T> void addToQueue (queue<T>&, const vector<T>&);
|
||||
template <typename T> void
|
||||
addToQueue (std::queue<T>&, const std::vector<T>&);
|
||||
|
||||
template <typename T> bool contains (const vector<T>&, const T&);
|
||||
template <typename T> bool
|
||||
contains (const std::vector<T>&, const T&);
|
||||
|
||||
template <typename T> bool contains (const set<T>&, const T&);
|
||||
template <typename T> bool contains
|
||||
(const std::set<T>&, const T&);
|
||||
|
||||
template <typename K, typename V> bool contains (
|
||||
const unordered_map<K, V>&, const K&);
|
||||
template <typename K, typename V> bool
|
||||
contains (const std::unordered_map<K, V>&, const K&);
|
||||
|
||||
template <typename T> size_t indexOf (const vector<T>&, const T&);
|
||||
template <typename T> size_t
|
||||
indexOf (const std::vector<T>&, const T&);
|
||||
|
||||
template <class Operation>
|
||||
void apply_n_times (Params& v1, const Params& v2,
|
||||
unsigned repetitions, Operation);
|
||||
template <class Operation> void
|
||||
apply_n_times (Params& v1, const Params& v2, unsigned reps, Operation);
|
||||
|
||||
template <typename T> void log (vector<T>&);
|
||||
template <typename T> void
|
||||
log (std::vector<T>&);
|
||||
|
||||
template <typename T> void exp (vector<T>&);
|
||||
template <typename T> void
|
||||
exp (std::vector<T>&);
|
||||
|
||||
template <typename T> string elementsToString (
|
||||
const vector<T>& v, string sep = " ");
|
||||
template <typename T> std::string
|
||||
elementsToString (const std::vector<T>& v, std::string sep = " ");
|
||||
|
||||
template <typename T> std::string toString (const T&);
|
||||
template <typename T> std::string
|
||||
toString (const T&);
|
||||
|
||||
template <> std::string toString (const bool&);
|
||||
template <> std::string
|
||||
toString (const bool&);
|
||||
|
||||
double logSum (double, double);
|
||||
|
||||
unsigned maxUnsigned (void);
|
||||
|
||||
unsigned stringToUnsigned (string);
|
||||
unsigned stringToUnsigned (std::string);
|
||||
|
||||
double stringToDouble (string);
|
||||
double stringToDouble (std::string);
|
||||
|
||||
double factorial (unsigned);
|
||||
|
||||
@@ -77,17 +84,18 @@ size_t sizeExpected (const Ranges&);
|
||||
|
||||
unsigned nrDigits (int);
|
||||
|
||||
bool isInteger (const string&);
|
||||
bool isInteger (const std::string&);
|
||||
|
||||
string parametersToString (const Params&, unsigned = Constants::PRECISION);
|
||||
std::string parametersToString (
|
||||
const Params&, unsigned = Constants::PRECISION);
|
||||
|
||||
vector<string> getStateLines (const Vars&);
|
||||
std::vector<std::string> getStateLines (const Vars&);
|
||||
|
||||
bool setHorusFlag (string option, string value);
|
||||
bool setHorusFlag (std::string option, std::string value);
|
||||
|
||||
void printHeader (string, std::ostream& os = std::cout);
|
||||
void printHeader (std::string, std::ostream& os = std::cout);
|
||||
|
||||
void printSubHeader (string, std::ostream& os = std::cout);
|
||||
void printSubHeader (std::string, std::ostream& os = std::cout);
|
||||
|
||||
void printAsteriskLine (std::ostream& os = std::cout);
|
||||
|
||||
@@ -98,7 +106,7 @@ void printDashedLine (std::ostream& os = std::cout);
|
||||
|
||||
|
||||
template <typename T> void
|
||||
Util::addToVector (vector<T>& v, const vector<T>& elements)
|
||||
Util::addToVector (std::vector<T>& v, const std::vector<T>& elements)
|
||||
{
|
||||
v.insert (v.end(), elements.begin(), elements.end());
|
||||
}
|
||||
@@ -106,7 +114,7 @@ Util::addToVector (vector<T>& v, const vector<T>& elements)
|
||||
|
||||
|
||||
template <typename T> void
|
||||
Util::addToSet (set<T>& s, const vector<T>& elements)
|
||||
Util::addToSet (std::set<T>& s, const std::vector<T>& elements)
|
||||
{
|
||||
s.insert (elements.begin(), elements.end());
|
||||
}
|
||||
@@ -114,7 +122,7 @@ Util::addToSet (set<T>& s, const vector<T>& elements)
|
||||
|
||||
|
||||
template <typename T> void
|
||||
Util::addToQueue (queue<T>& q, const vector<T>& elements)
|
||||
Util::addToQueue (std::queue<T>& q, const std::vector<T>& elements)
|
||||
{
|
||||
for (size_t i = 0; i < elements.size(); i++) {
|
||||
q.push (elements[i]);
|
||||
@@ -124,7 +132,7 @@ Util::addToQueue (queue<T>& q, const vector<T>& elements)
|
||||
|
||||
|
||||
template <typename T> bool
|
||||
Util::contains (const vector<T>& v, const T& e)
|
||||
Util::contains (const std::vector<T>& v, const T& e)
|
||||
{
|
||||
return std::find (v.begin(), v.end(), e) != v.end();
|
||||
}
|
||||
@@ -132,7 +140,7 @@ Util::contains (const vector<T>& v, const T& e)
|
||||
|
||||
|
||||
template <typename T> bool
|
||||
Util::contains (const set<T>& s, const T& e)
|
||||
Util::contains (const std::set<T>& s, const T& e)
|
||||
{
|
||||
return s.find (e) != s.end();
|
||||
}
|
||||
@@ -140,7 +148,7 @@ Util::contains (const set<T>& s, const T& e)
|
||||
|
||||
|
||||
template <typename K, typename V> bool
|
||||
Util::contains (const unordered_map<K, V>& m, const K& k)
|
||||
Util::contains (const std::unordered_map<K, V>& m, const K& k)
|
||||
{
|
||||
return m.find (k) != m.end();
|
||||
}
|
||||
@@ -148,7 +156,7 @@ Util::contains (const unordered_map<K, V>& m, const K& k)
|
||||
|
||||
|
||||
template <typename T> size_t
|
||||
Util::indexOf (const vector<T>& v, const T& e)
|
||||
Util::indexOf (const std::vector<T>& v, const T& e)
|
||||
{
|
||||
return std::distance (v.begin(),
|
||||
std::find (v.begin(), v.end(), e));
|
||||
@@ -157,7 +165,10 @@ Util::indexOf (const vector<T>& v, const T& e)
|
||||
|
||||
|
||||
template <class Operation> void
|
||||
Util::apply_n_times (Params& v1, const Params& v2, unsigned repetitions,
|
||||
Util::apply_n_times (
|
||||
Params& v1,
|
||||
const Params& v2,
|
||||
unsigned repetitions,
|
||||
Operation unary_op)
|
||||
{
|
||||
Params::iterator first = v1.begin();
|
||||
@@ -176,7 +187,7 @@ Util::apply_n_times (Params& v1, const Params& v2, unsigned repetitions,
|
||||
|
||||
|
||||
template <typename T> void
|
||||
Util::log (vector<T>& v)
|
||||
Util::log (std::vector<T>& v)
|
||||
{
|
||||
std::transform (v.begin(), v.end(), v.begin(), ::log);
|
||||
}
|
||||
@@ -184,17 +195,17 @@ Util::log (vector<T>& v)
|
||||
|
||||
|
||||
template <typename T> void
|
||||
Util::exp (vector<T>& v)
|
||||
Util::exp (std::vector<T>& v)
|
||||
{
|
||||
std::transform (v.begin(), v.end(), v.begin(), ::exp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T> string
|
||||
Util::elementsToString (const vector<T>& v, string sep)
|
||||
template <typename T> std::string
|
||||
Util::elementsToString (const std::vector<T>& v, std::string sep)
|
||||
{
|
||||
stringstream ss;
|
||||
std::stringstream ss;
|
||||
for (size_t i = 0; i < v.size(); i++) {
|
||||
ss << ((i != 0) ? sep : "") << v[i];
|
||||
}
|
||||
@@ -287,7 +298,7 @@ template <typename T>
|
||||
void operator+=(std::vector<T>& v, double val)
|
||||
{
|
||||
std::transform (v.begin(), v.end(), v.begin(),
|
||||
std::bind2nd (plus<double>(), val));
|
||||
std::bind2nd (std::plus<double>(), val));
|
||||
}
|
||||
|
||||
|
||||
@@ -296,7 +307,7 @@ template <typename T>
|
||||
void operator-=(std::vector<T>& v, double val)
|
||||
{
|
||||
std::transform (v.begin(), v.end(), v.begin(),
|
||||
std::bind2nd (minus<double>(), val));
|
||||
std::bind2nd (std::minus<double>(), val));
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +316,7 @@ template <typename T>
|
||||
void operator*=(std::vector<T>& v, double val)
|
||||
{
|
||||
std::transform (v.begin(), v.end(), v.begin(),
|
||||
std::bind2nd (multiplies<double>(), val));
|
||||
std::bind2nd (std::multiplies<double>(), val));
|
||||
}
|
||||
|
||||
|
||||
@@ -314,7 +325,7 @@ template <typename T>
|
||||
void operator/=(std::vector<T>& v, double val)
|
||||
{
|
||||
std::transform (v.begin(), v.end(), v.begin(),
|
||||
std::bind2nd (divides<double>(), val));
|
||||
std::bind2nd (std::divides<double>(), val));
|
||||
}
|
||||
|
||||
|
||||
@@ -324,7 +335,7 @@ void operator+=(std::vector<T>& a, const std::vector<T>& b)
|
||||
{
|
||||
assert (a.size() == b.size());
|
||||
std::transform (a.begin(), a.end(), b.begin(), a.begin(),
|
||||
plus<double>());
|
||||
std::plus<double>());
|
||||
}
|
||||
|
||||
|
||||
@@ -334,7 +345,7 @@ void operator-=(std::vector<T>& a, const std::vector<T>& b)
|
||||
{
|
||||
assert (a.size() == b.size());
|
||||
std::transform (a.begin(), a.end(), b.begin(), a.begin(),
|
||||
minus<double>());
|
||||
std::minus<double>());
|
||||
}
|
||||
|
||||
|
||||
@@ -344,7 +355,7 @@ void operator*=(std::vector<T>& a, const std::vector<T>& b)
|
||||
{
|
||||
assert (a.size() == b.size());
|
||||
std::transform (a.begin(), a.end(), b.begin(), a.begin(),
|
||||
multiplies<double>());
|
||||
std::multiplies<double>());
|
||||
}
|
||||
|
||||
|
||||
@@ -354,7 +365,7 @@ void operator/=(std::vector<T>& a, const std::vector<T>& b)
|
||||
{
|
||||
assert (a.size() == b.size());
|
||||
std::transform (a.begin(), a.end(), b.begin(), a.begin(),
|
||||
divides<double>());
|
||||
std::divides<double>());
|
||||
}
|
||||
|
||||
|
||||
@@ -363,7 +374,7 @@ template <typename T>
|
||||
void operator^=(std::vector<T>& v, double exp)
|
||||
{
|
||||
std::transform (v.begin(), v.end(), v.begin(),
|
||||
std::bind2nd (ptr_fun<double, double, double> (std::pow), exp));
|
||||
std::bind2nd (std::ptr_fun<double, double, double> (std::pow), exp));
|
||||
}
|
||||
|
||||
|
||||
@@ -372,13 +383,13 @@ template <typename T>
|
||||
void operator^=(std::vector<T>& v, int iexp)
|
||||
{
|
||||
std::transform (v.begin(), v.end(), v.begin(),
|
||||
std::bind2nd (ptr_fun<double, int, double> (std::pow), iexp));
|
||||
std::bind2nd (std::ptr_fun<double, int, double> (std::pow), iexp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator<< (std::ostream& os, const vector<T>& v)
|
||||
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v)
|
||||
{
|
||||
os << "[" ;
|
||||
os << Util::elementsToString (v, ", ");
|
||||
|
Reference in New Issue
Block a user