From 502e28b4c03b1e16c05c8557ea4d20ebb60395ef Mon Sep 17 00:00:00 2001 From: Patrick Barone Date: Wed, 24 Apr 2024 13:01:56 -0400 Subject: [PATCH] iox-#2277 Add nodiscard to iox containers when pushing/emplacing fails --- iceoryx_hoofs/container/include/iox/forward_list.hpp | 4 ++-- iceoryx_hoofs/container/include/iox/list.hpp | 8 ++++---- iceoryx_hoofs/container/include/iox/vector.hpp | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/iceoryx_hoofs/container/include/iox/forward_list.hpp b/iceoryx_hoofs/container/include/iox/forward_list.hpp index 80453b7f15..82670d1f50 100644 --- a/iceoryx_hoofs/container/include/iox/forward_list.hpp +++ b/iceoryx_hoofs/container/include/iox/forward_list.hpp @@ -179,12 +179,12 @@ class forward_list /// @brief add element to the beginning of the list /// @param[in] data reference to data element /// @return successful insertion (true), otherwise no element could be added to list (e.g. full -> false) - bool push_front(const T& data) noexcept; + [[nodiscard]] bool push_front(const T& data) noexcept; /// @brief add element to the beginning of the list via move /// @param[in] data universal reference perfectly forwarded to client class /// @return successful insertion (true), otherwise no element could be added to list (e.g. full -> false) - bool push_front(T&& data) noexcept; + [[nodiscard]] bool push_front(T&& data) noexcept; /// @brief remove the first element from the begining of the list /// element destructor will be invoked diff --git a/iceoryx_hoofs/container/include/iox/list.hpp b/iceoryx_hoofs/container/include/iox/list.hpp index 03b67018db..60e1b6c9cf 100644 --- a/iceoryx_hoofs/container/include/iox/list.hpp +++ b/iceoryx_hoofs/container/include/iox/list.hpp @@ -175,22 +175,22 @@ class list /// @brief add element to the beginning of the list /// @param[in] data reference to data element /// @return successful insertion (true), otherwise no element could be added to list (e.g. full -> false) - bool push_front(const T& data) noexcept; + [[nodiscard]] bool push_front(const T& data) noexcept; /// @brief add element to the beginning of the list via move /// @param[in] data universal reference perfectly forwarded to client class /// @return successful insertion (true), otherwise no element could be added to list (e.g. full -> false) - bool push_front(T&& data) noexcept; + [[nodiscard]] bool push_front(T&& data) noexcept; /// @brief add element to the end of the list /// @param[in] data reference to data element /// @return successful insertion (true), otherwise no element could be added to list (e.g. full -> false) - bool push_back(const T& data) noexcept; + [[nodiscard]] bool push_back(const T& data) noexcept; /// @brief add element to the end of the list via move /// @param[in] data universal reference perfectly forwarded to client class /// @return successful insertion (true), otherwise no element could be added to list (e.g. full -> false) - bool push_back(T&& data) noexcept; + [[nodiscard]] bool push_back(T&& data) noexcept; /// @brief remove the first element from the begining of the list /// element destructor will be invoked diff --git a/iceoryx_hoofs/container/include/iox/vector.hpp b/iceoryx_hoofs/container/include/iox/vector.hpp index 494242ec2d..5b660db9e9 100644 --- a/iceoryx_hoofs/container/include/iox/vector.hpp +++ b/iceoryx_hoofs/container/include/iox/vector.hpp @@ -180,7 +180,7 @@ class vector final /// creates two new elements via move construction. The first one has a valid source but the second /// gets an already moved parameter. template - bool resize(const uint64_t count, const Targs&... args) noexcept; + [[nodiscard]] bool resize(const uint64_t count, const Targs&... args) noexcept; /// @brief forwards all arguments to the constructor of the contained element /// and performs a placement new at the provided position @@ -188,24 +188,24 @@ class vector final /// @param[in] args arguments which are used by the constructor of the newly created argument /// @return true if successful, false if position is greater than size or the vector is already full template - bool emplace(const uint64_t position, Targs&&... args) noexcept; + [[nodiscard]] bool emplace(const uint64_t position, Targs&&... args) noexcept; /// @brief forwards all arguments to the constructor of the contained element /// and performs a placement new at the end /// @param[in] args arguments which are used by the constructor of the newly created argument /// @return true if successful, false if the vector is already full template - bool emplace_back(Targs&&... args) noexcept; + [[nodiscard]] bool emplace_back(Targs&&... args) noexcept; /// @brief appends the given element at the end of the vector /// @param[in] value to append to the vector /// @return true if successful, false if vector already full - bool push_back(const T& value) noexcept; + [[nodiscard]] bool push_back(const T& value) noexcept; /// @brief appends the given element at the end of the vector /// @param[in] value to append to the vector /// @return true if successful, false if vector already full - bool push_back(T&& value) noexcept; + [[nodiscard]] bool push_back(T&& value) noexcept; /// @brief removes the last element of the vector; calling pop_back on an empty container does nothing /// @return true if the last element was removed. If the vector is empty it returns false.