CJCoding With Joseph
15free / daySign inCreate account

Lvalue and Rvalue Overloads of a Template

Write two overloads of a function template identify:

- identify(T& value) prints Lvalue and a newline - identify(T&& value) prints Rvalue and a newline

An lvalue is an expression that names a place you could assign to, such as a variable; an rvalue is a temporary result, such as a literal or the value of an addition. When both overloads could match, the T& version wins for lvalues, and the T&& version is the only match for rvalues. The tests start with int x = 5; and call identify with x, with 10, with x + 1, with ++x (pre-increment gives back the variable itself) and with x++ (post-increment gives back a temporary copy), then print x, so six lines are printed.

Do NOT write a main function.

Expected Output:

Lvalue
Rvalue
Rvalue
Lvalue
Rvalue
7

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Templates
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.