From d9aae1521a524358d609aff55186b26f82dfae6b Mon Sep 17 00:00:00 2001 From: Nimrod Gileadi Date: Tue, 17 Jun 2025 08:33:38 -0700 Subject: [PATCH] Remove confusing operator overload in user_api.cc Explicitly add const_cast. This doesn't change the previous behaviour, just makes it explicit. PiperOrigin-RevId: 772486471 Change-Id: I942bd4effed93a366089411ca18461cad52bff88 --- src/user/user_api.cc | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/user/user_api.cc b/src/user/user_api.cc index eea4aa93..be326503 100644 --- a/src/user/user_api.cc +++ b/src/user/user_api.cc @@ -41,24 +41,6 @@ using mujoco::user::StringToVector; static constexpr std::size_t kGlobalCacheSize = 500 * (1 << 20); -// prepend prefix -template -static T& operator+(std::string_view prefix, T& base) { - base.prefix = std::string(prefix); - return base; -} - - - -// append suffix -template -static T& operator+(T& base, std::string_view suffix) { - base.suffix = std::string(suffix); - return base; -} - - - // create model mjSpec* mj_makeSpec() { mjCModel* modelC = new mjCModel; @@ -135,8 +117,11 @@ static void SetFrame(mjsBody* body, mjtObj objtype, mjsFrame* frame) { // attach body to a frame of the parent static mjsElement* attachBody(mjCFrame* parent, const mjCBody* child, const char* prefix, const char* suffix) { + mjCBody* mutable_child = const_cast(child); + mutable_child->prefix = prefix; + mutable_child->suffix = suffix; try { - *parent += std::string(prefix) + *(mjCBody*)child + std::string(suffix); + *parent += *mutable_child; } catch (mjCError& e) { parent->model->SetError(e); return nullptr; @@ -151,8 +136,11 @@ static mjsElement* attachBody(mjCFrame* parent, const mjCBody* child, // attach frame to a parent body static mjsElement* attachFrame(mjCBody* parent, const mjCFrame* child, const char* prefix, const char* suffix) { + mjCFrame* mutable_child = const_cast(child); + mutable_child->prefix = prefix; + mutable_child->suffix = suffix; try { - *parent += std::string(prefix) + *(mjCFrame*)child + std::string(suffix); + *parent += *mutable_child; } catch (mjCError& e) { parent->model->SetError(e); return nullptr;