Skip to content

Commit

Permalink
Mark more formatters nonlocking
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 21, 2024
1 parent 0c9fce2 commit 3cc32fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
29 changes: 15 additions & 14 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,20 +1185,6 @@ namespace detail {
template <typename T>
struct is_back_insert_iterator<basic_appender<T>> : std::true_type {};

template <typename T, typename Enable = void>
struct locking : std::true_type {};
template <typename T>
struct locking<T, void_t<typename formatter<remove_cvref_t<T>>::nonlocking>>
: std::false_type {};

template <typename T = int> FMT_CONSTEXPR inline auto is_locking() -> bool {
return locking<T>::value;
}
template <typename T1, typename T2, typename... Tail>
FMT_CONSTEXPR inline auto is_locking() -> bool {
return locking<T1>::value || is_locking<T2, Tail...>();
}

// An optimized version of std::copy with the output value type (T).
template <typename T, typename InputIt, typename OutputIt,
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value)>
Expand Down Expand Up @@ -2074,6 +2060,21 @@ using sign_t = sign::type;

namespace detail {

template <typename T, typename Enable = void>
struct locking : bool_constant<mapped_type_constant<T, format_context>::value ==
type::custom_type> {};
template <typename T>
struct locking<T, void_t<typename formatter<remove_cvref_t<T>>::nonlocking>>
: std::false_type {};

template <typename T = int> FMT_CONSTEXPR inline auto is_locking() -> bool {
return locking<T>::value;
}
template <typename T1, typename T2, typename... Tail>
FMT_CONSTEXPR inline auto is_locking() -> bool {
return locking<T1>::value || is_locking<T2, Tail...>();
}

template <typename Char>
using unsigned_char = typename conditional_t<std::is_integral<Char>::value,
std::make_unsigned<Char>,
Expand Down
4 changes: 4 additions & 0 deletions test/base-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ TEST(string_view_test, compare) {
check_op<std::greater_equal>();
}

TEST(base_test, is_locking) {
EXPECT_FALSE(fmt::detail::is_locking<const char (&)[3]>());
}

TEST(base_test, is_output_iterator) {
EXPECT_TRUE((fmt::detail::is_output_iterator<char*, char>::value));
EXPECT_FALSE((fmt::detail::is_output_iterator<const char*, char>::value));
Expand Down

0 comments on commit 3cc32fd

Please sign in to comment.