From 8d7f40d315f41da27b822ff4e1f8aef326126886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Fri, 5 Jul 2024 15:21:25 +0200 Subject: [PATCH] Removed deprecated clamp methods (#193) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- CMakeLists.txt | 3 -- include/rcppmath/clamp.hpp | 71 -------------------------------------- test/test_clamp.cpp | 66 ----------------------------------- 3 files changed, 140 deletions(-) delete mode 100644 include/rcppmath/clamp.hpp delete mode 100644 test/test_clamp.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index edca5d1..28a9fca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,9 +160,6 @@ if(BUILD_TESTING) ENVIRONMENT "_TEST_LIBRARY_DIR=$;_TEST_LIBRARY=$") - ament_add_gtest(test_clamp test/test_clamp.cpp) - target_link_libraries(test_clamp ${PROJECT_NAME}) - ament_add_gtest(test_accumulator test/test_accumulator.cpp) target_link_libraries(test_accumulator ${PROJECT_NAME}) diff --git a/include/rcppmath/clamp.hpp b/include/rcppmath/clamp.hpp deleted file mode 100644 index 9919099..0000000 --- a/include/rcppmath/clamp.hpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2020 PAL Robotics S.L. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/*! \file clamp.hpp - * \brief Restrict a value between two bounds. - */ - -#ifndef RCPPMATH__CLAMP_HPP_ -#define RCPPMATH__CLAMP_HPP_ - -#include - -namespace rcppmath -{ -/** - * If v compares less than lo, returns lo; otherwise if hi compares less - * than v, returns hi; otherwise returns v. Uses operator< to compare the values. - * - * \param[in] v The value to clamp. - * \param[in] lo The lower boundary. - * \param[in] hi The higher boundary. - * \return Reference to lo if v is less than lo, reference to hi if hi is less than v, otherwise - * reference to v. - * \note Implementation from https://en.cppreference.com/w/cpp/algorithm/clamp. - * \warning Capturing the result of clamp by reference if one of the parameters is rvalue produces - * a dangling reference if that parameter is returned. - */ -template -[[deprecated("use std::clamp instead, introduced in C++17")]] -constexpr const T & clamp(const T & v, const T & lo, const T & hi) -{ - assert(!(hi < lo) ); - return (v < lo) ? lo : (hi < v) ? hi : v; -} - -/** - * Performs clamping with a provided Comparison object (comp). - * - * \param[in] v The value to clamp. - * \param[in] lo The lower boundary. - * \param[in] hi The higher boundary. - * \param[in] comp Comparison object that returns true if the first argument is - * less than the second. - * \return Reference to lo if v is less than lo, reference to hi if hi is less than v, otherwise - * reference to v. "Less than" semantics determined by Comparison object. - * \warning Capturing the result of clamp by reference if one of the parameters is rvalue produces - * a dangling reference if that parameter is returned. - * \sa rcppmath::clamp(const T&, const T&, const T&) - */ -template -[[deprecated("use std::clamp instead, introduced in C++17")]] -constexpr const T & clamp(const T & v, const T & lo, const T & hi, Compare comp) -{ - assert(!comp(hi, lo) ); - return comp(v, lo) ? lo : comp(hi, v) ? hi : v; -} - -} // namespace rcppmath - -#endif // RCPPMATH__CLAMP_HPP_ diff --git a/test/test_clamp.cpp b/test/test_clamp.cpp deleted file mode 100644 index 49845a4..0000000 --- a/test/test_clamp.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2020 PAL Robotics S.L. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include "rcppmath/clamp.hpp" - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4996) -#else -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -TEST(test_clamp, test_basic) { - EXPECT_EQ(rcppmath::clamp(1, 2, 5), 2); - EXPECT_EQ(rcppmath::clamp(2, 2, 5), 2); - EXPECT_EQ(rcppmath::clamp(5, 2, 5), 5); - EXPECT_EQ(rcppmath::clamp(6, 2, 5), 5); - EXPECT_EQ(rcppmath::clamp(3, 2, 5), 3); - EXPECT_EQ(rcppmath::clamp(4, 2, 5), 4); -} - -TEST(test_clamp, test_cmp) { - auto cmp = [](const int & a, const int & b) - { - return a < b; - }; - EXPECT_EQ(rcppmath::clamp(1, 2, 5, cmp), 2); - EXPECT_EQ(rcppmath::clamp(2, 2, 5, cmp), 2); - EXPECT_EQ(rcppmath::clamp(5, 2, 5, cmp), 5); - EXPECT_EQ(rcppmath::clamp(6, 2, 5, cmp), 5); - EXPECT_EQ(rcppmath::clamp(3, 2, 5, cmp), 3); - EXPECT_EQ(rcppmath::clamp(4, 2, 5, cmp), 4); -} -TEST(test_clamp, test_limits) { - EXPECT_EQ(rcppmath::clamp(std::numeric_limits::infinity(), 0.0, 1.0), 1.0); - EXPECT_EQ(rcppmath::clamp(-std::numeric_limits::infinity(), 0.0, 1.0), 0.0); - - // Nan's are not limited by clamp, and return a nan, which is not comparable to itself - EXPECT_NE(rcppmath::clamp(std::numeric_limits::quiet_NaN(), 0.0, 1.0), 0.0); - EXPECT_NE(rcppmath::clamp(std::numeric_limits::quiet_NaN(), 0.0, 1.0), 1.0); - EXPECT_NE( - rcppmath::clamp( - std::numeric_limits::quiet_NaN(), 0.0, 1.0), - std::numeric_limits::quiet_NaN()); -} - -#ifdef _MSC_VER -#pragma warning(pop) -#else -#pragma GCC diagnostic pop -#endif