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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:31:34+00:00 2026-06-17T16:31:34+00:00

The title says it all. The first case f(const X&) is the good old

  • 0

The title says it all.

The first case f(const X&) is the good old fashioned const reference parameter.

However, when taking a mutable reference parameter, why not always use X&&? This way client code can use temps or regular lvalues, rather than f() dictating usage.

EDIT: Sloppiness on my part, sorry. I meant, given fc(const X&) and fm(X&&), do we need fm(X&)?

EDIT: Example: I use stateless decorators to pass as parameters:

class Base64Writer: public Writer {
public:
  Base64Writer(Writer& w): w_(w) {}
private:
  virtual void doWrite() override;
  Writer& w_;
}

void func(Writer&& w) { w.doWrite(); }

// to be called as
Writer wr = ...;
func(Base64Writer(wr));
  • 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-06-17T16:31:35+00:00Added an answer on June 17, 2026 at 4:31 pm
    • If you mean to ask : is it logical to have all three overloads at the same time?

      In most cases, it would be a bad idea. as the semantic of the overloaded functions contradict each other. One promises that it will not modify the argument, the other doesn’t make any such promise (it tacitly says it will modify the argument!). The user of such overloaded functions will be confused that differs only by const.

      It makes sense to have these overloads at the same time:

      void process(std::vector<int> const&);
      void process(std::vector<int> &&);
      

      But a third one, in addition to the above two, doesn’t make much sense to me:

      void process(std::vector<int> &); //contradicts the first overload
      

      It only adds confusion and makes code harder to read. If you want this semantic, choose a different name for the function!

    • If you mean to ask : which one should you have (though not necessarily all at the same time)?

      I would say, it depends on the semantic. If the parameter behaves as input and/or output parameter, then f(X&) makes sense. If the parameter is only input parameter, then f(X const&) makes sense, in this case you can additionally define f(X&&) also, to gain performance advantage!

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

Sidebar

Related Questions

The title prettymuch says it all. The first picture below is a screenshot when
Title says all. Sample code: ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object>
Title kinda says it all. The usual SOS command !bpmd doesn't do a lot
Title pretty much says it all. The web.config, unchanged from how VS2008SP1 generated it,
The title pretty much says it all, but basically I have a main parent
The title pretty much says it all, but in SQL Server 2005 Management Studio,
As the title says, I'm trying to change the ID of all elements with
I just want what my title says.I have already read all the previous similar
Title more or less says it all. In response to a touchesBegan event, my
The title more or less says it all. I create a widget, add it

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.