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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:39:02+00:00 2026-05-28T02:39:02+00:00

template<class U> void f( U && v) { std::cout << typeid(v).name() << \n; //’int’

  • 0
template<class U>
void f( U && v)
{     
    std::cout << typeid(v).name() << "\n"; //'int' in both cases

    if( boost::is_same<int&&,U>::value )
    {
        std::cout << "reach here\n"; //only with f<int&&>(int(1));
    }
}


int main()
{    
    f(int(1));

    f<int&&>(int(1));

    std::cin.ignore();
}

Why v parameter is interpreted as int when I don’t explicitly use f<int&&>?
What is the difference ? (Compiled with MVS2010)

My guess is that First is passed as a rvalue and second as a rvalue reference and both bound correctly into a rvalue reference, am I right ?

Thanks.

  • 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-28T02:39:03+00:00Added an answer on May 28, 2026 at 2:39 am

    No, not really. An rvalue reference is never deduced. The notion U&& with U being a deducible template parameter is used to indicate that U should be deduced such that the rvalue-ness of the argument is retained:

    • when passing an rvalue of type X the type of U becomes X.
    • when passing a cv qualified lvalue of type X then U becomes the type X cv&.

    The more interesting question is what happened to the rvalue references explicitly specified in the second call because there is no deduction going on because in this case the two rvalue references are collapsed into just one.

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

Sidebar

Related Questions

In code: template<class T,int row, int col> void invert(T (&a)[row][col]) { T* columns =
#include<iostream> template<class T> struct Foo { T v_; Foo(T&& v):v_(std::forward<T>(v)) { std::cout << building
template <class T> void BT<T>::inOrder(void (*inOrderPtr)(T&)) { inOrderPtr(inOrder(this->root)); } template <class T> void BT<T>::inOrder(Node<T>*
When compiling : #include <vector> template<class T> class foo { void bar() { std::vector<T>
class IShaderParam{ public: std::string name_value; }; template<class TParam> class TShaderParam:public IShaderParam{ public: void (TShaderParam::*send_to_shader)(
#include <iostream> using namespace std; template<class T> void toBinary(T num) { char * numi
Consider a template class like: template<typename ReturnType, ReturnType Fn()> class Proxy { void run()
check this out: template <class T> class Test: public T { public: void TestFunc()
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
Let's assume we have a template function foo: template<class T> void foo(T arg) {

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.