Skip to content

Commit

Permalink
Fix build on MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
Neverlord committed Jun 16, 2024
1 parent 3ddf595 commit 8cc0d68
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
5 changes: 3 additions & 2 deletions libbroker/broker/convert.hh
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ template <class T>
std::enable_if_t<
detail::has_convert_v<T, std::string> // must have a convert function
&& !std::is_arithmetic_v<T> // avoid ambiguitiy with default overloads
&& !std::is_convertible_v<T, std::string>, // avoid ambiguity with
// conversion-to-string
&& !std::is_convertible_v<T, std::string> // avoid ambiguity with
// conversion-to-string
&& !std::is_same_v<T, std::string_view>,
std::ostream&>
operator<<(std::ostream& os, const T& x) {
std::string str;
Expand Down
3 changes: 1 addition & 2 deletions libbroker/broker/detail/sqlite_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ struct sqlite_backend::impl {
if (!dir.empty()) {
if (!detail::is_directory(dir) && !detail::mkdirs(dir)) {
log::store::error("sqlite-create-dir-failed",
"failed to create directory for database: {}",
dir.c_str());
"failed to create directory for database: {}", dir);
return false;
}
}
Expand Down
15 changes: 15 additions & 0 deletions libbroker/broker/detail/type_traits.hh
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ public:
static constexpr bool value = std::is_same_v<result, std::string>;
};

// Trait that checks whether a type has a .string() member function.
template <class T>
class has_string_member_fn {
private:
template <class U>
static auto sfinae(const U& x) -> decltype(x.string());

static void sfinae(...);

using result = std::decay_t<decltype(sfinae(std::declval<const T&>()))>;

public:
static constexpr bool value = std::is_same_v<result, std::string>;
};

} // namespace broker::detail

#define BROKER_DEF_HAS_ENCODE_IN_NS(ns_name) \
Expand Down
3 changes: 3 additions & 0 deletions libbroker/broker/logger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ OutputIterator fmt_to(OutputIterator out, std::string_view fmt, const T& arg,
} else if constexpr (has_to_string<T>::value) {
auto str = to_string(arg);
out = std::copy(str.begin(), str.end(), out);
} else if constexpr (has_string_member_fn<T>::value) {
auto&& str = arg.string();
out = std::copy(str.begin(), str.end(), out);
} else {
static_assert(std::is_convertible_v<T, const char*>);
for (auto cstr = arg; *cstr != '\0'; ++cstr)
Expand Down
21 changes: 11 additions & 10 deletions libbroker/broker/master.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ bool operator==(const string_list& xs, const pattern_list& ys) {
}

struct fixture : base_fixture {
string_list log;
string_list log_lines;
worker logger;

caf::timespan tick_interval = defaults::store::tick_interval;
Expand All @@ -100,11 +100,11 @@ struct fixture : base_fixture {
[this](data_message msg) {
auto content = get_data(msg).to_data();
if (auto insert = store_event::insert::make(content))
log.emplace_back(to_string(insert));
log_lines.emplace_back(to_string(insert));
else if (auto update = store_event::update::make(content))
log.emplace_back(to_string(update));
log_lines.emplace_back(to_string(update));
else if (auto erase = store_event::erase::make(content))
log.emplace_back(to_string(erase));
log_lines.emplace_back(to_string(erase));
else
FAIL("unknown event: " << to_string(content));
},
Expand Down Expand Up @@ -162,12 +162,13 @@ TEST(local_master) {
CHECK_EQUAL(unbox(ds.put_unique("bar", "unicorn")), data{false});
// check log
run(tick_interval);
CHECK_EQUAL(log, pattern_list({
"insert\\(foo, hello, world, (null|none), .+\\)",
"update\\(foo, hello, world, universe, (null|none), .+\\)",
"erase\\(foo, hello, .+\\)",
"insert\\(foo, bar, baz, .+\\)",
}));
CHECK_EQUAL(log_lines,
pattern_list({
"insert\\(foo, hello, world, (null|none), .+\\)",
"update\\(foo, hello, world, universe, (null|none), .+\\)",
"erase\\(foo, hello, .+\\)",
"insert\\(foo, bar, baz, .+\\)",
}));
// done
caf::anon_send_exit(core, caf::exit_reason::user_shutdown);
}
Expand Down

0 comments on commit 8cc0d68

Please sign in to comment.