Repository: fmtlib/fmt
File: test/std-test.cc (C++)

Code before:
    EXPECT_EQ("My Exception", fmt::format("{:}", ex));
  }

  try {
    throw std::system_error(std::error_code(), "message");
  } catch (const std::system_error& ex) {
    EXPECT_THAT(fmt::format("{:t}", ex), StartsWith("std::system_error: "));
  }

#ifdef __cpp_lib_filesystem
  // Tests that the inline namespace is stripped out, e.g.
  // std::filesystem::__cxx11::* -> std::filesystem::*.
  try {
    throw std::filesystem::filesystem_error("message", std::error_code());
  } catch (const std::filesystem::filesystem_error& ex) {
    EXPECT_THAT(fmt::format("{:t}", ex),
                StartsWith("std::filesystem::filesystem_error: "));
  }
#endif
}

TEST(std_test, format_bit_reference) {
  std::bitset<2> bs(1);
  EXPECT_EQ(fmt::format("{} {}", bs[0], bs[1]), "true false");
  std::vector<bool> v = {true, false};
  EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false");
}


Review comment (bug):
try this

```
  const std::vector<bool> cv = {true, false};
  EXPECT_EQ(fmt::format("{} {}", cv[0], cv[1]), "true false");
```

```
[ 90%] Building CXX object test/CMakeFiles/std-test.dir/std-test.cc.o
In file included from /Users/wangzw/workspace/fmt/test/std-test.cc:8:
In file included from /Users/wangzw/workspace/fmt/include/fmt/std.h:21:
In file included from /Users/wangzw/workspace/fmt/include/fmt/format.h:49:
/Users/wangzw/workspace/fmt/include/fmt/core.h:1621:63: error: implicit instantiation of undefined template 'fmt::detail::type_is_unformattable_for<std::__bit_const_reference<std::vector<bool>>, char>'
    type_is_unformattable_for<T, typename Context::char_type> _;
                                                              ^
/Users/wangzw/workspace/fmt/include/fmt/core.h:1853:23: note: in instantiation of function template specialization 'fmt::detail::make_arg<true, fmt::basic_format_context<fmt::appender, char>, std::__bit_const_reference<std::vector<bool>>, 0>' requested here
        data_{detail::make_arg<is_packed, Context>(args)...} {
                      ^
/Users/wangzw/workspace/fmt/include/fmt/core.h:1871:10: note: in instantiation of function template specialization 'fmt::format_arg_store<fmt::basic_format_context<fmt::appender, char>, std::__bit_const_reference<std::vector<bool>>, std::__bit_const_reference<std::vector<bool>>>::format_arg_store<std::__bit_const_reference<std::vector<bool>>, std::__bit_const_reference<std::vector<bool>>>' requested here
  return {args...};
         ^
/Users/wangzw/workspace/fmt/include/fmt/core.h:2833:28: note: in instantiation of function template specialization 'fmt::make_format_args<fmt::basic_format_context<fmt::appender, char>, std::__bit_const_reference<std::vector<bool>>, std::__bit_const_reference<std::vector<bool>>>' requested here
  return vformat(fmt, fmt::make_format_args(args...));
                           ^
/Users/wangzw/workspace/fmt/test/std-test.cc:231:18: note: in instantiation of function template specialization 'fmt::format<std::__bit_const_reference<std::vector<bool>>, std::__bit_const_reference<std::vector<bool>>>' requested here
  EXPECT_EQ(fmt::format("{} {}", cv[0], cv[1]), "true false");
                 ^
/Users/wangzw/workspace/fmt/include/fmt/core.h:1599:45: note: template is declared here
template <typename T, typename Char> struct type_is_unformattable_for;
                                            ^
/Users/wangzw/workspace/fmt/include/fmt/core.h:1624:3: error: static assertion failed due to requirement 'formattable': Cannot format an argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#udt
  static_assert(
  ^
```

Code after:
    EXPECT_EQ("My Exception", fmt::format("{:}", ex));
  }

  try {
    throw std::system_error(std::error_code(), "message");
  } catch (const std::system_error& ex) {
    EXPECT_THAT(fmt::format("{:t}", ex), StartsWith("std::system_error: "));
  }

#ifdef __cpp_lib_filesystem
  // Tests that the inline namespace is stripped out, e.g.
  // std::filesystem::__cxx11::* -> std::filesystem::*.
  try {
    throw std::filesystem::filesystem_error("message", std::error_code());
  } catch (const std::filesystem::filesystem_error& ex) {
    EXPECT_THAT(fmt::format("{:t}", ex),
                StartsWith("std::filesystem::filesystem_error: "));
  }
#endif
}

TEST(std_test, format_bit_reference) {
  std::bitset<2> bs(1);
  EXPECT_EQ(fmt::format("{} {}", bs[0], bs[1]), "true false");
  std::vector<bool> v = {true, false};
  EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false");
}

TEST(std_test, format_const_bit_reference) {
  const std::bitset<2> bs(1);
  EXPECT_EQ(fmt::format("{} {}", bs[0], bs[1]), "true false");
  const std::vector<bool> v = {true, false};
  EXPECT_EQ(fmt::format("{} {}", v[0], v[1]), "true false");
}