Skip to content

Commit 21848b0

Browse files
committed
update to c++20
With various associated library updates and compatibility fixes.
1 parent 442e4a6 commit 21848b0

File tree

7 files changed

+18
-49
lines changed

7 files changed

+18
-49
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ endif()
1515

1616
project(spns)
1717

18-
set(CMAKE_CXX_STANDARD 17)
18+
set(CMAKE_CXX_STANDARD 20)
1919
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2020
set(CMAKE_CXX_EXTENSIONS OFF)
2121
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

libpqxx

Submodule libpqxx updated 101 files

spns/bytes.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ struct is_bytes_impl {
4747
template <typename T>
4848
inline constexpr bool is_bytes = decltype(is_bytes_impl::check(static_cast<T*>(nullptr)))::value;
4949

50+
template <typename T>
51+
concept bytes_subtype = is_bytes<T>;
52+
5053
struct AccountID : bytes<33> {};
5154
struct Ed25519PK : bytes<32> {};
5255
struct X25519PK : bytes<32> {};

spns/hivemind.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,9 @@ void HiveMind::log_stats(std::string_view pre_cmd) {
912912
total_notifies,
913913
pushes_processed_.load());
914914

915-
auto sd_format = pre_cmd.empty() ? "STATUS={1}" : "{0}\nSTATUS={1}";
916-
sd_notify(0, fmt::format(sd_format, pre_cmd, stat_line).c_str());
915+
auto sd_out = pre_cmd.empty() ? "STATUS={}"_format(stat_line)
916+
: "{}\nSTATUS={}"_format(pre_cmd, stat_line);
917+
sd_notify(0, sd_out.c_str());
917918

918919
if (auto now = std::chrono::steady_clock::now(); now - last_stats_logged >= 4min + 55s) {
919920
log::info(stats, "Status: {}", stat_line);
@@ -1049,12 +1050,7 @@ void HiveMind::on_notifier_validation(
10491050
response["message"] = std::move(message);
10501051

10511052
sub_json_set_one_response(
1052-
std::move(replier),
1053-
final_response,
1054-
i,
1055-
remaining,
1056-
multi,
1057-
std::move(response));
1053+
std::move(replier), final_response, i, remaining, multi, std::move(response));
10581054
}
10591055

10601056
std::tuple<SwarmPubkey, std::optional<Subaccount>, int64_t, Signature, std::string, nlohmann::json>
@@ -1667,8 +1663,8 @@ SELECT
16671663
ARRAY(SELECT namespace FROM sub_namespaces WHERE subscription = id ORDER BY namespace)
16681664
FROM subscriptions
16691665
WHERE
1670-
account = {} AND service = {} AND svcid = {})"_format(
1671-
tx.quote(pubkey.id), tx.quote(service), tx.quote(service_id)));
1666+
account = $1 AND service = $2 AND svcid = $3)",
1667+
{pubkey.id, service, service_id});
16721668
int64_t id;
16731669
if (result) {
16741670
auto& [row_id, sig_ts, ns_arr] = *result;

spns/pg.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#pragma once
2+
13
#include <chrono>
24
#include <mutex>
35
#include <pqxx/pqxx>
4-
#include <stack>
6+
#include <deque>
57

68
#include "bytes.hpp"
79

@@ -117,7 +119,7 @@ inline const std::string type_name<spns::Signature>{"spns::Signature"};
117119
template <>
118120
inline const std::string type_name<spns::EncKey>{"spns::EncKey"};
119121

120-
template <typename T, typename = std::enable_if_t<spns::is_bytes<T>>>
122+
template <spns::bytes_subtype T>
121123
struct spns_byte_helper {
122124
static constexpr size_t SIZE = T::SIZE;
123125
static T from_string(std::string_view text) {
@@ -148,9 +150,6 @@ struct spns_byte_helper {
148150
}
149151
};
150152

151-
template <typename T>
152-
struct nullness<T, std::enable_if_t<spns::is_bytes<T>>> : pqxx::no_null<T> {};
153-
154153
template <>
155154
struct string_traits<spns::AccountID> : spns_byte_helper<spns::AccountID> {};
156155
template <>

spns/utils.hpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <fmt/format.h>
4+
#include <oxen/log/format.hpp>
45

56
#include <charconv>
67
#include <chrono>
@@ -40,37 +41,7 @@ inline ustring_view as_usv(bstring_view s) {
4041
return {reinterpret_cast<const unsigned char*>(s.data()), s.size()};
4142
}
4243

43-
// Can replace this with a `using namespace oxen::log::literals` if we start using oxen-logging
44-
namespace detail {
45-
46-
// Internal implementation of _format that holds the format temporarily until the (...) operator
47-
// is invoked on it. This object cannot be moved, copied but only used ephemerally in-place.
48-
struct fmt_wrapper {
49-
private:
50-
std::string_view format;
51-
52-
// Non-copyable and non-movable:
53-
fmt_wrapper(const fmt_wrapper&) = delete;
54-
fmt_wrapper& operator=(const fmt_wrapper&) = delete;
55-
fmt_wrapper(fmt_wrapper&&) = delete;
56-
fmt_wrapper& operator=(fmt_wrapper&&) = delete;
57-
58-
public:
59-
constexpr explicit fmt_wrapper(const char* str, const std::size_t len) : format{str, len} {}
60-
61-
/// Calling on this object forwards all the values to fmt::format, using the format string
62-
/// as provided during construction (via the "..."_format user-defined function).
63-
template <typename... T>
64-
auto operator()(T&&... args) && {
65-
return fmt::format(format, std::forward<T>(args)...);
66-
}
67-
};
68-
69-
} // namespace detail
70-
71-
inline detail::fmt_wrapper operator""_format(const char* str, size_t len) {
72-
return detail::fmt_wrapper{str, len};
73-
}
44+
using namespace oxen::log::literals;
7445

7546
/// Splits a string on some delimiter string and returns a vector of string_view's pointing into the
7647
/// pieces of the original string. The pieces are valid only as long as the original string remains

0 commit comments

Comments
 (0)