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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:20:09+00:00 2026-05-27T06:20:09+00:00

Is there a modification to the interface that can get the second call to

  • 0

Is there a modification to the interface that can get the second call to work?

Or should I leave things as is?

I suspect the extra construction in the first case was designed that way on purpose so it is clear that ownership is being transferred.

#include <memory>

struct Bar { };
typedef std::unique_ptr<Bar> UPBar;

void foo1( UPBar p ) {  }
void foo2( UPBar p ) { foo1( move( p )); }
void foo3( UPBar p ) { foo2( move( p )); }
void foo4( UPBar p ) { foo3( move( p )); }

int main(int argc, char** argv)
{
    UPBar p( new Bar );
    foo4( move( p ));  // ok, but requires an extra construction vs line below
    foo4( new Bar );   // fails: any modification to get this to work?

    return 0;
}

Second Question: If I change all the parameters passed to RValue-References (&&), is there any disadvantage in doing so? In fact, should I ensure that all my std::unique_ptr<> parameters are passed by RValue-References?

  • 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-27T06:20:10+00:00Added an answer on May 27, 2026 at 6:20 am

    You can construct the unique_ptr as a temporary:

    foo4( UPBar( new Bar ));
    

    You can also write a make_unique function template, similar to the make_shared that exists for shared_ptr:

    template <typename T, typename... Args>
    std::unique_ptr<T> make_unique(Args&&... args) {
        return std::unique_ptr<T>(new T(std::forward<T>(args)...));
    }
    
    foo4( make_unique<Bar>() );
    // other constructors are also callable:
    foo4( make_unique<Bar>(x, y, z) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use numpy for numerical linear algebra. I suspect that I can get much
Wondering if there's any jquery library/plugin that can easily perform the following. At main
Is there any way to get a table's last modification datetime on Sql Server
If there are extensive modifications made to search.aspx in SPS 2003, will they get
I am making modifications to elements on UI. There is no (extra) thread or
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are two popular closure styles in javascript. The first I call anonymous constructor
There are a few ways to get class-like behavior in javascript, the most common
Dealing with go's funcs I discovered that one can't force the compiler to control
I'm working on an application that uses Sudzc to interface with a SOAP web-service.

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.