Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just cannot understand why would one want to use a forwarding reference instead of a const lvalue reference.

So why instead of this:

C++
template<typename T>
    void g(T&& x)
    {
        ...
    }
    
    template<typename T>
    void f(T&& x)
    {
        g(std::forward<T>(x));
    }


I could not use the following and get the same results performance wise (assuming I dont want to modify object x):
C++
template<typename T>
    void g(const T& x)
    {
        ...
    }
    
    template<typename T>
    void f(const T& x)
    {
        g(x);
    }


What I have tried:

This is a theoretical question
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900