You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

bit.h 3.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_BIT_H_
  17. #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_BIT_H_
  18. namespace mindspore {
  19. namespace dataset {
  20. template <typename Enum>
  21. Enum operator|(Enum lhs, Enum rhs) {
  22. static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type");
  23. using underlying = typename std::underlying_type<Enum>::type;
  24. return static_cast<Enum>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
  25. }
  26. template <typename Enum>
  27. Enum operator&(Enum lhs, Enum rhs) {
  28. static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type");
  29. using underlying = typename std::underlying_type<Enum>::type;
  30. return static_cast<Enum>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
  31. }
  32. template <typename Enum>
  33. Enum operator^(Enum lhs, Enum rhs) {
  34. static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type");
  35. using underlying = typename std::underlying_type<Enum>::type;
  36. return static_cast<Enum>(static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
  37. }
  38. template <typename Enum>
  39. Enum &operator|=(Enum &lhs, Enum rhs) {
  40. static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type");
  41. using underlying = typename std::underlying_type<Enum>::type;
  42. lhs = static_cast<Enum>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
  43. return lhs;
  44. }
  45. template <typename Enum>
  46. Enum &operator&=(Enum &lhs, Enum rhs) {
  47. static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type");
  48. using underlying = typename std::underlying_type<Enum>::type;
  49. lhs = static_cast<Enum>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
  50. return lhs;
  51. }
  52. template <typename Enum>
  53. Enum &operator^=(Enum &lhs, Enum rhs) {
  54. static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type");
  55. using underlying = typename std::underlying_type<Enum>::type;
  56. lhs = static_cast<Enum>(static_cast<underlying>(lhs) ^ static_cast<underlying>(rhs));
  57. return lhs;
  58. }
  59. template <typename Enum>
  60. Enum operator~(Enum v) {
  61. static_assert(std::is_enum<Enum>::value, "template parameter is not an enum type");
  62. using underlying = typename std::underlying_type<Enum>::type;
  63. return static_cast<Enum>(~static_cast<underlying>(v));
  64. }
  65. } // namespace dataset
  66. } // namespace mindspore
  67. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_BIT_H_