Skip to content

Commit

Permalink
Fix for invalid conversion from const char8_t* to char for C++20 (#160)
Browse files Browse the repository at this point in the history
Signed-off-by: Guilherme Rodrigues <[email protected]>
  • Loading branch information
AiVerisimilitude authored Sep 14, 2023
1 parent fa5d52c commit 7f4d0d6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions test_msgs/include/test_msgs/message_fixtures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <limits>
#include <memory>
#include <vector>
#include <utility>
#include <string>

#include "test_msgs/msg/arrays.hpp"
#include "test_msgs/msg/basic_types.hpp"
Expand All @@ -36,6 +38,26 @@
#include "test_msgs/msg/unbounded_sequences.hpp"
#include "test_msgs/msg/w_strings.hpp"

static inline std::string
from_u8string(const std::string & s)
{
return s;
}

static inline std::string
from_u8string(std::string && s)
{
return std::move(s);
}

#if defined(__cpp_lib_char8_t)
static inline std::string
from_u8string(const std::u8string & s)
{
return std::string(s.begin(), s.end());
}
#endif

static inline std::vector<test_msgs::msg::Empty::SharedPtr>
get_messages_empty()
{
Expand Down Expand Up @@ -160,8 +182,8 @@ get_messages_strings()
}
{
auto msg = std::make_shared<test_msgs::msg::Strings>();
msg->string_value = u8"Hell\u00F6 W\u00F6rld!"; // using umlaut
msg->bounded_string_value = u8"Hell\u00F6 W\u00F6rld!"; // using umlaut
msg->string_value = from_u8string(u8"Hell\u00F6 W\u00F6rld!"); // using umlaut
msg->bounded_string_value = from_u8string(u8"Hell\u00F6 W\u00F6rld!"); // using umlaut
messages.push_back(msg);
}
{
Expand Down

0 comments on commit 7f4d0d6

Please sign in to comment.