rivet is hosted by Hepforge, IPPP Durham
RivetSTL.hh
Go to the documentation of this file.
00001 #ifndef RIVET_RivetSTL_HH
00002 #define RIVET_RivetSTL_HH
00003 
00004 #include <typeinfo>
00005 #include <set>
00006 #include <list>
00007 #include <map>
00008 #include <utility>
00009 #include <string>
00010 #include <sstream>
00011 #include <vector>
00012 #include <stdexcept>
00013 #include <iostream>
00014 #include <iomanip>
00015 #include <cmath>
00016 #include <limits>
00017 #include <cassert>
00018 #include <fstream>
00019 #include <algorithm>
00020 
00021 namespace Rivet {
00022 
00023   /// @name Convenient imports of common STL classes and functions
00024   //@{
00025 
00026   using std::set;
00027   using std::map;
00028   using std::multimap;
00029   using std::type_info;
00030   using std::string;
00031   using std::stringstream;
00032   using std::less;
00033   using std::list;
00034   using std::vector;
00035   using std::pair;
00036   using std::make_pair;
00037   using std::runtime_error;
00038   using std::min;
00039   using std::max;
00040   using std::abs;
00041   using std::numeric_limits;
00042   using std::ostream;
00043   using std::istream;
00044   using std::cout;
00045   using std::cin;
00046   using std::cerr;
00047   using std::setw;
00048   using std::pow;
00049   using std::endl;
00050 
00051   //@}
00052 
00053 }
00054 
00055 #endif
00056 
00057 
00058 #ifndef CEDARSTD
00059 #define CEDARSTD
00060 
00061 namespace std {
00062 
00063 
00064   /// @name Standard library enhancements
00065   /// @todo Merge in nice ideas from mili: https://code.google.com/p/mili/
00066   //@{
00067 
00068   /// @name Boolean-return container searching
00069   //@{
00070 
00071   /// Does @a s contain @a sub as a substring?
00072   inline bool contains(const string& s, const string& sub) {
00073     return s.find(sub) != string::npos;
00074   }
00075 
00076   /// Does the vector @a v contain @a x?
00077   template <typename T>
00078   inline bool contains(const vector<T>& v, const T& x) {
00079     return find(v.begin(), v.end(), x) != v.end();
00080   }
00081 
00082   /// Does the list @a l contain @a x?
00083   template <typename T>
00084   inline bool contains(const list<T>& l, const T& x) {
00085     return find(l.begin(), l.end(), x) != l.end();
00086   }
00087 
00088   /// Does the set @a s contain @a x?
00089   template <typename T>
00090   inline bool contains(const set<T>& s, const T& x) {
00091     return find(s.begin(), s.end(), x) != s.end();
00092   }
00093 
00094   /// Does the map @a m contain the key @a key?
00095   template <typename K, typename T>
00096   inline bool has_key(const map<K, T>& m, const K& key) {
00097     return m.find(key) != m.end();
00098   }
00099 
00100   /// Does the map @a m contain the value @a val?
00101   template <typename K, typename T>
00102   inline bool has_value(const map<K, T>& m, const T& val) {
00103     for (typename map<K,T>::const_iterator it = m.begin(); it != m.end(); ++it) {
00104       if (it->second == val) return true;
00105     }
00106     return false;
00107   }
00108 
00109   //@}
00110 
00111 
00112   /// @name Container filling and merging
00113   //@{
00114 
00115   /// Append all the items from vector v2 to vector v1
00116   template <typename T>
00117   inline void operator+=(vector<T>& v1, const vector<T>& v2) {
00118     for (typename vector<T>::const_iterator s = v2.begin(); s != v2.end(); ++s) {
00119       v1.push_back(*s);
00120     }
00121   }
00122 
00123   /// Create a new vector from the concatenated items in vectors v1 and v2
00124   template <typename T>
00125   inline vector<T> operator+(const vector<T>& v1, const vector<T>& v2) {
00126     vector<T> rtn(v1);
00127     rtn += v2;
00128     return rtn;
00129   }
00130 
00131 
00132   /// Merge the contents of set @a s2 into @a s1
00133   template <typename T>
00134   inline void operator+=(set<T>& s1, const set<T>& s2) {
00135     for (typename set<T>::const_iterator s = s2.begin(); s != s2.end(); ++s) {
00136       s1.insert(*s);
00137     }
00138   }
00139 
00140   /// Merge the contents of sets @a s1 and @a s2
00141   template <typename T>
00142   inline set<T> operator+(const set<T>& s1, const set<T>& s2) {
00143     set<T> rtn(s1);
00144     rtn += s2;
00145     return rtn;
00146   }
00147 
00148   //@}
00149 
00150   //@}
00151 
00152 
00153 }
00154 
00155 #endif