mirror of
https://github.com/nlohmann/json.git
synced 2026-09-02 14:37:17 +00:00
Declare no_key_compare_map's accessors noexcept
The GCC C++20 job builds with -Wnoexcept and -Werror, and the standard
library takes noexcept(c.begin()) and noexcept(c.end()) in ranges_base.h and
range_access.h. Forwarding to std::map without repeating its noexcept made
those expressions false, which the warning reports as an error:
error: noexcept-expression evaluates to 'false' because of a call to
no_key_compare_map<...>::begin() [-Werror=noexcept]
note: but ... does not throw; perhaps it should be declared 'noexcept'
Give the accessors the exception specification of what they forward to.
std::map declares begin, end, cbegin, cend, empty, size, max_size, and clear
noexcept, so the wrapper does too. swap is left alone: std::map's is only
conditionally noexcept, and nothing asks for it.
void_erase_map is unaffected because it still derives from std::map and
inherits accessors that already carry the specification.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018hxZxz8svM54c6ATEvXp5E
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
co-authored by
Claude Opus 5
parent
b38c4cc937
commit
207db0f124
@@ -59,44 +59,44 @@ class no_key_compare_map
|
||||
template<class InputIt>
|
||||
no_key_compare_map(InputIt first, InputIt last) : data(first, last) {}
|
||||
|
||||
iterator begin()
|
||||
iterator begin() noexcept
|
||||
{
|
||||
return data.begin();
|
||||
}
|
||||
iterator end()
|
||||
iterator end() noexcept
|
||||
{
|
||||
return data.end();
|
||||
}
|
||||
const_iterator begin() const
|
||||
const_iterator begin() const noexcept
|
||||
{
|
||||
return data.begin();
|
||||
}
|
||||
const_iterator end() const
|
||||
const_iterator end() const noexcept
|
||||
{
|
||||
return data.end();
|
||||
}
|
||||
const_iterator cbegin() const
|
||||
const_iterator cbegin() const noexcept
|
||||
{
|
||||
return data.cbegin();
|
||||
}
|
||||
const_iterator cend() const
|
||||
const_iterator cend() const noexcept
|
||||
{
|
||||
return data.cend();
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
bool empty() const noexcept
|
||||
{
|
||||
return data.empty();
|
||||
}
|
||||
size_type size() const
|
||||
size_type size() const noexcept
|
||||
{
|
||||
return data.size();
|
||||
}
|
||||
size_type max_size() const
|
||||
size_type max_size() const noexcept
|
||||
{
|
||||
return data.max_size();
|
||||
}
|
||||
void clear()
|
||||
void clear() noexcept
|
||||
{
|
||||
data.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user