Skip to content

Commit

Permalink
Fix has_tag for variant custom tag
Browse files Browse the repository at this point in the history
  • Loading branch information
erenon authored and spektrof committed Jun 24, 2022
1 parent 7bb21fc commit e94cccc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/binlog/adapt_stdvariant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ struct CustomSerializer<std::variant<T...>>
template <typename... T>
struct CustomTag<std::variant<T...>>
{
// Make this type not-constructible, if some Tag<T> is not constructible
std::conditional_t<
detail::conjunction<detail::has_tag<T>...>::value,
std::true_type,
mserialize::detail::BuiltinTag<void>
> tag_guard;

static constexpr auto tag_string()
{
return cx_strcat(
Expand Down
8 changes: 8 additions & 0 deletions test/integration/LoggingVariants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,11 @@ int main()

binlog::consume(std::cout);
}

struct Adapted {};
BINLOG_ADAPT_STRUCT(Adapted)

struct NotAdapted {};

static_assert(mserialize::detail::has_tag<std::variant<Adapted>>::value, "");
static_assert(!mserialize::detail::has_tag<std::variant<NotAdapted>>::value, "");

0 comments on commit e94cccc

Please sign in to comment.