Skip to content

Commit 4356737

Browse files
committed
Use C++23
1 parent c7714a0 commit 4356737

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

.github/workflows/c-cpp.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ jobs:
3131
with:
3232
submodules: true
3333

34+
- if: matrix.os == 'ubuntu-latest'
35+
name: Install GCC 16
36+
uses: egor-tensin/setup-gcc@v2
37+
with:
38+
version: 16
39+
3440
- uses: lukka/get-cmake@latest
3541

3642
- name: Get submodule commit hashes

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
108108
file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp")
109109
add_library("${PROJECT_NAME}_static" STATIC ${SOURCES} ${PROTO_HEADER} ${PROTO_SRC})
110110
target_link_libraries("${PROJECT_NAME}_static" PUBLIC ${DEPS_LIBS})
111-
set_property(TARGET "${PROJECT_NAME}_static" PROPERTY CXX_STANDARD 20)
111+
set_property(TARGET "${PROJECT_NAME}_static" PROPERTY CXX_STANDARD 23)
112112
include_directories("${PROJECT_NAME}_static" PUBLIC ${DEPS_INCLUDES} ${Protobuf_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/src")
113113
if(UNIX)
114114
target_compile_options("${PROJECT_NAME}_static" PRIVATE "-fPIC")
@@ -119,15 +119,15 @@ endif()
119119
file(GLOB_RECURSE DRIVER_MAIN "${CMAKE_CURRENT_SOURCE_DIR}/src/DriverFactory.cpp")
120120
add_library("${PROJECT_NAME}" SHARED ${DRIVER_MAIN} ${HEADERS} ${PROTO_HEADER})
121121
target_link_libraries("${PROJECT_NAME}" PUBLIC "${PROJECT_NAME}_static")
122-
set_property(TARGET "${PROJECT_NAME}" PROPERTY CXX_STANDARD 20)
122+
set_property(TARGET "${PROJECT_NAME}" PROPERTY CXX_STANDARD 23)
123123

124124
# compile tests
125125
function(build_tests target_name test_dir)
126126
file(GLOB TESTS "${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/*.hpp")
127127
file(GLOB TESTS_COMMON "${CMAKE_CURRENT_SOURCE_DIR}/test/common/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/test/common/*.hpp")
128128
add_executable(${target_name} ${TESTS} ${TESTS_COMMON} ${HEADERS} ${PROTO_HEADER})
129129
target_link_libraries(${target_name} PUBLIC "${PROJECT_NAME}_static" Catch2::Catch2WithMain)
130-
set_property(TARGET ${target_name} PROPERTY CXX_STANDARD 20)
130+
set_property(TARGET ${target_name} PROPERTY CXX_STANDARD 23)
131131
endfunction()
132132
build_tests(tests "test")
133133
build_tests(tests_integration "test/integration")

src/VRDriver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <TrackerDevice.hpp>
66
#include <google/protobuf/arena.h>
77
#include <simdjson.h>
8+
#include <utility>
89

910
vr::EVRInitError SlimeVRDriver::VRDriver::Init(vr::IVRDriverContext* pDriverContext) {
1011
// Perform driver context initialisation
@@ -133,7 +134,7 @@ void SlimeVRDriver::VRDriver::RunPoseRequestThread(std::stop_token stop) {
133134

134135
auto notify_status_changed = [this](DeviceData& device, messages::ProtobufMessage* message, messages::TrackerStatus_Status status) {
135136
if (device.status != status) {
136-
logger_->Log("Status for device {} changing {}->{}", device.index, static_cast<int>(device.status), static_cast<int>(status));
137+
logger_->Log("Status for device {} changing {}->{}", device.index, std::to_underlying(device.status), std::to_underlying(status));
137138
messages::TrackerStatus* tracker_status = google::protobuf::Arena::Create<messages::TrackerStatus>(&arena_);
138139
message->set_allocated_tracker_status(tracker_status);
139140
tracker_status->set_tracker_id(device.index);
@@ -342,7 +343,7 @@ void SlimeVRDriver::VRDriver::OnBridgeMessage(const messages::ProtobufMessage& m
342343
AddDevice(std::make_shared<TrackerDevice>(ta.tracker_serial(), ta.tracker_id(), role));
343344
break;
344345
default:
345-
logger_->Log("Got tracker added message for unhandled device type {} (role {})", static_cast<unsigned>(GetDeviceType(role)), static_cast<unsigned>(role));
346+
logger_->Log("Got tracker added message for unhandled device type {} (role {})", std::to_underlying(GetDeviceType(role)), std::to_underlying(role));
346347
break;
347348
}
348349
} else if (message.has_position()) {

src/bridge/BridgeTransport.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
THE SOFTWARE.
2222
*/
2323
#include "BridgeTransport.hpp"
24+
#include <bit>
2425

2526
void BridgeTransport::Start() {
2627
thread_ = std::make_unique<std::thread>(&BridgeTransport::RunThread, this);
@@ -83,11 +84,10 @@ void BridgeTransport::OnRecv(const uvw::data_event& event) {
8384

8485
char len_buf[4];
8586
recv_buf_.Peek(len_buf, 4);
86-
uint32_t size = 0;
87-
size = static_cast<uint32_t>(static_cast<uint8_t>(len_buf[0])) | //
88-
(static_cast<uint32_t>(static_cast<uint8_t>(len_buf[1])) << 8) | //
89-
(static_cast<uint32_t>(static_cast<uint8_t>(len_buf[2])) << 16) | //
90-
(static_cast<uint32_t>(static_cast<uint8_t>(len_buf[3])) << 24);
87+
uint32_t size = *reinterpret_cast<uint32_t*>(&len_buf[0]);
88+
if constexpr (std::endian::native != std::endian::little) {
89+
size = std::byteswap(size);
90+
}
9191

9292
if (size > VRBRIDGE_MAX_MESSAGE_SIZE) {
9393
logger_->Log(

0 commit comments

Comments
 (0)