brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 85b78c4 Raw
77 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <charconv>12 13// Bitmask type14// enum class chars_format {15//   scientific = unspecified,16//   fixed = unspecified,17//   hex = unspecified,18//   general = fixed | scientific19// };20 21#include <cassert>22#include <charconv>23#include <type_traits>24 25#include "test_macros.h"26 27constexpr bool test() {28  using cf = std::chars_format;29  using ut = std::underlying_type<cf>::type;30 31  {32    cf x = cf::scientific;33    x |= cf::fixed;34    assert(x == cf::general);35  }36  {37    cf x = cf::general;38    x &= cf::fixed;39    assert(x == cf::fixed);40  }41  {42    cf x = cf::general;43    x ^= cf::fixed;44    assert(x == cf::scientific);45  }46 47  assert(static_cast<ut>(cf::scientific & (cf::fixed | cf::hex)) == 0);48  assert(static_cast<ut>(cf::fixed & (cf::scientific | cf::hex)) == 0);49  assert(static_cast<ut>(cf::hex & (cf::scientific | cf::fixed)) == 0);50 51  assert((cf::scientific | cf::fixed) == cf::general);52 53  assert(static_cast<ut>(cf::scientific & cf::fixed) == 0);54 55  assert((cf::general ^ cf::fixed) == cf::scientific);56 57  assert((~cf::hex & cf::general) == cf::general);58 59  return true;60}61 62std::chars_format x;63static_assert(std::is_same<std::chars_format, decltype(~x)>::value, "");64static_assert(std::is_same<std::chars_format, decltype(x & x)>::value, "");65static_assert(std::is_same<std::chars_format, decltype(x | x)>::value, "");66static_assert(std::is_same<std::chars_format, decltype(x ^ x)>::value, "");67static_assert(std::is_same<std::chars_format&, decltype(x &= x)>::value, "");68static_assert(std::is_same<std::chars_format&, decltype(x |= x)>::value, "");69static_assert(std::is_same<std::chars_format&, decltype(x ^= x)>::value, "");70 71int main(int, char**) {72  assert(test());73  static_assert(test(), "");74 75  return 0;76}77