From 3d952d3c0f712743f39f7d9627186e762c120183 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 23 Feb 2022 14:26:28 -0800 Subject: [PATCH 1/2] Add missing `[[nodiscard]]` qualifiers as outlined by C++20 --- include/boost/unordered/unordered_map.hpp | 15 ++++++++++++--- include/boost/unordered/unordered_set.hpp | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index a7815d87..0341d229 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -210,7 +210,10 @@ namespace boost { // size and capacity - bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; } + BOOST_ATTRIBUTE_NODISCARD bool empty() const BOOST_NOEXCEPT + { + return table_.size_ == 0; + } size_type size() const BOOST_NOEXCEPT { return table_.size_; } @@ -1177,7 +1180,10 @@ namespace boost { // size and capacity - bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; } + BOOST_ATTRIBUTE_NODISCARD bool empty() const BOOST_NOEXCEPT + { + return table_.size_ == 0; + } size_type size() const BOOST_NOEXCEPT { return table_.size_; } @@ -2705,7 +2711,10 @@ namespace boost { bool operator!() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; } - bool empty() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; } + BOOST_ATTRIBUTE_NODISCARD bool empty() const BOOST_NOEXCEPT + { + return ptr_ ? 0 : 1; + } void swap(node_handle_map& n) BOOST_NOEXCEPT_IF( value_allocator_traits::propagate_on_container_swap::value || diff --git a/include/boost/unordered/unordered_set.hpp b/include/boost/unordered/unordered_set.hpp index 57133eda..d7e0f99c 100644 --- a/include/boost/unordered/unordered_set.hpp +++ b/include/boost/unordered/unordered_set.hpp @@ -208,7 +208,10 @@ namespace boost { // size and capacity - bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; } + BOOST_ATTRIBUTE_NODISCARD bool empty() const BOOST_NOEXCEPT + { + return table_.size_ == 0; + } size_type size() const BOOST_NOEXCEPT { return table_.size_; } @@ -835,7 +838,10 @@ namespace boost { // size and capacity - bool empty() const BOOST_NOEXCEPT { return table_.size_ == 0; } + BOOST_ATTRIBUTE_NODISCARD bool empty() const BOOST_NOEXCEPT + { + return table_.size_ == 0; + } size_type size() const BOOST_NOEXCEPT { return table_.size_; } @@ -2169,7 +2175,10 @@ namespace boost { bool operator!() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; } - bool empty() const BOOST_NOEXCEPT { return ptr_ ? 0 : 1; } + BOOST_ATTRIBUTE_NODISCARD bool empty() const BOOST_NOEXCEPT + { + return ptr_ ? 0 : 1; + } void swap(node_handle_set& n) BOOST_NOEXCEPT_IF( value_allocator_traits::propagate_on_container_swap::value || From b57ac0472820148679c0e3f7a42d43fbea152f21 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 23 Feb 2022 14:36:04 -0800 Subject: [PATCH 2/2] Update reference docs to include `[[nodiscard]]` annotations --- doc/unordered/unordered_map.adoc | 4 ++-- doc/unordered/unordered_multimap.adoc | 4 ++-- doc/unordered/unordered_multiset.adoc | 4 ++-- doc/unordered/unordered_set.adoc | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/unordered/unordered_map.adoc b/doc/unordered/unordered_map.adoc index e8737402..f4f9f9ec 100644 --- a/doc/unordered/unordered_map.adoc +++ b/doc/unordered/unordered_map.adoc @@ -87,7 +87,7 @@ namespace boost { const_iterator xref:#unordered_map_cend[cend]() const noexcept; // capacity - bool xref:#unordered_map_empty[empty]() const noexcept; + ++[[nodiscard]]++ bool xref:#unordered_map_empty[empty]() const noexcept; size_type xref:#unordered_map_size[size]() const noexcept; size_type xref:#unordered_map_max_size[max_size]() const noexcept; @@ -629,7 +629,7 @@ Returns:;; A `const_iterator` which refers to the past-the-end value for the con ==== empty ```c++ -bool empty() const noexcept; +[[nodiscard]] bool empty() const noexcept; ``` [horizontal] diff --git a/doc/unordered/unordered_multimap.adoc b/doc/unordered/unordered_multimap.adoc index 8eb8fb30..a621fe4e 100644 --- a/doc/unordered/unordered_multimap.adoc +++ b/doc/unordered/unordered_multimap.adoc @@ -88,7 +88,7 @@ namespace boost { const_iterator xref:#unordered_multimap_cend[cend]() const noexcept; // capacity - bool xref:#unordered_multimap_empty[empty]() const noexcept; + ++[[nodiscard]]++ bool xref:#unordered_multimap_empty[empty]() const noexcept; size_type xref:#unordered_multimap_size[size]() const noexcept; size_type xref:#unordered_multimap_max_size[max_size]() const noexcept; @@ -612,7 +612,7 @@ Returns:;; A `const_iterator` which refers to the past-the-end value for the con ==== empty ```c++ -bool empty() const noexcept; +[[nodiscard]] bool empty() const noexcept; ``` [horizontal] diff --git a/doc/unordered/unordered_multiset.adoc b/doc/unordered/unordered_multiset.adoc index 122a1b27..f806f9ee 100644 --- a/doc/unordered/unordered_multiset.adoc +++ b/doc/unordered/unordered_multiset.adoc @@ -84,7 +84,7 @@ namespace boost { const_iterator xref:#unordered_multiset_cend[cend]() const noexcept; // capacity - bool xref:#unordered_multiset_empty[empty]() const noexcept; + ++[[nodiscard]]++ bool xref:#unordered_multiset_empty[empty]() const noexcept; size_type xref:#unordered_multiset_size[size]() const noexcept; size_type xref:#unordered_multiset_max_size[max_size]() const noexcept; @@ -607,7 +607,7 @@ Returns:;; A `const_iterator` which refers to the past-the-end value for the con ==== empty ```c++ -bool empty() const noexcept; +[[nodiscard]] bool empty() const noexcept; ``` [horizontal] diff --git a/doc/unordered/unordered_set.adoc b/doc/unordered/unordered_set.adoc index e976b97a..426ddd9a 100644 --- a/doc/unordered/unordered_set.adoc +++ b/doc/unordered/unordered_set.adoc @@ -85,7 +85,7 @@ namespace boost { const_iterator xref:#unordered_set_cend[cend]() const noexcept; // capacity - bool xref:#unordered_set_empty[empty]() const noexcept; + ++[[nodiscard]]++ bool xref:#unordered_set_empty[empty]() const noexcept; size_type xref:#unordered_set_size[size]() const noexcept; size_type xref:#unordered_set_max_size[max_size]() const noexcept; @@ -618,7 +618,7 @@ Returns:;; A `const_iterator` which refers to the past-the-end value for the con ==== empty ```c++ -bool empty() const noexcept; +[[nodiscard]] bool empty() const noexcept; ``` [horizontal]