#include #include #include struct Box { int value; }; decltype(auto) copy_value(Box& b) { return b.value; } decltype(auto) borrow_value(Box& b) { return (b.value); } int main() { const int source = 3; auto copy = source; auto& ref = source; static_assert(std::is_same::value, "value"); static_assert(std::is_same::value, "borrow"); Box b{4}; static_assert(std::is_same::value, "copy return"); static_assert(std::is_same::value, "reference return"); auto detached = copy_value(b); borrow_value(b) = 9; assert(detached == 4 && b.value == 9); std::cout << detached << ' ' << b.value << '\n'; }