Pol  Revision:cb584c9
stlutil.h
Go to the documentation of this file.
1 
11 #ifndef STLUTIL_H
12 #define STLUTIL_H
13 
14 #include "Header_Windows.h"
15 #include "compilerspecifics.h"
16 #include <cstring>
17 #include <sstream>
18 
19 namespace Pol
20 {
21 namespace Clib
22 {
23 template <class T>
24 void delete_all( T& coll )
25 {
26  while ( !coll.empty() )
27  {
28  delete coll.back();
29  coll.pop_back();
30  }
31 }
32 
33 template <class D, class S>
34 inline D implicit_cast( const S& s )
35 {
36  return s; // fails unless S can be converted to D implicitly
37 }
38 
39 template <class D, class S>
40 inline D explicit_cast( const S& s )
41 {
42  return static_cast<D>( s );
43 }
44 
45 template <class S1, class S2>
46 inline int stringicmp( const S1& str1, const S2& str2 )
47 {
48 #ifdef _WIN32
49  return _stricmp( str1.c_str(), str2.c_str() );
50 #else
51  return strcasecmp( str1.c_str(), str2.c_str() );
52 #endif
53 }
54 template <class S1, const char*>
55 inline int stringicmp( const S1& str1, const char* str2 )
56 {
57 #ifdef _WIN32
58  return _stricmp( str1.c_str(), str2 );
59 #else
60  return strcasecmp( str1.c_str(), str2 );
61 #endif
62 }
63 template <const char*, class S2>
64 inline int stringicmp( const char* str1, const S2& str2 )
65 {
66 #ifdef _WIN32
67  return _stricmp( str1, str2.c_str() );
68 #else
69  return strcasecmp( str1, str2.c_str() );
70 #endif
71 }
72 
73 #define ISTRINGSTREAM std::istringstream
74 
75 #define OSTRINGSTREAM std::ostringstream
76 #define OSTRINGSTREAM_STR( x ) x.str()
77 
78 template <class T>
79 std::string tostring( const T& v )
80 {
81  OSTRINGSTREAM os;
82  os << v;
83  return OSTRINGSTREAM_STR( os );
84 }
85 
86 template <class T, size_t N>
87 CONSTEXPR size_t arsize( T ( & )[N] )
88 {
89  return N;
90 }
91 }
92 }
93 
94 #endif
void delete_all(T &coll)
Definition: stlutil.h:24
#define CONSTEXPR
D implicit_cast(const S &s)
Definition: stlutil.h:34
#define OSTRINGSTREAM_STR(x)
Definition: stlutil.h:76
CONSTEXPR size_t arsize(T(&)[N])
Definition: stlutil.h:87
std::string tostring(const Bscript::BTokenType &v)
Definition: tokens.cpp:19
#define OSTRINGSTREAM
Definition: stlutil.h:75
int stringicmp(const S1 &str1, const S2 &str2)
Definition: stlutil.h:46
D explicit_cast(const S &s)
Definition: stlutil.h:40
Definition: berror.cpp:12