#include <iostream>
#include <functional>
#include <type_traits>
class testClass
{
public:
testClass() = default;
testClass( const testClass & other ) { std::cout << "COPY C" << std::endl; }
testClass & operator=(const testClass & other ) { std::cout << "COPY A" << std::endl; }
};
template< class T>
void testFunc(T && t)
{ [test = std::conditional_t<
std::is_lvalue_reference<T>::value,
std::reference_wrapper<std::remove_reference_t<T>>,
T>{std::forward<T>(t)}]{}(); }
int main()
{
testClass x;
std::cout << "PLEASE NO COPY" << std::endl;
testFunc(x);
std::cout << "DONE" << std::endl;
std::cout << "COPY HERE" << std::endl;
testFunc(testClass());
std::cout << "DONE" << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKI2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDx0eXBlX3RyYWl0cz4KCmNsYXNzIHRlc3RDbGFzcwp7CnB1YmxpYzoKICAgdGVzdENsYXNzKCkgPSBkZWZhdWx0OwogICB0ZXN0Q2xhc3MoIGNvbnN0IHRlc3RDbGFzcyAmIG90aGVyICkgeyBzdGQ6OmNvdXQgPDwgIkNPUFkgQyIgPDwgc3RkOjplbmRsOyB9CiAgIHRlc3RDbGFzcyAmIG9wZXJhdG9yPShjb25zdCB0ZXN0Q2xhc3MgJiBvdGhlciApIHsgc3RkOjpjb3V0IDw8ICJDT1BZIEEiIDw8IHN0ZDo6ZW5kbDsgfQp9OwoKdGVtcGxhdGU8IGNsYXNzIFQ+CnZvaWQgdGVzdEZ1bmMoVCAmJiB0KQogICB7IFt0ZXN0ID0gc3RkOjpjb25kaXRpb25hbF90PAogICAgICAgICAgICAgICAgIHN0ZDo6aXNfbHZhbHVlX3JlZmVyZW5jZTxUPjo6dmFsdWUsCiAgICAgICAgICAgICAgICAgc3RkOjpyZWZlcmVuY2Vfd3JhcHBlcjxzdGQ6OnJlbW92ZV9yZWZlcmVuY2VfdDxUPj4sCiAgICAgICAgICAgICAgICAgVD57c3RkOjpmb3J3YXJkPFQ+KHQpfV17fSgpOyB9CgppbnQgbWF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