Skip to content

Commit

Permalink
Workaround C complex.h idiocy
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Sep 3, 2022
1 parent 29c6000 commit aec3bb5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
14 changes: 7 additions & 7 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ class is_tuple_formattable_ {
static constexpr const bool value = false;
};
template <typename T, typename C> class is_tuple_formattable_<T, C, true> {
template <std::size_t... I>
static std::true_type check2(index_sequence<I...>,
integer_sequence<bool, (I == I)...>);
template <std::size_t... Is>
static std::true_type check2(index_sequence<Is...>,
integer_sequence<bool, (Is == Is)...>);
static std::false_type check2(...);
template <std::size_t... I>
template <std::size_t... Is>
static decltype(check2(
index_sequence<I...>{},
index_sequence<Is...>{},
integer_sequence<
bool, (is_formattable<typename std::tuple_element<I, T>::type,
C>::value)...>{})) check(index_sequence<I...>);
bool, (is_formattable<typename std::tuple_element<Is, T>::type,
C>::value)...>{})) check(index_sequence<Is...>);

public:
static constexpr const bool value =
Expand Down
9 changes: 4 additions & 5 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,16 @@ template <typename T>
using variant_index_sequence =
std::make_index_sequence<std::variant_size<T>::value>;

template <typename>
struct is_variant_like_ : std::false_type {};
template <typename> struct is_variant_like_ : std::false_type {};
template <typename... Types>
struct is_variant_like_<std::variant<Types...>> : std::true_type {};

// formattable element check.
template <typename T, typename C> class is_variant_formattable_ {
template <std::size_t... I>
template <std::size_t... Is>
static std::conjunction<
is_formattable<std::variant_alternative_t<I, T>, C>...>
check(std::index_sequence<I...>);
is_formattable<std::variant_alternative_t<Is, T>, C>...>
check(std::index_sequence<Is...>);

public:
static constexpr const bool value =
Expand Down
2 changes: 0 additions & 2 deletions test/core-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#include "test-assert.h"
// clang-format on

#define I 42 // simulate https://en.cppreference.com/w/c/numeric/complex/I
#include "fmt/core.h"
#undef I

#include <algorithm> // std::copy_n
#include <climits> // INT_MAX
Expand Down
2 changes: 2 additions & 0 deletions test/enforce-checks-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#include <iterator>
#include <vector>

#define I 42 // simulate https://en.cppreference.com/w/c/numeric/complex/I
#include "fmt/chrono.h"
#include "fmt/color.h"
#include "fmt/format.h"
#include "fmt/ostream.h"
#include "fmt/ranges.h"
#include "fmt/xchar.h"
#undef I

// Exercise the API to verify that everything we expect to can compile.
void test_format_api() {
Expand Down

0 comments on commit aec3bb5

Please sign in to comment.