thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.1.5
std.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // std.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2017 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef ThePEG_std_H
10 #define ThePEG_std_H
11 
25 #include <map>
26 #include <set>
27 #include <string>
28 #include <array>
29 #include <vector>
30 #include <list>
31 #include <iostream>
32 #include <fstream>
33 #include <sstream>
34 #include <iomanip>
35 #include <stack>
36 #include <utility>
37 #include <typeinfo>
38 #include <stdexcept>
39 #include <cmath>
40 
41 namespace std {
42 
49 template <>
50 struct less<const type_info *> :
51  public binary_function<const type_info *, const type_info *, bool>
52 {
57  bool operator()(const type_info * x, const type_info * y) const {
58  return x->before(*y); }
59 };
62 }
63 
64 namespace ThePEG {
65 
66 using std::array;
67 using std::deque;
68 using std::stack;
69 using std::vector;
70 using std::multiset;
71 using std::set;
72 using std::map;
73 using std::list;
74 using std::multimap;
75 using std::pair;
76 using std::make_pair;
77 using std::less;
78 using std::string;
79 using std::type_info;
80 using std::exception;
81 using std::range_error;
82 using std::ios;
83 using std::ostream;
84 using std::istream;
85 using std::ofstream;
86 using std::ifstream;
87 using std::ostringstream;
88 using std::istringstream;
89 using std::cin;
90 using std::cout;
91 using std::cerr;
92 using std::endl;
93 using std::flush;
94 using std::setprecision;
95 using std::setw;
96 using std::swap;
97 using std::min;
98 using std::max;
99 using std::mem_fun;
100 using std::sqrt;
101 //using std::pow;
102 using std::abs;
103 using std::atan2;
104 using std::isfinite;
105 
107 template <class ExponentT>
108 inline constexpr double pow(double x, ExponentT p) {
109  return std::pow(x,double(p));
110 }
111 
113 inline double sqrt(int x) {
114  return std::sqrt(double(x));
115 }
116 
118 inline constexpr long double factorial(unsigned int n) {
119  return (n < 2) ? 1.0 : n * factorial(n - 1);
120 }
121 
123 template <typename Container, typename Key>
124 inline bool member(const Container & c, const Key & k) {
125  return c.find(k) != c.end();
126 }
127 
129 template <typename T, typename Key>
130 inline bool member(const vector<T> & v, const Key & k) {
131  for ( typename vector<T>::const_iterator i = v.begin(); i != v.end(); ++i )
132  if ( *i == k ) return true;
133  return false;
134  // return find(v.begin(), v.end(), k) != v.end();
135 }
136 
138 template <typename Cont>
139 inline std::insert_iterator<Cont> inserter(Cont & c) {
140  return std::insert_iterator<Cont>(c, c.end());
141 }
142 
143 
146 template <typename T, typename A>
147 inline std::back_insert_iterator< vector<T,A> > inserter(vector<T,A> & v) {
148  return back_inserter(v);
149 }
150 
153 template <typename T, typename A>
154 inline std::back_insert_iterator< deque<T,A> > inserter(deque<T,A> & v) {
155  return back_inserter(v);
156 }
157 
159 inline ostream& left(ostream& os) {
160  os.setf(ios::left, ios::adjustfield);
161  return os;
162 }
163 
165 inline ostream& right(ostream& os) {
166  os.setf(ios::right, ios::adjustfield);
167  return os;
168 }
169 
170 }
171 
173 #define ThePEG_DECLARE_SET(VALTYPE,NAME) \
174  \
175  typedef set<VALTYPE, less<VALTYPE> > NAME
176 
178 #define ThePEG_DECLARE_MULTISET(VALTYPE,NAME) \
179  \
180  typedef multiset<VALTYPE, less<VALTYPE> > NAME
181 
183 #define ThePEG_DECLARE_MAP(KEYTYPE,VALTYPE,NAME) \
184  \
185  typedef map<KEYTYPE, VALTYPE, less<KEYTYPE> > NAME
186 
187 #endif /* ThePEG_std_H */
double sqrt(int x)
Square root of an integer.
Definition: std.h:113
constexpr double pow(double x, ExponentT p)
Powers - standard or non-standard.
Definition: std.h:108
bool member(const vector< T > &v, const Key &k)
Check if a given object is a part of a vector.
Definition: std.h:130
STL namespace.
std::back_insert_iterator< deque< T, A > > inserter(deque< T, A > &v)
Return an insert iterator for a given vector.
Definition: std.h:154
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
ostream & left(ostream &os)
Stream manipulator setting an ostream to left-adjust its ouput.
Definition: std.h:159
ostream & right(ostream &os)
Stream manipulator setting an ostream to right-adjust its ouput.
Definition: std.h:165
constexpr long double factorial(unsigned int n)
factorial
Definition: std.h:118