Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(868)

Side by Side Diff: base/numerics/safe_conversions_impl.h

Issue 2797793002: Remove base::underlying_type, replace uses with std::underlying_type (Closed)
Patch Set: underlyingtype: rm-tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/logging.h ('k') | base/template_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ 5 #ifndef BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_
6 #define BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ 6 #define BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 static_assert(IsIntegerArithmeticSafe<type, Lhs, Rhs>::value, ""); 510 static_assert(IsIntegerArithmeticSafe<type, Lhs, Rhs>::value, "");
511 static const bool is_contained = true; 511 static const bool is_contained = true;
512 }; 512 };
513 513
514 template <typename Lhs, typename Rhs> 514 template <typename Lhs, typename Rhs>
515 struct FastIntegerArithmeticPromotion<Lhs, Rhs, false> { 515 struct FastIntegerArithmeticPromotion<Lhs, Rhs, false> {
516 using type = typename BigEnoughPromotion<Lhs, Rhs>::type; 516 using type = typename BigEnoughPromotion<Lhs, Rhs>::type;
517 static const bool is_contained = false; 517 static const bool is_contained = false;
518 }; 518 };
519 519
520 // This hacks around libstdc++ 4.6 missing stuff in type_traits.
521 #if defined(__GLIBCXX__)
522 #define PRIV_GLIBCXX_4_7_0 20120322
523 #define PRIV_GLIBCXX_4_5_4 20120702
524 #define PRIV_GLIBCXX_4_6_4 20121127
525 #if (__GLIBCXX__ < PRIV_GLIBCXX_4_7_0 || __GLIBCXX__ == PRIV_GLIBCXX_4_5_4 || \
526 __GLIBCXX__ == PRIV_GLIBCXX_4_6_4)
527 #define PRIV_USE_FALLBACKS_FOR_OLD_GLIBCXX
528 #undef PRIV_GLIBCXX_4_7_0
529 #undef PRIV_GLIBCXX_4_5_4
530 #undef PRIV_GLIBCXX_4_6_4
531 #endif
532 #endif
533
534 // Extracts the underlying type from an enum. 520 // Extracts the underlying type from an enum.
535 template <typename T, bool is_enum = std::is_enum<T>::value> 521 template <typename T, bool is_enum = std::is_enum<T>::value>
536 struct ArithmeticOrUnderlyingEnum; 522 struct ArithmeticOrUnderlyingEnum;
537 523
538 template <typename T> 524 template <typename T>
539 struct ArithmeticOrUnderlyingEnum<T, true> { 525 struct ArithmeticOrUnderlyingEnum<T, true> {
540 #if defined(PRIV_USE_FALLBACKS_FOR_OLD_GLIBCXX)
541 using type = __underlying_type(T);
542 #else
543 using type = typename std::underlying_type<T>::type; 526 using type = typename std::underlying_type<T>::type;
544 #endif
545 static const bool value = std::is_arithmetic<type>::value; 527 static const bool value = std::is_arithmetic<type>::value;
546 }; 528 };
547 529
548 #if defined(PRIV_USE_FALLBACKS_FOR_OLD_GLIBCXX)
549 #undef PRIV_USE_FALLBACKS_FOR_OLD_GLIBCXX
550 #endif
551
552 template <typename T> 530 template <typename T>
553 struct ArithmeticOrUnderlyingEnum<T, false> { 531 struct ArithmeticOrUnderlyingEnum<T, false> {
554 using type = T; 532 using type = T;
555 static const bool value = std::is_arithmetic<type>::value; 533 static const bool value = std::is_arithmetic<type>::value;
556 }; 534 };
557 535
558 // The following are helper templates used in the CheckedNumeric class. 536 // The following are helper templates used in the CheckedNumeric class.
559 template <typename T> 537 template <typename T>
560 class CheckedNumeric; 538 class CheckedNumeric;
561 539
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 static_cast<BigType>(static_cast<L>(lhs)), 701 static_cast<BigType>(static_cast<L>(lhs)),
724 static_cast<BigType>(static_cast<R>(rhs))) 702 static_cast<BigType>(static_cast<R>(rhs)))
725 // Let the template functions figure it out for mixed types. 703 // Let the template functions figure it out for mixed types.
726 : C<L, R>::Test(lhs, rhs); 704 : C<L, R>::Test(lhs, rhs);
727 }; 705 };
728 706
729 } // namespace internal 707 } // namespace internal
730 } // namespace base 708 } // namespace base
731 709
732 #endif // BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_ 710 #endif // BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_
OLDNEW
« no previous file with comments | « base/logging.h ('k') | base/template_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698