ThePEG  1.8.0
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-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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 <vector>
29 #include <list>
30 #include <iostream>
31 #include <fstream>
32 #include <sstream>
33 #include <iomanip>
34 #include <stack>
35 #include <utility>
36 #include <typeinfo>
37 #include <stdexcept>
38 #include <cmath>
39 
40 namespace std {
41 
48 template <>
49 struct less<const type_info *> :
50  public binary_function<const type_info *, const type_info *, bool>
51 {
56  bool operator()(const type_info * x, const type_info * y) const {
57  return x->before(*y); }
58 };
61 }
62 
64 // Workarounds for OS X
65 #if defined __APPLE__ && defined __MACH__
66 extern "C" int isnan(double) throw();
67 extern "C" int isinf(double) throw();
68 #endif
69 
71 namespace ThePEG {
72 
73 using std::deque;
74 using std::stack;
75 using std::vector;
76 using std::multiset;
77 using std::set;
78 using std::map;
79 using std::list;
80 using std::multimap;
81 using std::pair;
82 using std::make_pair;
83 using std::less;
84 using std::string;
85 using std::type_info;
86 using std::exception;
87 using std::range_error;
88 using std::ios;
89 using std::ostream;
90 using std::istream;
91 using std::ofstream;
92 using std::ifstream;
93 using std::ostringstream;
94 using std::istringstream;
95 using std::cin;
96 using std::cout;
97 using std::cerr;
98 using std::endl;
99 using std::flush;
100 using std::setprecision;
101 using std::setw;
102 using std::swap;
103 using std::min;
104 using std::max;
105 using std::mem_fun;
106 using std::sqrt;
107 using std::pow;
108 using std::atan2;
109 
111 inline double sqrt(int x) {
112  return std::sqrt(double(x));
113 }
114 
116 template <typename Container, typename Key>
117 inline bool member(const Container & c, const Key & k) {
118  return c.find(k) != c.end();
119 }
120 
122 template <typename T, typename Key>
123 inline bool member(const vector<T> & v, const Key & k) {
124  for ( typename vector<T>::const_iterator i = v.begin(); i != v.end(); ++i )
125  if ( *i == k ) return true;
126  return false;
127  // return find(v.begin(), v.end(), k) != v.end();
128 }
129 
131 template <typename Cont>
132 inline std::insert_iterator<Cont> inserter(Cont & c) {
133  return std::insert_iterator<Cont>(c, c.end());
134 }
135 
136 
139 template <typename T, typename A>
140 inline std::back_insert_iterator< vector<T,A> > inserter(vector<T,A> & v) {
141  return back_inserter(v);
142 }
143 
146 template <typename T, typename A>
147 inline std::back_insert_iterator< deque<T,A> > inserter(deque<T,A> & v) {
148  return back_inserter(v);
149 }
150 
152 inline ostream& left(ostream& os) {
153  os.setf(ios::left, ios::adjustfield);
154  return os;
155 }
156 
158 inline ostream& right(ostream& os) {
159  os.setf(ios::right, ios::adjustfield);
160  return os;
161 }
162 
163 }
164 
165 #ifndef ThePEG_WRAP_STL_CONTAINERS
166 
168 #define ThePEG_DECLARE_SET(VALTYPE,NAME) \
169  \
170  typedef set<VALTYPE, less<VALTYPE> > NAME
171 
173 #define ThePEG_DECLARE_MULTISET(VALTYPE,NAME) \
174  \
175  typedef multiset<VALTYPE, less<VALTYPE> > NAME
176 
178 #define ThePEG_DECLARE_MAP(KEYTYPE,VALTYPE,NAME) \
179  \
180  typedef map<KEYTYPE, VALTYPE, less<KEYTYPE> > NAME
181 
183 #define ThePEG_IMPLEMENT_SET(VALTYPE,NAME)
184 
186 #define ThePEG_IMPLEMENT_MULTISET(VALTYPE,NAME)
187 
189 #define ThePEG_IMPLEMENT_MAP(KEYTYPE,VALTYPE,NAME)
190 
191 #else
192 
194 #define ThePEG_DECLARE_SET(VALTYPE,NAME) \
195 class NAME : public set<VALTYPE, less<VALTYPE> > { \
196 public: \
197  typedef set<VALTYPE, less<VALTYPE> > SETTYPE; \
198  NAME(); \
199  explicit NAME(const key_compare & c, \
200  const allocator_type & a = allocator_type()); \
201  template <typename InputIterator> \
202  NAME(InputIterator first, InputIterator last) \
203  : SETTYPE(first, last) {} \
204  template <typename InputIterator> \
205  NAME(InputIterator first, InputIterator last, const key_compare & c, \
206  const allocator_type & a = allocator_type()) \
207  : SETTYPE(first, last, c, a) {} \
208  NAME(const SETTYPE & s); \
209  NAME(const NAME & s); \
210  ~NAME(); \
211  NAME & operator=(const NAME &); \
212  NAME & operator=(const SETTYPE &); \
213  pair<iterator,bool> insert(const value_type & x); \
214  iterator insert(iterator position, const value_type & x); \
215  template <typename InputIterator> \
216  void insert(InputIterator first, InputIterator last) { \
217  SETTYPE::insert(first, last); \
218  } \
219  void erase(iterator position); \
220  size_type erase(const key_type & x); \
221  void erase(iterator first, iterator last); \
222  void clear(); \
223  iterator find(const key_type & x) const; \
224  size_type count(const key_type & x) const; \
225  iterator lower_bound(const key_type & x) const; \
226  iterator upper_bound(const key_type & x) const; \
227  pair<iterator,iterator> equal_range(const key_type & x) const; \
228 }
229 
230 
232 #define ThePEG_DECLARE_MULTISET(VALTYPE,NAME) \
233 class NAME : \
234  public multiset<VALTYPE, less<VALTYPE> > { \
235 public: \
236  typedef multiset<VALTYPE, less<VALTYPE> > SETTYPE;\
237  NAME(); \
238  explicit NAME(const key_compare & c, \
239  const allocator_type & a = allocator_type()); \
240  template <typename InputIterator> \
241  NAME(InputIterator first, InputIterator last) \
242  : SETTYPE(first, last) {} \
243  template <typename InputIterator> \
244  NAME(InputIterator first, InputIterator last, const key_compare & c, \
245  const allocator_type & a = allocator_type()) \
246  : SETTYPE(first, last, c, a) {} \
247  NAME(const SETTYPE & s); \
248  NAME(const NAME & s); \
249  ~NAME(); \
250  NAME & operator=(const NAME &); \
251  NAME & operator=(const SETTYPE &); \
252  iterator insert(const value_type & x); \
253  iterator insert(iterator position, const value_type & x); \
254  template <typename InputIterator> \
255  void insert(InputIterator first, InputIterator last) { \
256  SETTYPE::insert(first, last); \
257  } \
258  void erase(iterator position); \
259  size_type erase(const key_type & x); \
260  void erase(iterator first, iterator last); \
261  void clear(); \
262  iterator find(const key_type & x) const; \
263  size_type count(const key_type & x) const; \
264  iterator lower_bound(const key_type & x) const; \
265  iterator upper_bound(const key_type & x) const; \
266  pair<iterator,iterator> equal_range(const key_type & x) const; \
267 }
268 
269 
271 #define ThePEG_DECLARE_MAP(KEYTYPE,VALTYPE,NAME) \
272 class NAME : \
273  public map<KEYTYPE, VALTYPE, less<KEYTYPE> > { \
274 public: \
275  typedef map<KEYTYPE, VALTYPE, less<KEYTYPE> > MAPTYPE; \
276  NAME(); \
277  explicit NAME(const key_compare & c, \
278  const allocator_type & a = allocator_type()); \
279  template <typename InputIterator> \
280  NAME(InputIterator first, InputIterator last) \
281  : MAPTYPE(first, last) {} \
282  template <typename InputIterator> \
283  NAME(InputIterator first, InputIterator last, const key_compare & c, \
284  const allocator_type & a = allocator_type()) \
285  : MAPTYPE(first, last, c, a) {} \
286  NAME(const NAME & s); \
287  NAME(const MAPTYPE & s); \
288  ~NAME(); \
289  NAME & operator=(const NAME &); \
290  NAME & operator=(const MAPTYPE &); \
291  data_type & operator[](const key_type & k); \
292  pair<iterator,bool> insert(const value_type & x); \
293  iterator insert(iterator position, const value_type & x); \
294  template <typename InputIterator> \
295  void insert(InputIterator first, InputIterator last) { \
296  MAPTYPE::insert(first, last); \
297  } \
298  void erase(iterator position); \
299  size_type erase(const key_type & x); \
300  void erase(iterator first, iterator last); \
301  void clear(); \
302  iterator find(const key_type & x); \
303  const_iterator find(const key_type & x) const; \
304  size_type count(const key_type & x) const; \
305  iterator lower_bound(const key_type & x); \
306  const_iterator lower_bound(const key_type & x) const; \
307  iterator upper_bound(const key_type & x); \
308  const_iterator upper_bound(const key_type & x) const; \
309  pair<iterator,iterator> equal_range(const key_type & x); \
310  pair<const_iterator,const_iterator> \
311  equal_range(const key_type & x) const; \
312 }
313 
314 
316 #define ThePEG_IMPLEMENT_SET(VALTYPE,NAME) \
317 NAME::NAME() {} \
318 NAME::NAME(const key_compare & c, const allocator_type & a) \
319  :SETTYPE(c, a) {} \
320 NAME::NAME(const NAME & x) : SETTYPE(x) {} \
321 NAME::NAME(const SETTYPE & x) : SETTYPE(x) {} \
322 NAME::~NAME() {} \
323 NAME & NAME::operator=(const NAME & x) { \
324  SETTYPE::operator=(x); \
325  return *this; \
326 } \
327 NAME & NAME::operator=(const SETTYPE & x) { \
328  SETTYPE::operator=(x); \
329  return *this; \
330 } \
331 pair<NAME::iterator,bool> NAME::insert(const value_type & x) { \
332  return SETTYPE::insert(x); \
333 } \
334 NAME::iterator NAME::insert(iterator position, const value_type & x) { \
335  return SETTYPE::insert(position, x); \
336 } \
337 void NAME::erase(iterator position) { \
338  SETTYPE::erase(position); \
339 } \
340 NAME::size_type NAME::erase(const key_type & x) { \
341  return SETTYPE::erase(x); \
342 } \
343 void NAME::erase(iterator first, iterator last) { \
344  SETTYPE::erase(first, last); \
345 } \
346 void NAME::clear() { \
347  SETTYPE::clear(); \
348 } \
349 NAME::iterator NAME::find(const key_type & x) const { \
350  return SETTYPE::find(x); \
351 } \
352 NAME::size_type NAME::count(const key_type & x) const { \
353  return SETTYPE::count(x); \
354 } \
355 NAME::iterator NAME::lower_bound(const key_type & x) const { \
356  return SETTYPE::lower_bound(x); \
357 } \
358 NAME::iterator NAME::upper_bound(const key_type & x) const { \
359  return SETTYPE::upper_bound(x); \
360 } \
361 pair<NAME::iterator,NAME::iterator> \
362 NAME::equal_range(const key_type & x) const { \
363  return SETTYPE::equal_range(x); \
364 } \
365 
366 
368 #define ThePEG_IMPLEMENT_MULTISET(VALTYPE,NAME) \
369 NAME::NAME() {} \
370 NAME::NAME(const key_compare & c, const allocator_type & a) \
371  :SETTYPE(c, a) {} \
372 NAME::NAME(const NAME & x) : SETTYPE(x) {} \
373 NAME::NAME(const SETTYPE & x) : SETTYPE(x) {} \
374 NAME::~NAME() {} \
375 NAME & NAME::operator=(const NAME & x) { \
376  SETTYPE::operator=(x); \
377  return *this; \
378 } \
379 NAME & NAME::operator=(const SETTYPE & x) { \
380  SETTYPE::operator=(x); \
381  return *this; \
382 } \
383 NAME::iterator NAME::insert(const value_type & x) { \
384  return SETTYPE::insert(x); \
385 } \
386 NAME::iterator NAME::insert(iterator position, const value_type & x) { \
387  return SETTYPE::insert(position, x); \
388 } \
389 void NAME::erase(iterator position) { \
390  SETTYPE::erase(position); \
391 } \
392 NAME::size_type NAME::erase(const key_type & x) { \
393  return SETTYPE::erase(x); \
394 } \
395 void NAME::erase(iterator first, iterator last) { \
396  SETTYPE::erase(first, last); \
397 } \
398 void NAME::clear() { \
399  SETTYPE::clear(); \
400 } \
401 NAME::iterator NAME::find(const key_type & x) const { \
402  return SETTYPE::find(x); \
403 } \
404 NAME::size_type NAME::count(const key_type & x) const { \
405  return SETTYPE::count(x); \
406 } \
407 NAME::iterator NAME::lower_bound(const key_type & x) const { \
408  return SETTYPE::lower_bound(x); \
409 } \
410 NAME::iterator NAME::upper_bound(const key_type & x) const { \
411  return SETTYPE::upper_bound(x); \
412 } \
413 pair<NAME::iterator,NAME::iterator> \
414 NAME::equal_range(const key_type & x) const { \
415  return SETTYPE::equal_range(x); \
416 } \
417 
418 
420 #define ThePEG_IMPLEMENT_MAP(KEYTYPE,VALTYPE,NAME) \
421 NAME::NAME() {} \
422 NAME::NAME(const key_compare & c, const allocator_type & a) \
423  :MAPTYPE(c, a) {} \
424 NAME::NAME(const NAME & x) : MAPTYPE(x) {} \
425 NAME::NAME(const MAPTYPE & x) : MAPTYPE(x) {} \
426 NAME::~NAME() {} \
427 NAME & NAME::operator=(const NAME & x) { \
428  MAPTYPE::operator=(x); \
429  return *this; \
430 } \
431 NAME & NAME::operator=(const MAPTYPE & x) { \
432  MAPTYPE::operator=(x); \
433  return *this; \
434 } \
435 pair<NAME::iterator,bool> NAME::insert(const value_type & x) { \
436  return MAPTYPE::insert(x); \
437 } \
438 NAME::iterator NAME::insert(iterator position, const value_type & x) { \
439  return MAPTYPE::insert(position, x); \
440 } \
441 void NAME::erase(iterator position) { \
442  MAPTYPE::erase(position); \
443 } \
444 NAME::size_type NAME::erase(const key_type & x) { \
445  return MAPTYPE::erase(x); \
446 } \
447 void NAME::erase(iterator first, iterator last) { \
448  MAPTYPE::erase(first, last); \
449 } \
450 void NAME::clear() { \
451  MAPTYPE::clear(); \
452 } \
453 NAME::iterator NAME::find(const key_type & x) { \
454  return MAPTYPE::find(x); \
455 } \
456 NAME::const_iterator NAME::find(const key_type & x) const { \
457  return MAPTYPE::find(x); \
458 } \
459 NAME::size_type NAME::count(const key_type & x) const { \
460  return MAPTYPE::count(x); \
461 } \
462 NAME::iterator NAME::lower_bound(const key_type & x) { \
463  return MAPTYPE::lower_bound(x); \
464 } \
465 NAME::const_iterator NAME::lower_bound(const key_type & x) const { \
466  return MAPTYPE::lower_bound(x); \
467 } \
468 NAME::iterator NAME::upper_bound(const key_type & x) { \
469  return MAPTYPE::upper_bound(x); \
470 } \
471 NAME::const_iterator NAME::upper_bound(const key_type & x) const { \
472  return MAPTYPE::upper_bound(x); \
473 } \
474 pair<NAME::iterator,NAME::iterator> \
475 NAME::equal_range(const key_type & x) { \
476  return MAPTYPE::equal_range(x); \
477 } \
478 pair<NAME::const_iterator,NAME::const_iterator> \
479 NAME::equal_range(const key_type & x) const { \
480  return MAPTYPE::equal_range(x); \
481 } \
482 NAME::data_type & NAME::operator[](const key_type & k) { \
483  return MAPTYPE::operator[](k); \
484 } \
485 
486 #endif
487 
488 // #include "std.icc"
489 #ifndef ThePEG_TEMPLATES_IN_CC_FILE
490 // #include "std.tcc"
491 #endif
492 
493 #endif /* ThePEG_std_H */
double sqrt(int x)
Square root of an integer.
Definition: std.h:111
bool member(const Container &c, const Key &k)
Check if a given object is a part of a container.
Definition: std.h:117
STL namespace.
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:152
std::insert_iterator< Cont > inserter(Cont &c)
Return an insert iterator for a given container.
Definition: std.h:132
ostream & right(ostream &os)
Stream manipulator setting an ostream to right-adjust its ouput.
Definition: std.h:158