Skip to content

Cpp20 #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 14, 2025
Merged

Cpp20 #536

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ target_compile_options(quicr_benchmark

set_target_properties(quicr_benchmark
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS ON)

Expand Down
4 changes: 2 additions & 2 deletions benchmark/uintvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ UIntVar_ToBytes(benchmark::State& state)
{
constexpr auto var_int = quicr::UintVar(0x123456789);
for ([[maybe_unused]] const auto& _ : state) {
auto bytes = Span{ var_int };
auto bytes = std::span{ var_int };
benchmark::DoNotOptimize(bytes);
benchmark::ClobberMemory();
}
Expand All @@ -43,7 +43,7 @@ static void
UIntVar_FromBytes(benchmark::State& state)
{
constexpr auto var = quicr::UintVar(0x123456789);
auto bytes = Span{ var };
auto bytes = std::span{ var };
for ([[maybe_unused]] const auto& _ : state) {
auto value = quicr::UintVar(bytes);
benchmark::DoNotOptimize(value);
Expand Down
4 changes: 2 additions & 2 deletions cmd/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ target_compile_options(qclient

set_target_properties(qclient
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS OFF)

Expand All @@ -36,7 +36,7 @@ target_compile_options(qserver

set_target_properties(qserver
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS ON)

Expand Down
18 changes: 12 additions & 6 deletions cmd/examples/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,18 @@ DoPublisher(const quicr::FullTrackName& full_track_name, const std::shared_ptr<q
json moq_arr_j = json::parse(moq_fs);

for (const auto& moq_j : moq_arr_j) {
quicr::ObjectHeaders hdr;
hdr.object_id = moq_j["objectID"];
hdr.group_id = moq_j["groupID"];
hdr.subgroup_id = moq_j["subGroup"];
hdr.priority = moq_j["publisherPriority"];
hdr.payload_length = moq_j["dataLength"];
quicr::ObjectHeaders hdr{
.group_id = moq_j["groupID"],
.object_id = moq_j["objectID"],
.subgroup_id = moq_j["subGroup"],
.payload_length = moq_j["dataLength"],
.status = quicr::ObjectStatus::kAvailable,
.priority = moq_j["publisherPriority"],
.ttl = std::nullopt,
.track_mode = std::nullopt,
.extensions = std::nullopt,
};

std::size_t data_offset = moq_j["dataOffset"];

auto& msg = messages.emplace_back(std::make_pair(hdr, quicr::Bytes{}));
Expand Down
2 changes: 1 addition & 1 deletion cmd/examples/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ class MyServer : public quicr::Server
if (cache_entries.empty())
return false;

std::thread retrieve_cache_thread([=, cache_entries = cache_entries] {
std::thread retrieve_cache_thread([=, this, cache_entries = cache_entries] {
defer(UnbindFetchTrack(connection_handle, pub_fetch_h));

for (const auto& cache_entry : cache_entries) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/qperf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target_compile_options(qperf

set_target_properties(qperf
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS OFF)

Expand Down
4 changes: 3 additions & 1 deletion cmd/qperf/qperf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ main(int argc, char** argv)
.transport_config = config,
.metrics_sample_ms = 5000,
},
.connect_uri = result["connect_uri"].as<std::string>(),
result["connect_uri"].as<std::string>(),
};

const auto logger = spdlog::stderr_color_mt("PERF");
Expand Down Expand Up @@ -366,9 +366,11 @@ main(int argc, char** argv)
.group_id = group,
.object_id = objects,
.payload_length = data.size(),
.status = quicr::ObjectStatus::kAvailable,
.priority = priority,
.ttl = expiry_age,
.track_mode = track_mode,
.extensions = std::nullopt,
};

handler->PublishObject(header, data);
Expand Down
4 changes: 2 additions & 2 deletions cmd/qperf2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target_compile_options(qperf_pub

set_target_properties(qperf_pub
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS OFF)

Expand All @@ -34,7 +34,7 @@ target_compile_options(qperf_sub

set_target_properties(qperf_sub
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS OFF)

Expand Down
4 changes: 3 additions & 1 deletion include/quicr/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#pragma once

#include "detail/quic_transport.h"

#include <span>
#include <string>

namespace quicr {
Expand All @@ -20,7 +22,7 @@ namespace quicr {

using Byte = uint8_t;
using Bytes = std::vector<Byte>;
using BytesSpan = Span<const Byte>;
using BytesSpan = std::span<const Byte>;
using ConnectionHandle = uint64_t;

/**
Expand Down
7 changes: 4 additions & 3 deletions include/quicr/detail/base_track_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#pragma once

#include "quicr/common.h"
#include "quicr/track_name.h"

#include <optional>
#include <quicr/common.h>
#include <quicr/detail/span.h>
#include <quicr/track_name.h>
#include <span>
#include <vector>

namespace quicr {
Expand Down
14 changes: 7 additions & 7 deletions include/quicr/detail/data_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@

#pragma once

#include "span.h"
#include <cstdint>
#include <deque>
#include <memory>
#include <optional>
#include <span>
#include <vector>

namespace quicr {
template<class T, std::enable_if_t<std::is_standard_layout_v<T>, bool> = true>
inline Span<const uint8_t> AsBytes(const T& value)
inline std::span<const uint8_t> AsBytes(const T& value)
{
return Span{ reinterpret_cast<const std::uint8_t*>(&value), sizeof(T) };
return std::span{ reinterpret_cast<const std::uint8_t*>(&value), sizeof(T) };
}

template<>
inline Span<const uint8_t> AsBytes<std::string>(const std::string& value)
inline std::span<const uint8_t> AsBytes<std::string>(const std::string& value)
{
return Span{ reinterpret_cast<const std::uint8_t*>(value.data()), value.size() };
return std::span{ reinterpret_cast<const std::uint8_t*>(value.data()), value.size() };
}

template<class Allocator = std::allocator<std::uint8_t>>
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace quicr {
const SliceType& Last() const noexcept { return *std::prev(this->end()); }
const SliceType GetLast() const noexcept { return *std::prev(this->end()); }

void Push(Span<const uint8_t> bytes)
void Push(std::span<const uint8_t> bytes)
{
auto slice = std::make_shared<typename SliceType::element_type>();
slice->assign(bytes.begin(), bytes.end());
Expand All @@ -122,7 +122,7 @@ namespace quicr {

void Push(SliceType slice) { buffer_.push_back(std::move(slice)); }

friend DataStorage& operator<<(DataStorage& buffer, Span<const uint8_t> value)
friend DataStorage& operator<<(DataStorage& buffer, std::span<const uint8_t> value)
{
buffer.Push(value);
return buffer;
Expand Down
2 changes: 1 addition & 1 deletion include/quicr/detail/quic_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "quicr/detail/data_storage.h"
#include "quicr/detail/tick_service.h"
#include "safe_queue.h"
#include "span.h"
#include "stream_buffer.h"
#include "uintvar.h"
#include <span>

#include <spdlog/spdlog.h>

Expand Down
54 changes: 0 additions & 54 deletions include/quicr/detail/quic_transport_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@ namespace quicr {
uint64_t value_sum{ 0 }; /// Accumulating sum of values in period
uint64_t value_count{ 0 }; /// Number of values in period

#if __cplusplus >= 202002L
constexpr auto operator<=>(const MinMaxAvg&) const = default;
#else
constexpr bool operator==(const MinMaxAvg& other) const
{
return min == other.min && max == other.max && avg == other.avg && value_sum == other.value_sum;
}
constexpr bool operator!=(const MinMaxAvg& other) const { return !(*this == other); }
#endif

/**
* @brief Add value to period
Expand Down Expand Up @@ -92,25 +84,7 @@ namespace quicr {
uint64_t tx_dgram_spurious{ 0 }; ///< count of picoquic callback for late/delayed dgram acks
uint64_t tx_dgram_drops{ 0 }; ///< count of drops due to data context missing

#if __cplusplus >= 202002L
auto operator<=>(const QuicConnectionMetrics&) const = default;
#else
constexpr bool operator==(const QuicConnectionMetrics& other) const
{
return this->cwin_congested == other.cwin_congested &&
this->prev_cwin_congested == other.prev_cwin_congested && this->tx_congested == other.tx_congested &&
this->tx_rate_bps == other.tx_rate_bps && this->rx_rate_bps == other.rx_rate_bps &&
this->tx_cwin_bytes == other.tx_cwin_bytes &&
this->tx_in_transit_bytes == other.tx_in_transit_bytes && this->rtt_us == other.rtt_us &&
this->srtt_us == other.srtt_us && this->tx_retransmits == other.tx_retransmits &&
this->tx_lost_pkts == other.tx_lost_pkts && this->tx_timer_losses == other.tx_timer_losses &&
this->tx_spurious_losses == other.tx_spurious_losses && this->rx_dgrams == other.rx_dgrams &&
this->rx_dgrams_bytes == other.rx_dgrams_bytes && this->tx_dgram_cb == other.tx_dgram_cb &&
this->tx_dgram_ack == other.tx_dgram_ack && this->tx_dgram_lost == other.tx_dgram_lost &&
this->tx_dgram_spurious == other.tx_dgram_spurious && this->tx_dgram_drops == other.tx_dgram_drops;
}
constexpr bool operator!=(const QuicConnectionMetrics& other) const { return !(*this == other); }
#endif

/**
* @brief Reset metrics for period
Expand Down Expand Up @@ -151,25 +125,7 @@ namespace quicr {
uint64_t tx_stream_objects{ 0 }; /// count of stream objects sent
uint64_t tx_stream_bytes{ 0 }; /// count of stream bytes sent

#if __cplusplus >= 202002L
constexpr auto operator<=>(const QuicDataContextMetrics&) const = default;
#else
constexpr bool operator==(const QuicDataContextMetrics& other) const
{
return this->enqueued_objs == other.enqueued_objs && this->rx_stream_cb == other.rx_stream_cb &&
this->rx_stream_bytes == other.rx_stream_bytes && this->tx_buffer_drops == other.tx_buffer_drops &&
this->tx_queue_discards == other.tx_queue_discards &&
this->tx_queue_expired == other.tx_queue_expired &&
this->tx_delayed_callback == other.tx_delayed_callback &&
this->prev_tx_delayed_callback == other.prev_tx_delayed_callback &&
this->tx_reset_wait == other.tx_reset_wait && this->tx_queue_size == other.tx_queue_size &&
this->tx_callback_ms == other.tx_callback_ms &&
this->tx_object_duration_us == other.tx_object_duration_us && this->tx_dgrams == other.tx_dgrams &&
this->tx_dgrams_bytes == other.tx_dgrams_bytes && this->tx_stream_cb == other.tx_stream_cb &&
this->tx_stream_objects == other.tx_stream_objects && this->tx_stream_bytes == other.tx_stream_bytes;
}
constexpr bool operator!=(const QuicDataContextMetrics& other) const { return !(*this == other); }
#endif

/**
* @brief Reset metrics for period
Expand Down Expand Up @@ -197,17 +153,7 @@ namespace quicr {
uint64_t rx_bytes{ 0 }; /// count of bytes received
uint64_t rx_objects{ 0 }; /// count of objects received

#if __cplusplus >= 202002L
constexpr auto operator<=>(const UdpDataContextMetrics&) const = default;
#else
constexpr auto operator==(const UdpDataContextMetrics& other) const
{
return this->enqueued_objs == other.enqueued_objs && this->tx_queue_expired == other.tx_queue_expired &&
this->tx_bytes == other.tx_bytes && this->tx_objects == other.tx_objects &&
this->rx_bytes == other.rx_bytes && this->rx_objects == other.rx_objects;
}
constexpr auto operator!=(const UdpDataContextMetrics& other) const { return !(*this == other); }
#endif
};

struct UdpConnectionMetrics
Expand Down
Loading