#include <iostream>
#include <type_traits>
template<typename T>
void foo(T) { std::cout << __PRETTY_FUNCTION__ << std::endl; }
template<typename T>
struct pair {
pair(T v)
:key("")
,val(v)
{}
pair(const char *k, T v)
:key(k)
,val(v)
{}
const char *key;
T val;
};
template<typename T>
auto make_pair(const char *key, T &&val) {
using R = typename std::conditional<
std::is_rvalue_reference<decltype(val)>::value || std::is_const<decltype(val)>::value
,const T&
,T&
>::type;
return pair<R>{key, val};
}
int main() {
int i=0;
auto p0 = make_pair("i", 33);
foo(p0);
auto p1 = make_pair("i", i);
foo(p1);
foo(make_pair("i", 33));
foo(make_pair("i", i));
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgp2b2lkIGZvbyhUKSB7IHN0ZDo6Y291dCA8PCBfX1BSRVRUWV9GVU5DVElPTl9fIDw8IHN0ZDo6ZW5kbDsgfQoKdGVtcGxhdGU8dHlwZW5hbWUgVD4Kc3RydWN0IHBhaXIgewoJcGFpcihUIHYpCgkJOmtleSgiIikKCQksdmFsKHYpCgl7fQoJcGFpcihjb25zdCBjaGFyICprLCBUIHYpCgkJOmtleShrKQoJCSx2YWwodikKCXt9CgoJY29uc3QgY2hhciAqa2V5OwoJVCB2YWw7Cn07Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgphdXRvIG1ha2VfcGFpcihjb25zdCBjaGFyICprZXksIFQgJiZ2YWwpIHsKCQl1c2luZyBSID0gdHlwZW5hbWUgc3RkOjpjb25kaXRpb25hbDwKCQkJIHN0ZDo6aXNfcnZhbHVlX3JlZmVyZW5jZTxkZWNsdHlwZSh2YWwpPjo6dmFsdWUgfHwgc3RkOjppc19jb25zdDxkZWNsdHlwZSh2YWwpPjo6dmFsdWUKCQkJLGNvbnN0IFQmCgkJCSxUJgoJCT46OnR5cGU7CglyZXR1cm4gcGFpcjxSPntrZXksIHZhbH07Cn0KCmludCBtYWluKCkgewoJaW50IGk9MDsKCWF1dG8gcDAgPSBtYWtlX3BhaXIoImkiLCAzMyk7Cglmb28ocDApOwoJYXV0byBwMSA9IG1ha2VfcGFpcigiaSIsIGkpOwoJZm9vKHAxKTsKCglmb28obWFrZV9wYWlyKCJpIiwgMzMpKTsKCWZvbyhtYWtlX3BhaXIoImkiLCBpKSk7Cn0K