@@ -99,38 +99,26 @@ _LIBCPP_BEGIN_NAMESPACE_STD
99
99
// __static_gcd
100
100
101
101
template <intmax_t _Xp, intmax_t _Yp>
102
- struct __static_gcd {
103
- static const intmax_t value = __static_gcd<_Yp, _Xp % _Yp>::value;
104
- };
102
+ inline const intmax_t __static_gcd = __static_gcd<_Yp, _Xp % _Yp>;
105
103
106
104
template <intmax_t _Xp>
107
- struct __static_gcd <_Xp, 0 > {
108
- static const intmax_t value = _Xp;
109
- };
105
+ inline const intmax_t __static_gcd<_Xp, 0 > = _Xp;
110
106
111
107
template <>
112
- struct __static_gcd <0 , 0 > {
113
- static const intmax_t value = 1 ;
114
- };
108
+ inline const intmax_t __static_gcd<0 , 0 > = 1 ;
115
109
116
110
// __static_lcm
117
111
118
112
template <intmax_t _Xp, intmax_t _Yp>
119
- struct __static_lcm {
120
- static const intmax_t value = _Xp / __static_gcd<_Xp, _Yp>::value * _Yp;
121
- };
113
+ inline const intmax_t __static_lcm = _Xp / __static_gcd<_Xp, _Yp> * _Yp;
122
114
123
115
template <intmax_t _Xp>
124
- struct __static_abs {
125
- static const intmax_t value = _Xp < 0 ? -_Xp : _Xp;
126
- };
116
+ inline const intmax_t __static_abs = _Xp < 0 ? -_Xp : _Xp;
127
117
128
118
template <intmax_t _Xp>
129
- struct __static_sign {
130
- static const intmax_t value = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1 );
131
- };
119
+ inline const intmax_t __static_sign = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1 );
132
120
133
- template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value >
121
+ template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp> >
134
122
class __ll_add ;
135
123
136
124
template <intmax_t _Xp, intmax_t _Yp>
@@ -161,7 +149,7 @@ public:
161
149
static const intmax_t value = _Xp + _Yp;
162
150
};
163
151
164
- template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value >
152
+ template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp> >
165
153
class __ll_sub ;
166
154
167
155
template <intmax_t _Xp, intmax_t _Yp>
@@ -197,8 +185,8 @@ class __ll_mul {
197
185
static const intmax_t nan = (1LL << (sizeof (intmax_t ) * CHAR_BIT - 1 ));
198
186
static const intmax_t min = nan + 1 ;
199
187
static const intmax_t max = -min;
200
- static const intmax_t __a_x = __static_abs<_Xp>::value ;
201
- static const intmax_t __a_y = __static_abs<_Yp>::value ;
188
+ static const intmax_t __a_x = __static_abs<_Xp>;
189
+ static const intmax_t __a_y = __static_abs<_Yp>;
202
190
203
191
static_assert (_Xp != nan && _Yp != nan && __a_x <= max / __a_y, " overflow in __ll_mul" );
204
192
@@ -239,13 +227,13 @@ public:
239
227
240
228
template <intmax_t _Num, intmax_t _Den = 1 >
241
229
class _LIBCPP_TEMPLATE_VIS ratio {
242
- static_assert (__static_abs<_Num>::value >= 0 , " ratio numerator is out of range" );
230
+ static_assert (__static_abs<_Num> >= 0 , " ratio numerator is out of range" );
243
231
static_assert (_Den != 0 , " ratio divide by 0" );
244
- static_assert (__static_abs<_Den>::value > 0 , " ratio denominator is out of range" );
245
- static _LIBCPP_CONSTEXPR const intmax_t __na = __static_abs<_Num>::value ;
246
- static _LIBCPP_CONSTEXPR const intmax_t __da = __static_abs<_Den>::value ;
247
- static _LIBCPP_CONSTEXPR const intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value ;
248
- static _LIBCPP_CONSTEXPR const intmax_t __gcd = __static_gcd<__na, __da>::value ;
232
+ static_assert (__static_abs<_Den> > 0 , " ratio denominator is out of range" );
233
+ static _LIBCPP_CONSTEXPR const intmax_t __na = __static_abs<_Num>;
234
+ static _LIBCPP_CONSTEXPR const intmax_t __da = __static_abs<_Den>;
235
+ static _LIBCPP_CONSTEXPR const intmax_t __s = __static_sign<_Num> * __static_sign<_Den>;
236
+ static _LIBCPP_CONSTEXPR const intmax_t __gcd = __static_gcd<__na, __da>;
249
237
250
238
public:
251
239
static _LIBCPP_CONSTEXPR const intmax_t num = __s * __na / __gcd;
@@ -261,9 +249,10 @@ template <intmax_t _Num, intmax_t _Den>
261
249
_LIBCPP_CONSTEXPR const intmax_t ratio<_Num, _Den>::den;
262
250
263
251
template <class _Tp >
264
- struct __is_ratio : false_type {};
252
+ inline const bool __is_ratio_v = false ;
253
+
265
254
template <intmax_t _Num, intmax_t _Den>
266
- struct __is_ratio <ratio<_Num, _Den> > : true_type {} ;
255
+ inline const bool __is_ratio_v <ratio<_Num, _Den> > = true ;
267
256
268
257
typedef ratio<1LL , 1000000000000000000LL > atto;
269
258
typedef ratio<1LL , 1000000000000000LL > femto;
@@ -285,11 +274,11 @@ typedef ratio<1000000000000000000LL, 1LL> exa;
285
274
template <class _R1 , class _R2 >
286
275
struct __ratio_multiply {
287
276
private:
288
- static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>::value ;
289
- static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>::value ;
277
+ static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>;
278
+ static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>;
290
279
291
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
292
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
280
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
281
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
293
282
294
283
public:
295
284
typedef typename ratio< __ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value,
@@ -311,11 +300,11 @@ struct _LIBCPP_TEMPLATE_VIS ratio_multiply : public __ratio_multiply<_R1, _R2>::
311
300
template <class _R1 , class _R2 >
312
301
struct __ratio_divide {
313
302
private:
314
- static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value ;
315
- static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value ;
303
+ static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>;
304
+ static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>;
316
305
317
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
318
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
306
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
307
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
319
308
320
309
public:
321
310
typedef typename ratio< __ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
@@ -337,11 +326,11 @@ struct _LIBCPP_TEMPLATE_VIS ratio_divide : public __ratio_divide<_R1, _R2>::type
337
326
template <class _R1 , class _R2 >
338
327
struct __ratio_add {
339
328
private:
340
- static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value ;
341
- static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value ;
329
+ static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>;
330
+ static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>;
342
331
343
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
344
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
332
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
333
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
345
334
346
335
public:
347
336
typedef typename ratio_multiply<
@@ -366,11 +355,11 @@ struct _LIBCPP_TEMPLATE_VIS ratio_add : public __ratio_add<_R1, _R2>::type {};
366
355
template <class _R1 , class _R2 >
367
356
struct __ratio_subtract {
368
357
private:
369
- static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value ;
370
- static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value ;
358
+ static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>;
359
+ static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>;
371
360
372
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
373
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
361
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
362
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
374
363
375
364
public:
376
365
typedef typename ratio_multiply<
@@ -396,14 +385,14 @@ struct _LIBCPP_TEMPLATE_VIS ratio_subtract : public __ratio_subtract<_R1, _R2>::
396
385
397
386
template <class _R1 , class _R2 >
398
387
struct _LIBCPP_TEMPLATE_VIS ratio_equal : _BoolConstant<(_R1::num == _R2::num && _R1::den == _R2::den)> {
399
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
400
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
388
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
389
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
401
390
};
402
391
403
392
template <class _R1 , class _R2 >
404
393
struct _LIBCPP_TEMPLATE_VIS ratio_not_equal : _BoolConstant<!ratio_equal<_R1, _R2>::value> {
405
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
406
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
394
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
395
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
407
396
};
408
397
409
398
// ratio_less
@@ -439,10 +428,7 @@ struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, _M2> {
439
428
static const bool value = __ratio_less1<ratio<_R1::den, _M1>, ratio<_R2::den, _M2>, !_Odd>::value;
440
429
};
441
430
442
- template <class _R1 ,
443
- class _R2 ,
444
- intmax_t _S1 = __static_sign<_R1::num>::value,
445
- intmax_t _S2 = __static_sign<_R2::num>::value>
431
+ template <class _R1 , class _R2 , intmax_t _S1 = __static_sign<_R1::num>, intmax_t _S2 = __static_sign<_R2::num> >
446
432
struct __ratio_less {
447
433
static const bool value = _S1 < _S2;
448
434
};
@@ -459,31 +445,31 @@ struct __ratio_less<_R1, _R2, -1LL, -1LL> {
459
445
460
446
template <class _R1 , class _R2 >
461
447
struct _LIBCPP_TEMPLATE_VIS ratio_less : _BoolConstant<__ratio_less<_R1, _R2>::value> {
462
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
463
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
448
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
449
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
464
450
};
465
451
466
452
template <class _R1 , class _R2 >
467
453
struct _LIBCPP_TEMPLATE_VIS ratio_less_equal : _BoolConstant<!ratio_less<_R2, _R1>::value> {
468
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
469
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
454
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
455
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
470
456
};
471
457
472
458
template <class _R1 , class _R2 >
473
459
struct _LIBCPP_TEMPLATE_VIS ratio_greater : _BoolConstant<ratio_less<_R2, _R1>::value> {
474
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
475
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
460
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
461
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
476
462
};
477
463
478
464
template <class _R1 , class _R2 >
479
465
struct _LIBCPP_TEMPLATE_VIS ratio_greater_equal : _BoolConstant<!ratio_less<_R1, _R2>::value> {
480
- static_assert (__is_ratio <_R1>::value , " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
481
- static_assert (__is_ratio <_R2>::value , " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
466
+ static_assert (__is_ratio_v <_R1>, " [ratio.general]/2 requires R1 to be a specialisation of the ratio template" );
467
+ static_assert (__is_ratio_v <_R2>, " [ratio.general]/2 requires R2 to be a specialisation of the ratio template" );
482
468
};
483
469
484
470
template <class _R1 , class _R2 >
485
471
struct __ratio_gcd {
486
- typedef ratio<__static_gcd<_R1::num, _R2::num>::value , __static_lcm<_R1::den, _R2::den>::value > type;
472
+ typedef ratio<__static_gcd<_R1::num, _R2::num>, __static_lcm<_R1::den, _R2::den> > type;
487
473
};
488
474
489
475
#if _LIBCPP_STD_VER >= 17
0 commit comments