41 #ifndef __USE_STD_IOSTREAM
42 # define __USE_STD_IOSTREAM
53 #if defined(_MSC_VER) && _MSC_VER >= 1400
54 # define GMM_SECURE_CRT
55 # define SECURE_NONCHAR_SSCANF sscanf_s
56 # define SECURE_NONCHAR_FSCANF fscanf_s
57 # define SECURE_STRNCPY(a, la, b, lb) strncpy_s(a, la, b, lb)
58 # define SECURE_FOPEN(F, filename, mode) (*(F) = 0, fopen_s(F, filename, mode))
59 # define SECURE_SPRINTF1(S, l, st, p1) sprintf_s(S, l, st, p1)
60 # define SECURE_SPRINTF2(S, l, st, p1, p2) sprintf_s(S, l, st, p1, p2)
61 # define SECURE_SPRINTF4(S, l, st, p1, p2, p3, p4) sprintf_s(S, l, st, p1, p2, p3, p4)
62 # define SECURE_STRDUP(s) _strdup(s)
63 # ifndef _CRT_SECURE_NO_DEPRECATE
64 # error Add _CRT_SECURE_NO_DEPRECATE to your compilation options, Microsoft is overstrict (e.g. bans fopen) without offering portable alternatives
67 # define SECURE_NONCHAR_SSCANF sscanf
68 # define SECURE_NONCHAR_FSCANF fscanf
69 # define SECURE_STRNCPY(a, la, b, lb) strncpy(a, b, lb)
70 # define SECURE_FOPEN(F, filename, mode) ((*(F)) = fopen(filename, mode))
71 # define SECURE_SPRINTF1(S, l, st, p1) snprintf(S, l, st, p1)
72 # define SECURE_SPRINTF2(S, l, st, p1, p2) snprintf(S, l, st, p1, p2)
73 # define SECURE_SPRINTF4(S, l, st, p1, p2, p3, p4) snprintf(S, l, st, p1, p2, p3, p4)
74 # define SECURE_STRDUP(s) strdup(s)
77 inline void GMM_NOPERATION_(
int) { }
78 #define GMM_NOPERATION(a) { GMM_NOPERATION_(abs(&(a) != &(a))); }
92 # error : PLEASE UPDATE g++ TO AT LEAST 4.8 VERSION
127 #include <gmm/gmm_arch_config.h>
130 #if defined(__GNUC__) && (__cplusplus <= 201103L)
131 template<
typename _Tp>
133 {
typedef unique_ptr<_Tp> __single_object; };
134 template<
typename _Tp>
135 struct _MakeUniq<_Tp[]>
136 {
typedef unique_ptr<_Tp[]> __array; };
137 template<
typename _Tp,
size_t _Bound>
138 struct _MakeUniq<_Tp[_Bound]>
139 {
struct __invalid_type { }; };
141 template<
typename _Tp,
typename... _Args>
142 inline typename _MakeUniq<_Tp>::__single_object
143 make_unique(_Args&&... __args)
144 {
return unique_ptr<_Tp>(
new _Tp(std::forward<_Args>(__args)...)); }
146 template<
typename _Tp>
147 inline typename _MakeUniq<_Tp>::__array
148 make_unique(
size_t __num)
149 {
return unique_ptr<_Tp>(
new typename remove_extent<_Tp>::type[__num]()); }
151 template<
typename _Tp,
typename... _Args>
152 inline typename _MakeUniq<_Tp>::__invalid_type
153 make_unique(_Args&&...) =
delete;
159 template <
typename T>
class shared_array_ptr : shared_ptr<T> {
161 shared_array_ptr() {}
162 shared_array_ptr(T *q) : std::shared_ptr<T>(q, default_delete<T[]>()) {}
163 template <
typename Y> shared_array_ptr(
const std::shared_ptr<Y> &p, T *q)
164 : std::shared_ptr<T>(p, q) {}
165 T *get()
const {
return shared_ptr<T>::get(); }
166 T& operator*()
const {
return shared_ptr<T>::operator*(); }
167 T* operator->()
const {
return shared_ptr<T>::operator->(); }
170 template <
typename T> shared_array_ptr<T> make_shared_array(
size_t num)
171 {
return shared_array_ptr<T>(
new T[num]); }
176 using std::endl;
using std::cout;
using std::cerr;
177 using std::ends;
using std::cin;
using std::isnan;
179 class standard_locale {
184 inline standard_locale(
void)
185 : cloc(setlocale(LC_NUMERIC, 0)), cinloc(cin.getloc())
186 { setlocale(LC_NUMERIC,
"C"); cin.imbue(std::locale(
"C")); }
187 inline ~standard_locale()
188 { setlocale(LC_NUMERIC, cloc.c_str()); cin.imbue(cinloc); }
191 class stream_standard_locale {
196 inline stream_standard_locale(std::ios &i)
197 : cloc(i.getloc()), io(i) { io.imbue(std::locale(
"C")); }
198 inline ~stream_standard_locale() { io.imbue(cloc); }
205 # if defined(HAVE_SYS_TIMES)
206 inline double uclock_sec(
void) {
207 static double ttclk = 0.;
208 if (ttclk == 0.) ttclk = sysconf(_SC_CLK_TCK);
209 tms t; times(&t);
return double(t.tms_utime) / ttclk;
212 inline double uclock_sec(
void)
213 {
return double(clock())/double(CLOCKS_PER_SEC); }
222 template <
size_t s>
struct fixed_size_integer_generator {
223 typedef void int_base_type;
224 typedef void uint_base_type;
227 template <>
struct fixed_size_integer_generator<sizeof(char)> {
228 typedef signed char int_base_type;
229 typedef unsigned char uint_base_type;
232 template <>
struct fixed_size_integer_generator<sizeof(short int)
233 - ((sizeof(short int) ==
sizeof(char)) ? 78 : 0)> {
234 typedef signed short int int_base_type;
235 typedef unsigned short int uint_base_type;
238 template <>
struct fixed_size_integer_generator<sizeof(int)
239 - ((sizeof(int) ==
sizeof(
short int)) ? 59 : 0)> {
240 typedef signed int int_base_type;
241 typedef unsigned int uint_base_type;
244 template <>
struct fixed_size_integer_generator<sizeof(long)
245 - ((sizeof(int) ==
sizeof(long)) ? 93 : 0)> {
246 typedef signed long int_base_type;
247 typedef unsigned long uint_base_type;
250 template <>
struct fixed_size_integer_generator<sizeof(long long)
251 - ((sizeof(long long) ==
sizeof(long)) ? 99 : 0)> {
252 typedef signed long long int_base_type;
253 typedef unsigned long long uint_base_type;
256 typedef fixed_size_integer_generator<1>::int_base_type int8_type;
257 typedef fixed_size_integer_generator<1>::uint_base_type uint8_type;
258 typedef fixed_size_integer_generator<2>::int_base_type int16_type;
259 typedef fixed_size_integer_generator<2>::uint_base_type uint16_type;
260 typedef fixed_size_integer_generator<4>::int_base_type int32_type;
261 typedef fixed_size_integer_generator<4>::uint_base_type uint32_type;
262 typedef fixed_size_integer_generator<8>::int_base_type int64_type;
263 typedef fixed_size_integer_generator<8>::uint_base_type uint64_type;
301 #if defined(__GNUC__) && !defined(__ICC)
306 # define IS_DEPRECATED __attribute__ ((__deprecated__))
310 # define ALWAYS_INLINE __attribute__((always_inline))
312 # define IS_DEPRECATED
313 # define ALWAYS_INLINE
316 #if defined(_MSC_VER) || defined(__INTEL_COMPILER)
317 # define NOINLINE __declspec(noinline)
318 #elif defined(__GNUC__) && !defined(__ICC)
319 # define NOINLINE __attribute__((noinline))
328 #if defined(EXPORTED_TO_SHARED_LIB)
329 # if defined(_MSC_VER) || defined(__INTEL_COMPILER)
330 # define APIDECL __declspec(dllexport)
331 # elif defined(__GNUC__)
332 # define __attribute__((visibility("default")))
336 # if defined(IMPORTED_FROM_SHARED_LIB)
337 # error INTENTIONAL COMPILATION ERROR, DLL IMPORT AND EXPORT ARE INCOMPATIBLE
341 #if defined(IMPORTED_FROM_SHARED_LIB)
342 # if defined(_MSC_VER) || defined(__INTEL_COMPILER)
343 # define APIDECL __declspec(dllimport)
347 # if defined(EXPORTED_TO_SHARED_LIB)
348 # error INTENTIONAL COMPILATION ERROR, DLL IMPORT AND EXPORT ARE INCOMPATIBLE
352 #ifndef EXPORTED_TO_SHARED_LIB
353 # ifndef IMPORTED_FROM_SHARED_LIB