Skip to content

Mark swap as noexcept#106

Open
Flamefire wants to merge 3 commits into
boostorg:developfrom
Flamefire:noexcept-swap
Open

Mark swap as noexcept#106
Flamefire wants to merge 3 commits into
boostorg:developfrom
Flamefire:noexcept-swap

Conversation

@Flamefire

Copy link
Copy Markdown
Contributor

All used operations are trivial or already noexcept so set the annotation.
This is recommended for swap implementations

@nigels-com

Copy link
Copy Markdown

std::swap(std::vector) is noexcept for C++17. But it's less clear for C++11 and C++14.

As a workaround, perhaps conditional compilation using BOOST_CXX_VERSION which is probably OK considering it's a header-only library?

#if BOOST_CXX_VERSION >= 201703L
// C++17 or later
#endif

@mclow

mclow commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

std::swap(std::vector) is noexcept for C++17. But it's less clear for C++11 and C++14.

std::swap(std::vector) is not marked as noexcept in C++11 or C++14.

In C++17, it depends on various allocator bits.

void swap(vector&)
    noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
    allocator_traits<Allocator>::is_always_equal::value);

Different implementations may have added noexcept at various times.

@Flamefire

Copy link
Copy Markdown
Contributor Author

You are right. I updated it to use the conditionals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants