15
15
#include < utility>
16
16
#include < random>
17
17
18
- #include " narrowing.h"
19
18
#include " traits.h"
20
19
21
20
@@ -59,7 +58,7 @@ template<class T = real_t>
59
58
struct radians_turn
60
59
{
61
60
using type = T;
62
- static constexpr type value = static_cast <type>(2 * pi );
61
+ static constexpr type value = static_cast <type>(2 * pi <type> );
63
62
};
64
63
65
64
@@ -145,57 +144,38 @@ class angle
145
144
template <class T > friend class angle ;
146
145
147
146
public:
148
- // ---------------------------------------------------------------
149
- // TYPES
150
147
// ---------------------------------------------------------------
151
148
using turn_type = Turn;
152
149
using numeric_type = typename Turn::type;
150
+ using value_type = numeric_type;
153
151
154
152
155
- // ---------------------------------------------------------------
156
- // CONSTANTS
157
153
// ---------------------------------------------------------------
158
154
static constexpr numeric_type
159
155
turn () noexcept {
160
156
return (turn_type::value);
161
157
}
162
158
163
159
164
- // ---------------------------------------------------------------
165
- // CONSTRUCTION / DESTRUCTION
166
160
// ---------------------------------------------------------------
167
161
// /@brief no default contructor, angle has to be initialized with a value
168
162
angle () = delete ;
169
163
170
164
// -----------------------------------------------------
171
165
// / @brief implicit conversion from simple values is not allowed
172
166
explicit constexpr
173
- angle (numeric_type a):
174
- // TODO doesn't compile with gcc 5.1
175
- // but desirable for move-enabled 'heavy' number types
176
- // v_{std::move(a)}
167
+ angle (const numeric_type& a):
177
168
v_{a}
178
169
{}
179
- // -----------------------------------------------------
180
- // / @brief implicit conversion from simple values is not allowed
181
- template <class T , class = typename std::enable_if<
182
- is_number<T>::value && !is_angle<T>::value>::type>
183
- explicit constexpr
184
- angle (T a):
185
- v_ (static_cast <numeric_type>(a))
186
- {
187
- AM_CHECK_NARROWING (numeric_type, T)
188
- }
170
+
189
171
// -----------------------------------------------------
190
172
// / @brief implicit conversion of angles is allowed
191
173
// / @details may cause numerical drift when performed repeatedly
192
174
template <class T >
193
175
constexpr
194
176
angle (const angle<T>& a):
195
177
v_{a.template as <turn_type>()}
196
- {
197
- AM_CHECK_NARROWING (numeric_type, typename T::type)
198
- }
178
+ {}
199
179
200
180
// -----------------------------------------------------
201
181
angle (const angle&) = default ;
@@ -205,8 +185,6 @@ class angle
205
185
angle&
206
186
operator = (const angle<T>& a)
207
187
{
208
- AM_CHECK_NARROWING (numeric_type, typename T::type)
209
-
210
188
v_ = a.template as <turn_type>();
211
189
return *this ;
212
190
}
@@ -230,44 +208,30 @@ class angle
230
208
// ---------------------------------------------------------------
231
209
// ASSIGNING ARITHMETIC OPERATIONS
232
210
// ---------------------------------------------------------------
233
- template <class T >
234
211
angle&
235
- operator += (const angle<T> & a)
212
+ operator += (const angle& a)
236
213
{
237
- AM_CHECK_NARROWING (numeric_type, typename T::type)
238
-
239
- v_ += a.template as <turn_type>();
214
+ v_ += a.v_ ;
240
215
return *this ;
241
216
}
242
217
// -----------------------------------------------------
243
- template <class T >
244
218
angle&
245
- operator -= (const angle<T> & a)
219
+ operator -= (const angle& a)
246
220
{
247
- AM_CHECK_NARROWING (numeric_type, typename T::type)
248
-
249
- v_ -= a.template as <turn_type>();
221
+ v_ -= a.v_ ;
250
222
return *this ;
251
223
}
252
224
// -----------------------------------------------------
253
- template <class T , class = typename std::enable_if<
254
- is_number<T>::value && !is_angle<T>::value>::type>
255
225
angle&
256
- operator *= (const T & factor)
226
+ operator *= (const numeric_type & factor)
257
227
{
258
- AM_CHECK_NARROWING (numeric_type, T)
259
-
260
228
v_ *= factor;
261
229
return *this ;
262
230
}
263
231
// -----------------------------------------------------
264
- template <class T , class = typename std::enable_if<
265
- is_number<T>::value && !is_angle<T>::value>::type>
266
232
angle&
267
- operator /= (const T & factor)
233
+ operator /= (const numeric_type & factor)
268
234
{
269
- AM_CHECK_NARROWING (numeric_type, T)
270
-
271
235
v_ /= factor;
272
236
return *this ;
273
237
}
@@ -276,42 +240,34 @@ class angle
276
240
// ---------------------------------------------------------------
277
241
// ARITHMETIC OPERATIONS
278
242
// ---------------------------------------------------------------
279
- template <class T >
280
243
constexpr angle
281
- operator + (const angle<T> & a) const
244
+ operator + (const angle& a) const
282
245
{
283
- return angle{v_ + a.template as <turn_type>() };
246
+ return angle{v_ + a.v_ };
284
247
}
285
248
// -----------------------------------------------------
286
- template <class T >
287
249
constexpr angle
288
- operator - (const angle<T> & a) const
250
+ operator - (const angle& a) const
289
251
{
290
- return angle{v_ - a.template as <turn_type>() };
252
+ return angle{v_ - a.v_ };
291
253
}
292
254
// -----------------------------------------------------
293
- template <class T , class = typename std::enable_if<
294
- is_number<decay_t <T>>::value && !is_angle<decay_t <T>>::value>::type>
295
255
constexpr angle
296
- operator * (const T & factor) const
256
+ operator * (const numeric_type & factor) const
297
257
{
298
258
return angle{v_ * factor};
299
259
}
300
260
// -----------------------------------------------------
301
- template <class T , class = typename std::enable_if<
302
- is_number<decay_t <T>>::value && !is_angle<decay_t <T>>::value>::type>
303
261
constexpr angle
304
- operator / (const T & factor) const
262
+ operator / (const numeric_type & factor) const
305
263
{
306
264
return angle{v_ / factor};
307
265
}
308
266
309
267
// -----------------------------------------------------
310
268
// / @brief pre-multiplication
311
- template <class T , class = typename std::enable_if<
312
- is_number<decay_t <T>>::value && !is_angle<decay_t <T>>::value>::type>
313
269
inline friend constexpr angle
314
- operator * (const T & factor, const angle& a)
270
+ operator * (const numeric_type & factor, const angle& a)
315
271
{
316
272
return angle{factor * a.v_ };
317
273
}
@@ -321,7 +277,7 @@ class angle
321
277
// inversion (works only on signed domains)
322
278
// ---------------------------------------------------------------
323
279
template <class T = numeric_type, class = typename std::enable_if<
324
- !std::is_unsigned<T>::value && !is_angle<decay_t <T>>::value>::type>
280
+ !std::is_unsigned<T>::value && !is_angle<std:: decay_t <T>>::value>::type>
325
281
constexpr angle
326
282
operator - () const {
327
283
return angle{-v_};
@@ -363,37 +319,37 @@ class angle
363
319
// ---------------------------------------------------------------
364
320
template <class T >
365
321
constexpr bool
366
- operator == (const angle<T>& other) const {
322
+ operator == (const angle<T>& other) const noexcept {
367
323
return (v_ == other.template as <turn_type>());
368
324
}
369
325
// -----------------------------------------------------
370
326
template <class T >
371
327
constexpr bool
372
- operator != (const angle<T>& other) const {
328
+ operator != (const angle<T>& other) const noexcept {
373
329
return (v_ != other.template as <turn_type>());
374
330
}
375
331
// -----------------------------------------------------
376
332
template <class T >
377
333
constexpr bool
378
- operator < (const angle<T>& other) const {
334
+ operator < (const angle<T>& other) const noexcept {
379
335
return (v_ < other.template as <turn_type>());
380
336
}
381
337
// -----------------------------------------------------
382
338
template <class T >
383
339
constexpr bool
384
- operator > (const angle<T>& other) const {
340
+ operator > (const angle<T>& other) const noexcept {
385
341
return (v_ > other.template as <turn_type>());
386
342
}
387
343
// -----------------------------------------------------
388
344
template <class T >
389
345
constexpr bool
390
- operator <= (const angle<T>& other) const {
346
+ operator <= (const angle<T>& other) const noexcept {
391
347
return (v_ <= other.template as <turn_type>());
392
348
}
393
349
// -----------------------------------------------------
394
350
template <class T >
395
351
constexpr bool
396
- operator >= (const angle<T>& other) const {
352
+ operator >= (const angle<T>& other) const noexcept {
397
353
return (v_ >= other.template as <turn_type>());
398
354
}
399
355
@@ -492,8 +448,8 @@ class angle
492
448
std::enable_if<!std::is_same<turn_type,OutTurn>::value>::type>
493
449
constexpr conversion_t <OutTurn>
494
450
as () const noexcept {
495
- using res_t = conversion_t <OutTurn>;
496
- return ( (res_t (OutTurn::value) / res_t (turn ())) * res_t (v_));
451
+ using T = conversion_t <OutTurn>;
452
+ return ( (T (OutTurn::value) / T (turn ())) * T (v_));
497
453
}
498
454
499
455
@@ -661,11 +617,11 @@ constexpr radians<real_t> operator"" _rad (unsigned long long int x) {
661
617
}
662
618
// ---------------------------------------------------------
663
619
constexpr radians<real_t > operator " " _pi_rad(long double x) {
664
- return radians<real_t >{real_t (x * pi ) };
620
+ return radians<real_t >{real_t (x) * pi < real_t > };
665
621
}
666
622
// ---------------------------------------------------------
667
623
constexpr radians<real_t > operator " " _pi_rad(unsigned long long int x) {
668
- return radians<real_t >{real_t (x * pi ) };
624
+ return radians<real_t >{real_t (x) * pi < real_t > };
669
625
}
670
626
671
627
@@ -713,18 +669,18 @@ template<class U1, class U2>
713
669
inline common_numeric_t <typename U1::type, typename U2::type>
714
670
operator / (const angle<U1>& a, const angle<U2>& b)
715
671
{
716
- using res_t = common_numeric_t <typename U1::type, typename U2::type>;
672
+ using T = common_numeric_t <typename U1::type, typename U2::type>;
717
673
718
- return radians_cast<res_t >(a) / radians_cast<res_t >(b);
674
+ return radians_cast<T >(a) / radians_cast<T >(b);
719
675
}
720
676
// ---------------------------------------------------------
721
677
template <class U >
722
678
inline typename U::type
723
679
operator / (const angle<U>& a, const angle<U>& b)
724
680
{
725
- using res_t = typename U::type;
681
+ using T = typename U::type;
726
682
727
- return radians_cast<res_t >(a) / radians_cast<res_t >(b);
683
+ return radians_cast<T >(a) / radians_cast<T >(b);
728
684
}
729
685
730
686
@@ -841,32 +797,6 @@ struct common_numeric_type<angle<T>,angle<T>>
841
797
842
798
843
799
844
- namespace detail {
845
-
846
- // -------------------------------------------------------------------
847
- template <class To , class From >
848
- struct is_non_narrowing_helper <true , angle<To>, From> :
849
- public is_non_narrowing_helper<true ,typename angle<To>::numeric_type,From>
850
- {};
851
-
852
- // ---------------------------------------------------------
853
- template <class To , class From >
854
- struct is_non_narrowing_helper <true , angle<To>, angle<From> > :
855
- public is_non_narrowing_helper<true ,
856
- typename angle<To>::numeric_type,
857
- typename angle<From>::numeric_type>
858
- {};
859
-
860
- // ---------------------------------------------------------
861
- template <class To , class From >
862
- struct is_non_narrowing_helper <true , To, angle<From> > :
863
- public is_non_narrowing_helper<true ,To,typename angle<From>::numeric_type>
864
- {};
865
-
866
-
867
- } // namespace detail
868
-
869
-
870
800
871
801
/* ****************************************************************************
872
802
*
@@ -1115,8 +1045,6 @@ rad_atanh(T a)
1115
1045
template <class Turn , class ValueDistr >
1116
1046
class angle_distribution
1117
1047
{
1118
- AM_CHECK_NARROWING (typename Turn::type,typename ValueDistr::result_type)
1119
-
1120
1048
public:
1121
1049
using param_type = typename ValueDistr::param_type;
1122
1050
using numeric_type = typename ValueDistr::result_type;
0 commit comments