Question Details

No question body available.

Tags

c++ templates

Answers (1)

Accepted Answer Available
Accepted Answer
March 12, 2026 Score: 5 Rep: 4,354 Quality: High Completeness: 80%

You're on the right track but forwarding reference is the way to go

template 
void foo(T&& a, U&& b)
    requires std::issamev &&
             std::issame_v
{
    bar(std::forward(a));
    bar(std::forward(b));
}

LIVE

Both argument are "forwarding reference" and can match either rvalue or lvalue. With std::forward, you guarantee that the original value-category is passed to bar

The default template arguments allow for calls like: foo(l,{{"A", "B"}}); where l is a StringList object (thanks to Jarod42).

The requires clause ensure that only StringList can be used.