SigUtil  0.95
Utility modules for modern C++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sigutil.hpp
Go to the documentation of this file.
1 /*
2 Copyright© 2014 Akihiro Nishimura
3 
4 This software is released under the MIT License.
5 http://opensource.org/licenses/mit-license.php
6 */
7 
8 #ifndef SIG_UTIL_HPP
9 #define SIG_UTIL_HPP
10 
11 /*--------------------------------------- User Option --------------------------------------------------------------------*/
12 
13 #define SIG_ENABLE_BOOST 1 // boostが使用可能か
14 #define SIG_USE_OPTIONAL 1 // boost::optionalを使用するか(大規模データを扱う際にはオーバーヘッドが影響する可能性あり)
15 
16 /*------------------------------------------------------------------------------------------------------------------------*/
17 
18 #define SIG_UTIL_VERSION 095
19 
20 #if defined(_WIN32) || defined(_WIN64) // windows env
21  #ifdef _MSC_VER
22  #define SIG_MSVC_ENV 1
23  #endif
24 
25 #elif defined(__unix__) || defined(linux) // linux env
26  #define SIG_LINUX_ENV 1
27 
28  #if defined(__clang__)
29  #define SIG_CLANG_ENV 1
30  #elif defined(__GNUC__)
31  #define SIG_GCC_ENV 1
32  #endif
33 #endif
34 
35 // compiler version check
36 #ifdef SIG_MSVC_ENV
37  #ifdef _DEBUG
38  #define SIG_DEBUG_MODE 1
39  #endif
40 
41  #if _MSC_VER < 1800
42  static_assert(false, "require \"Visual C++ Compiler Nov 2013 CTP (CTP_Nov2013)\" to compile on msvc");
43  #elif _MSC_VER == 1800
44  #define SIG_MSVC_VER 120
45  #elif _MSC_VER == 1900
46  #define SIG_MSVC_VER 140
47  #endif
48 
49 #elif SIG_GCC_ENV
50  #if __GNUC__ > 4 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 0)
51  #define SIG_GCC_GT5_0_0 1
52  #elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
53  #define SIG_GCC_GT4_9_0 1
54  #elif (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
55  #define SIG_GCC_GT4_8_0 1
56  #endif
57 
58 #elif SIG_CLANG_ENV
59  #if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4)
60  #define SIG_CLANG_GT_3_4 1
61  #elif __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 5)
62  #define SIG_CLANG_GT_3_5 1
63  #endif
64 #endif
65 
66 
67 #define SIG_ENABLE_CONSTEXPR (SIG_MSVC_ENV && SIG_MSVC_VER > 140) || (SIG_GCC_ENV) || (SIG_CLANG_ENV)
68 
69 #define SIG_ENABLE_MOVEITERATOR (SIG_MSVC_ENV) || (SIG_GCC_ENV && SIG_GCC_GT5_0_0) || (SIG_CLANG_ENV)
70 
71 #define SIG_ENABLE_FOLDR SIG_MSVC_ENV || SIG_GCC_GT5_0_0 || SIG_CLANG_GT_3_5
72 
73 #define SIG_ENABLE_TUPLE_ZIP (SIG_MSVC_VER > 140) || SIG_GCC_GT4_9_0 || SIG_CLANG_GT_3_5
74 
75 
76 #include <assert.h>
77 #include <string>
78 #include <memory>
79 #include <functional>
80 #include <iostream>
81 #include <iomanip>
82 #include <algorithm>
83 #include <numeric>
84 #include <utility>
85 
86 #if SIG_MSVC_ENV || !SIG_ENABLE_BOOST
87 #include <regex>
88 #endif
89 
90 #if SIG_ENABLE_BOOST
91 #include <boost/pool/pool_alloc.hpp>
92 #include <boost/call_traits.hpp>
93 #endif
94 
95 
96 namespace sig{
97 #undef max
98 #undef min
99 
100 extern void* enabler;
101 
102 /* typedef */
103 using uint = std::size_t;
104 using StrPtr = std::shared_ptr< std::string >;
105 using C_StrPtr = std::shared_ptr< std::string const >;
106 using WStrPtr = std::shared_ptr< std::wstring >;
107 using C_WStrPtr = std::shared_ptr< std::wstring const >;
108 
109 using std::placeholders::_1;
110 using std::placeholders::_2;
111 
112 
113 #if SIG_ENABLE_BOOST
114  template <class T>
115  using fragment_allocator = boost::fast_pool_allocator<T>;
116 #else
117  template <class T>
118  using fragment_allocator = std::allocator<T>;
119 #endif
120 
121 
122 // boost.call_traits の有効・無効に関係なくコードを統一的に記述するための処理
123 #if SIG_ENABLE_BOOST
124  template <class T> using ParamType = typename boost::call_traits<T>::param_type;
125 #else
126  template <class T>
127  using ParamType = typename std::conditional<std::is_class<T>::value, T const&, T>::type;
128 #endif
129 
130 
131 // ファイルパスの文字型の指定
132 #if SIG_MSVC_ENV
133  using FilepassString = std::wstring;
134  using FilepassStringC = wchar_t const*;
135  template <class T> FilepassString to_fpstring(T v){ return std::to_wstring(v); }
136  inline void FileOpenErrorPrint(FilepassString const& pass){ std::wcout << L"file open error: " << pass << std::endl; }
137  #define SIG_TO_FPSTR(str) L ## str
138  #define SIG_USE_BOOST_FILESYSTEM 0
139 #else
140  using FilepassString = std::string;
141  using FilepassStringC = char const*;
142  template <class T> FilepassString to_fpstring(T v){ return std::to_string(v); }
143  inline void FileOpenErrorPrint(FilepassString const& pass){ std::cout << "file open error: " << pass << std::endl; }
144  #define SIG_TO_FPSTR(str) str
145  #define SIG_USE_BOOST_FILESYSTEM 1
146 #endif
147 
148 
149 #define SIG_FILE_LOCALE_INIT\
150  static bool first = true; \
151  if (first){\
152  std::locale::global(std::locale("")); \
153  first = false; \
154  }
155 }
156 
157 #endif
void * enabler
Definition: array.hpp:15