Skip to content

Commit b510abe

Browse files
committed
C++20 compatibility.
1 parent d0689de commit b510abe

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

ros_babel_fish/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cmake_minimum_required(VERSION 3.5)
2-
project(ros_babel_fish VERSION 3.25.2)
3-
set(CMAKE_CXX_STANDARD 17)
2+
project(ros_babel_fish VERSION 4.26.43)
3+
# Default to C++20
4+
if(NOT CMAKE_CXX_STANDARD)
5+
set(CMAKE_CXX_STANDARD 20)
6+
endif()
47

58
# If the value doesn't fit, an exception is thrown in any case because that could result in unexpected behavior and can not be ignored lightly
69
option(WARN_ON_INCOMPATIBLE_TYPE "If ON a warning is printed if a value message is set or accessed with a type that does not allow casting without loss of information" ON)

ros_babel_fish/examples/any_subscriber.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
#include <chrono>
5+
#include <cstdint>
56
#include <geometry_msgs/msg/point.hpp>
67
#include <geometry_msgs/msg/point32.hpp>
78
#include <rclcpp/rclcpp.hpp>
@@ -117,6 +118,20 @@ void printToStdOut<uint8_t>( const uint8_t &val )
117118
std::cout << static_cast<int>( val ); // Cast to int for proper displaying
118119
}
119120

121+
template<>
122+
void printToStdOut<char16_t>( const char16_t &val )
123+
{
124+
// std::ostream << char16_t is deleted in C++20 for narrow streams.
125+
std::cout << static_cast<std::uint_least16_t>( val );
126+
}
127+
128+
template<>
129+
void printToStdOut<char32_t>( const char32_t &val )
130+
{
131+
// std::ostream << char32_t is deleted in C++20 for narrow streams.
132+
std::cout << static_cast<std::uint_least32_t>( val );
133+
}
134+
120135
template<typename T>
121136
void printArray( const T &message, const std::string & )
122137
{

ros_babel_fish_tools/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cmake_minimum_required(VERSION 3.5)
2-
project(ros_babel_fish_tools VERSION 0.1.0)
3-
set(CMAKE_CXX_STANDARD 17)
2+
project(ros_babel_fish_tools VERSION 4.26.43)
3+
# Default to C++20
4+
if(NOT CMAKE_CXX_STANDARD)
5+
set(CMAKE_CXX_STANDARD 20)
6+
endif()
47

58
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
69
add_compile_options(-Wall -Wextra -Wpedantic)

ros_babel_fish_tools/test/nlohmann_json_serialization.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,15 @@ TEST_F( JsonSerializationTest, supplementaryUnicode )
399399
{
400400
auto msg = fish.create_message_shared( "ros_babel_fish_test_msgs/msg/TestMessage" );
401401
// U+1F600 GRINNING FACE — requires 4-byte UTF-8
402-
( *msg )["str"] = std::string( u8"\U0001F600" );
402+
const std::string emoji_utf8 = "\xF0\x9F\x98\x80";
403+
( *msg )["str"] = emoji_utf8;
403404

404405
json j = compound_message_to_json( *msg );
405-
EXPECT_EQ( j["str"].get<std::string>(), u8"\U0001F600" );
406+
EXPECT_EQ( j["str"].get<std::string>(), emoji_utf8 );
406407

407408
auto msg2 = fish.create_message_shared( "ros_babel_fish_test_msgs/msg/TestMessage" );
408409
json_to_message( j, *msg2 );
409-
EXPECT_EQ( ( *msg2 )["str"].value<std::string>(), u8"\U0001F600" );
410+
EXPECT_EQ( ( *msg2 )["str"].value<std::string>(), emoji_utf8 );
410411
}
411412

412413
TEST_F( JsonSerializationTest, boundedArrayThrows )

0 commit comments

Comments
 (0)