40 #ifndef __USE_STD_IOSTREAM
41 # define __USE_STD_IOSTREAM
52 #if defined(_MSC_VER) && _MSC_VER >= 1400
53 # define GMM_SECURE_CRT
54 # define SECURE_NONCHAR_SSCANF sscanf_s
55 # define SECURE_NONCHAR_FSCANF fscanf_s
56 # define SECURE_STRNCPY(a, la, b, lb) strncpy_s(a, la, b, lb)
57 # define SECURE_FOPEN(F, filename, mode) (*(F) = 0, fopen_s(F, filename, mode))
58 # define SECURE_SPRINTF1(S, l, st, p1) sprintf_s(S, l, st, p1)
59 # define SECURE_SPRINTF2(S, l, st, p1, p2) sprintf_s(S, l, st, p1, p2)
60 # define SECURE_SPRINTF4(S, l, st, p1, p2, p3, p4) sprintf_s(S, l, st, p1, p2, p3, p4)
61 # define SECURE_STRDUP(s) _strdup(s)
62 # ifndef _CRT_SECURE_NO_DEPRECATE
63 # error Add _CRT_SECURE_NO_DEPRECATE to your compilation options, Microsoft is overstrict (e.g. bans fopen) without offering portable alternatives
66 # define SECURE_NONCHAR_SSCANF sscanf
67 # define SECURE_NONCHAR_FSCANF fscanf
68 # define SECURE_STRNCPY(a, la, b, lb) strncpy(a, b, lb)
69 # define SECURE_FOPEN(F, filename, mode) ((*(F)) = fopen(filename, mode))
70 # define SECURE_SPRINTF1(S, l, st, p1) snprintf(S, l, st, p1)
71 # define SECURE_SPRINTF2(S, l, st, p1, p2) snprintf(S, l, st, p1, p2)
72 # define SECURE_SPRINTF4(S, l, st, p1, p2, p3, p4) snprintf(S, l, st, p1, p2, p3, p4)
73 # define SECURE_STRDUP(s) strdup(s)
76 inline void GMM_NOPERATION_(
int) { }
77 #define GMM_NOPERATION(a) { GMM_NOPERATION_(abs(&(a) != &(a))); }
85 # error : PLEASE UPDATE g++ TO AT LEAST 4.8 VERSION
120 #include <gmm/gmm_arch_config.h>
123 #if defined(__GNUC__) && (__cplusplus <= 201103L)
124 template<
typename _Tp>
126 {
typedef unique_ptr<_Tp> __single_object; };
127 template<
typename _Tp>
128 struct _MakeUniq<_Tp[]>
129 {
typedef unique_ptr<_Tp[]> __array; };
130 template<
typename _Tp,
size_t _Bound>
131 struct _MakeUniq<_Tp[_Bound]>
132 {
struct __invalid_type { }; };
134 template<
typename _Tp,
typename... _Args>
135 inline typename _MakeUniq<_Tp>::__single_object
136 make_unique(_Args&&... __args)
137 {
return unique_ptr<_Tp>(
new _Tp(std::forward<_Args>(__args)...)); }
139 template<
typename _Tp>
140 inline typename _MakeUniq<_Tp>::__array
141 make_unique(
size_t __num)
142 {
return unique_ptr<_Tp>(
new typename remove_extent<_Tp>::type[__num]()); }
144 template<
typename _Tp,
typename... _Args>
145 inline typename _MakeUniq<_Tp>::__invalid_type
146 make_unique(_Args&&...) =
delete;
152 template <
typename T>
class shared_array_ptr : shared_ptr<T> {
154 shared_array_ptr() {}
155 shared_array_ptr(T *q) : std::shared_ptr<T>(q, default_delete<T[]>()) {}
156 template <
typename Y> shared_array_ptr(
const std::shared_ptr<Y> &p, T *q)
157 : std::shared_ptr<T>(p, q) {}
158 T *get()
const {
return shared_ptr<T>::get(); }
159 T& operator*()
const {
return shared_ptr<T>::operator*(); }
160 T* operator->()
const {
return shared_ptr<T>::operator->(); }
163 template <
typename T> shared_array_ptr<T> make_shared_array(
size_t num)
164 {
return shared_array_ptr<T>(
new T[num]); }
169 using std::endl;
using std::cout;
using std::cerr;
170 using std::ends;
using std::cin;
using std::isnan;
172 class standard_locale {
177 inline standard_locale(
void)
178 : cloc(setlocale(LC_NUMERIC, 0)), cinloc(cin.getloc())
179 { setlocale(LC_NUMERIC,
"C"); cin.imbue(std::locale(
"C")); }
180 inline ~standard_locale()
181 { setlocale(LC_NUMERIC, cloc.c_str()); cin.imbue(cinloc); }
184 class stream_standard_locale {
189 inline stream_standard_locale(std::ios &i)
190 : cloc(i.getloc()), io(i) { io.imbue(std::locale(
"C")); }
191 inline ~stream_standard_locale() { io.imbue(cloc); }
198 # if defined(HAVE_SYS_TIMES)
199 inline double uclock_sec(
void) {
200 static double ttclk = 0.;
201 if (ttclk == 0.) ttclk = sysconf(_SC_CLK_TCK);
202 tms t; times(&t);
return double(t.tms_utime) / ttclk;
205 inline double uclock_sec(
void)
206 {
return double(clock())/double(CLOCKS_PER_SEC); }
215 template <
size_t s>
struct fixed_size_integer_generator {
216 typedef void int_base_type;
217 typedef void uint_base_type;
220 template <>
struct fixed_size_integer_generator<sizeof(char)> {
221 typedef signed char int_base_type;
222 typedef unsigned char uint_base_type;
225 template <>
struct fixed_size_integer_generator<sizeof(short int)
226 - ((sizeof(short int) ==
sizeof(char)) ? 78 : 0)> {
227 typedef signed short int int_base_type;
228 typedef unsigned short int uint_base_type;
231 template <>
struct fixed_size_integer_generator<sizeof(int)
232 - ((sizeof(int) ==
sizeof(
short int)) ? 59 : 0)> {
233 typedef signed int int_base_type;
234 typedef unsigned int uint_base_type;
237 template <>
struct fixed_size_integer_generator<sizeof(long)
238 - ((sizeof(int) ==
sizeof(long)) ? 93 : 0)> {
239 typedef signed long int_base_type;
240 typedef unsigned long uint_base_type;
243 template <>
struct fixed_size_integer_generator<sizeof(long long)
244 - ((sizeof(long long) ==
sizeof(long)) ? 99 : 0)> {
245 typedef signed long long int_base_type;
246 typedef unsigned long long uint_base_type;
249 typedef fixed_size_integer_generator<1>::int_base_type int8_type;
250 typedef fixed_size_integer_generator<1>::uint_base_type uint8_type;
251 typedef fixed_size_integer_generator<2>::int_base_type int16_type;
252 typedef fixed_size_integer_generator<2>::uint_base_type uint16_type;
253 typedef fixed_size_integer_generator<4>::int_base_type int32_type;
254 typedef fixed_size_integer_generator<4>::uint_base_type uint32_type;
255 typedef fixed_size_integer_generator<8>::int_base_type int64_type;
256 typedef fixed_size_integer_generator<8>::uint_base_type uint64_type;
294 #if defined(__GNUC__) && !defined(__ICC)
299 # define IS_DEPRECATED __attribute__ ((__deprecated__))
303 # define ALWAYS_INLINE __attribute__((always_inline))
305 # define IS_DEPRECATED
306 # define ALWAYS_INLINE
309 #if defined(_MSC_VER) || defined(__INTEL_COMPILER)
310 # define NOINLINE __declspec(noinline)
311 #elif defined(__GNUC__) && !defined(__ICC)
312 # define NOINLINE __attribute__((noinline))
321 #if defined(EXPORTED_TO_SHARED_LIB)
322 # if defined(_MSC_VER) || defined(__INTEL_COMPILER)
323 # define APIDECL __declspec(dllexport)
324 # elif defined(__GNUC__)
325 # define __attribute__((visibility("default")))
329 # if defined(IMPORTED_FROM_SHARED_LIB)
330 # error INTENTIONAL COMPILATION ERROR, DLL IMPORT AND EXPORT ARE INCOMPATIBLE
334 #if defined(IMPORTED_FROM_SHARED_LIB)
335 # if defined(_MSC_VER) || defined(__INTEL_COMPILER)
336 # define APIDECL __declspec(dllimport)
340 # if defined(EXPORTED_TO_SHARED_LIB)
341 # error INTENTIONAL COMPILATION ERROR, DLL IMPORT AND EXPORT ARE INCOMPATIBLE
345 #ifndef EXPORTED_TO_SHARED_LIB
346 # ifndef IMPORTED_FROM_SHARED_LIB