1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 15:55:37 +00:00

Torture yourself with namespace lookup 101

This commit is contained in:
Antonin Portelli 2018-03-05 19:58:13 +00:00
parent f32555dcc5
commit cd51b9af99
2 changed files with 46 additions and 43 deletions

View File

@ -43,12 +43,15 @@ See the full license in the file "LICENSE" in the top level distribution directo
namespace Grid {\ namespace Grid {\
using namespace QCD;\ using namespace QCD;\
namespace Hadrons {\ namespace Hadrons {\
using Grid::operator<<; using Grid::operator<<;\
using Grid::operator>>;
#define END_HADRONS_NAMESPACE }} #define END_HADRONS_NAMESPACE }}
#define BEGIN_MODULE_NAMESPACE(name)\ #define BEGIN_MODULE_NAMESPACE(name)\
namespace name {\ namespace name {\
using Grid::operator<<; using Grid::operator<<;\
using Grid::operator>>;
#define END_MODULE_NAMESPACE } #define END_MODULE_NAMESPACE }
/* the 'using Grid::operator<<;' statement prevents a very nasty compilation /* the 'using Grid::operator<<;' statement prevents a very nasty compilation

View File

@ -33,42 +33,6 @@ Author: Guido Cossu <guido.cossu@ed.ac.uk>
#include <type_traits> #include <type_traits>
namespace Grid { namespace Grid {
// Vector IO utilities ///////////////////////////////////////////////////////
// helper function to read space-separated values
template <typename T>
std::vector<T> strToVec(const std::string s)
{
std::istringstream sstr(s);
T buf;
std::vector<T> v;
while(!sstr.eof())
{
sstr >> buf;
v.push_back(buf);
}
return v;
}
// output to streams for vectors
template < class T >
inline std::ostream & operator<<(std::ostream &os, const std::vector<T> &v)
{
os << "[";
for (auto &x: v)
{
os << x << " ";
}
if (v.size() > 0)
{
os << "\b";
}
os << "]";
return os;
}
// Vector element trait ////////////////////////////////////////////////////// // Vector element trait //////////////////////////////////////////////////////
template <typename T> template <typename T>
struct element struct element
@ -151,15 +115,15 @@ namespace Grid {
do do
{ {
is.get(c); is.get(c);
} while (c != '<' && !is.eof()); } while (c != '{' && !is.eof());
if (c == '<') if (c == '{')
{ {
int start = is.tellg(); int start = is.tellg();
do do
{ {
is.get(c); is.get(c);
} while (c != '>' && !is.eof()); } while (c != '}' && !is.eof());
if (c == '>') if (c == '}')
{ {
int end = is.tellg(); int end = is.tellg();
int psize = end - start - 1; int psize = end - start - 1;
@ -182,7 +146,43 @@ namespace Grid {
template <class T1, class T2> template <class T1, class T2>
inline std::ostream & operator<<(std::ostream &os, const std::pair<T1, T2> &p) inline std::ostream & operator<<(std::ostream &os, const std::pair<T1, T2> &p)
{ {
os << "<" << p.first << " " << p.second << ">"; os << "{" << p.first << " " << p.second << "}";
return os;
}
// Vector IO utilities ///////////////////////////////////////////////////////
// helper function to read space-separated values
template <typename T>
std::vector<T> strToVec(const std::string s)
{
std::istringstream sstr(s);
T buf;
std::vector<T> v;
while(!sstr.eof())
{
sstr >> buf;
v.push_back(buf);
}
return v;
}
// output to streams for vectors
template < class T >
inline std::ostream & operator<<(std::ostream &os, const std::vector<T> &v)
{
os << "[";
for (auto &x: v)
{
os << x << " ";
}
if (v.size() > 0)
{
os << "\b";
}
os << "]";
return os; return os;
} }