Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6474721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:37:16+00:00 2026-05-25T06:37:16+00:00

The noexcept specification on move-constructors are known to have performance implications in C++0x. For

  • 0

The noexcept specification on move-constructors are known to have performance implications in C++0x. For example, std::vector<T>::resize, std::vector<T>::reserve may use a non-throwing move-constructor of T if it can be proven to not throw. The noexcept opeator is the way to check that property at compile-time. If noexcept says that T’s move-ctor does not throw, T objects will be moved instead of copied most likely achieving higher performance.

My question is about member swap or namespace-level swap for a user-defined class T. C++0x spec spends some effort in exporting noexcept specifications of std::pair, std::tuple, std::array:swap possibly indicating that user-defined classes should try to use the same principle. For instance, std::pair::swap is declared as equivalent to:

void std::pair::swap(pair& p) noexcept(noexcept(swap(first, p.first)) && noexcept(swap(second, p.second));

It basically says that pair’s swap will throw if either swapping of first or second member throws. Swap of first, second possibly have their own noexcept specifications in terms of their members.

Finally the question: Are there generic algorithms out there (in stl or otherwise) that depending upon the noexcept specification of swap do different things? Moreover, is there a performance implication of that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:37:16+00:00Added an answer on May 25, 2026 at 6:37 am

    In addition to code that specifically behaves differently when something is noexcept (such as std::vector), declaring a function noexcept can allow the compiler to do its own optimizations. At the very least the compiler doesn’t have to keep track of certain things that are involved in exception handling, which might free up registers or execute less instructions among other things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this example code: explicit MyClass(std::wstring text) noexcept; Is the use of noexcept here
I recently started to add the new noexcept specification to move constructors/assignments wherever possible.
I read about concern that the overly use of noexcept may hinder a testable
I am curious about the rationale behind noexcept in the C++0x FCD . throw(X)
§20.2.4 [declval] template <class T> typename add_rvalue_reference<T>::type declval() noexcept; // as unevaluated operand Why
When implementing the non-throwing swap idiom, should I use throw() ? namespace A {
This question is a dual of Constructor with by-value parameter & noexcept . That
I am using DB2 in this case, but I'm figuring this has a generic
I'm using a memory pool class which reuses allocated memory addresses and a custom
.Net Compact Framework Scenario: User is on a screen. Device can't finds a printer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.