Skip to content

Commit

Permalink
Simplify is_variant_like_ check, fix compile error before GCC 11 (#3072)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladislav Shchapov <[email protected]>

Co-authored-by: Vladislav Shchapov <[email protected]>
  • Loading branch information
NewbieOrange and phprus authored Sep 3, 2022
1 parent fec5515 commit 29c6000
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 4 additions & 6 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,12 @@ template <typename T>
using variant_index_sequence =
std::make_index_sequence<std::variant_size<T>::value>;

// variant_size and variant_alternative check.
template <typename T, typename U = void>
template <typename>
struct is_variant_like_ : std::false_type {};
template <typename T>
struct is_variant_like_<T, std::void_t<decltype(std::variant_size<T>::value)>>
: std::true_type {};
template <typename... Types>
struct is_variant_like_<std::variant<Types...>> : std::true_type {};

// formattable element check
// formattable element check.
template <typename T, typename C> class is_variant_formattable_ {
template <std::size_t... I>
static std::conjunction<
Expand Down
3 changes: 3 additions & 0 deletions test/std-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ TEST(std_test, variant) {

EXPECT_EQ(fmt::format("{}", v4), "variant(monostate)");
EXPECT_EQ(fmt::format("{}", v5), "variant(\"yes, this is variant\")");

volatile int i = 42; // Test compile error before GCC 11 described in #3068.
EXPECT_EQ(fmt::format("{}", i), "42");
#endif
}

Expand Down

0 comments on commit 29c6000

Please sign in to comment.