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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:59:06+00:00 2026-05-16T13:59:06+00:00

If you have this function template<typename T> f(T&); And then try to call it

  • 0

If you have this function

template<typename T> f(T&);

And then try to call it with, let’s say an rvalue like

f(1);

Why isn’t T just be deduced to be const int, making the argument a const int& and thus bindable to an rvalue?

  • 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-16T13:59:07+00:00Added an answer on May 16, 2026 at 1:59 pm

    This is mentioned as a potential solution in the document I linked in the recent C++0x forwarding question.

    It would work fairly well, but it breaks existing code. Consider (straight from the document):

    template<class A1> void f(A1 & a1)
    {
        std::cout << 1 << std::endl;
    }
    
    void f(long const &)
    {
        std::cout << 2 << std::endl;
    }
    
    int main()
    {
        f(5);              // prints 2 under the current rules, 1 after the change
        int const n(5);
        f(n);              // 1 in both cases
    }
    

    Or

    // helper function in a header
    
    template<class T> void something(T & t) // #1
    {
        t.something();
    }
    
    // source
    
    #include <vector>
    
    void something(bool) // #2
    {
    }
    
    int main()
    {
        std::vector<bool> v(5);
    
        // resolves to #2 under the current rules, #1 after the change
        something(v[0]);
    }
    

    This also fails to forward the value category (lvalue or rvalue), which isn’t much of a problem in C++03. But since this fix could only be done during C++0x, we’d effectively shutting ourselves out from rvalue references when forwarding (a bad thing). We should strive for a better solution.

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

Sidebar

Related Questions

Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
Suppose I have a function which looks like this: template <class In, class In2>
I have this template function: template <class P> double Determinant(const P & a, const
I have this function header: template < bool src_alpha, int sbpp, int dbpp, typename
Say I have this: template<typename T, int X> class foo { public: void set(const
See,I have this code: template<typename T=int>struct color { T red, green, blue; color(T r,
I have a template looking like this: struct add_node_value_visitor : boost::static_visitor<> { add_node_value_visitor(){} template
I have a class template Foo<T> . I'd like to implement a non-member function
I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');
I have this function: public bool IsValidProduct(int productTypeId) { bool isValid = false; if

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.