From be9f725023b7479ac121edd90a0822d52f9cc135 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 31 Dec 2020 12:35:02 -0800 Subject: [PATCH] [ntcore] NetworkTableValue: Use std::forward instead of std::move (#3022) Because these are forwarding references, they could unexpectedly move a passed lvalue. Using std::forward() makes a copy if an lvalue is passed. --- .../main/native/include/networktables/NetworkTableValue.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ntcore/src/main/native/include/networktables/NetworkTableValue.h b/ntcore/src/main/native/include/networktables/NetworkTableValue.h index a26f06636e..40881126d8 100644 --- a/ntcore/src/main/native/include/networktables/NetworkTableValue.h +++ b/ntcore/src/main/native/include/networktables/NetworkTableValue.h @@ -288,7 +288,7 @@ class Value final { typename std::enable_if::value>::type> static std::shared_ptr MakeString(T&& value, uint64_t time = 0) { auto val = std::make_shared(NT_STRING, time, private_init()); - val->m_string = std::move(value); + val->m_string = std::forward(value); val->m_val.data.v_string.str = const_cast(val->m_string.c_str()); val->m_val.data.v_string.len = val->m_string.size(); return val; @@ -322,7 +322,7 @@ class Value final { typename std::enable_if::value>::type> static std::shared_ptr MakeRaw(T&& value, uint64_t time = 0) { auto val = std::make_shared(NT_RAW, time, private_init()); - val->m_string = std::move(value); + val->m_string = std::forward(value); val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); val->m_val.data.v_raw.len = val->m_string.size(); return val; @@ -355,7 +355,7 @@ class Value final { template static std::shared_ptr MakeRpc(T&& value, uint64_t time = 0) { auto val = std::make_shared(NT_RPC, time, private_init()); - val->m_string = std::move(value); + val->m_string = std::forward(value); val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); val->m_val.data.v_raw.len = val->m_string.size(); return val;