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 711991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:47:53+00:00 2026-05-14T04:47:53+00:00

I ran across this article on copy ellision in C++ and I’ve seen comments

  • 0

I ran across this article on copy ellision in C++ and I’ve seen comments about it in the boost library. This is appealing, as I prefer my functions to look like

verylargereturntype DoSomething(...)

rather than

void DoSomething(..., verylargereturntype& retval)

So, I have two questions about this

  1. Google has virtually no documentation on this at all, how real is this?
  2. How can I check that this optimization is actually occuring? I assume it involves looking at the assembly, but lets just say that isn’t my strong suit. If anyone can give a very basic example as to what successful ellision looks like, that would be very useful

I won’t be using copy ellision just to prettify things, but if I can be guaranteed that it works, it sounds pretty useful.

  • 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-14T04:47:54+00:00Added an answer on May 14, 2026 at 4:47 am

    I think this is a very commonly applied optimization because:

    1. it’s not difficult for the compiler to do
    2. it can be a huge gain
    3. it’s an area of C++ that was a commonly critiqued before the optimization became common

    If you’re just curious, put a debug printf() in your copy constructor:

    class foo {
    public:
        foo(): x(0) {};
    
        foo(int x_) : x( x_) {};
    
        foo( foo const& other) : x( other.x) {
            printf( "copied a foo\n");
        };
    
        static foo foobar() {
            foo tmp( 2);
    
            return tmp;
        }
    
    
    private:
        int x;
    };
    
    
    
    int main()
    {
        foo myFoo;
    
        myFoo = foo::foobar();
    
        return 0;
    }
    

    Prints out “copied a foo” when I run an unoptimmized build, but nothing when I build optimized.

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

Sidebar

Related Questions

I recently ran across this great article by Chad Parry entitled DIY-DI or Do-It-Yourself
I ran across this pattern in the code of a library I'm using. It
I have been familiarizing myself with javascript closures and ran across this article http://blog.morrisjohns.com/javascript_closures_for_dummies.html
I just ran across this an Google App Engine article that uses that funny
Recently I ran across a blog article about using PHP scripts to redirect affiliate
I stumbled across this article and found it very interesting, so I ran some
I was just reading about Gems/Plugin development for Rails 3 and ran across this
Ran across this line of code: FormsAuth = formsAuth ?? new FormsAuthenticationWrapper(); What do
I ran across this situation this afternoon, so I thought I'd ask what you
I ran across this and was wondering if someone could explain why this works

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.