I have the following code:
#include
#include
template
auto callback(T&& func) ->decltype(fu
std::bind() is designed for value semantics (as R. Martinho Fernandes nicely explains in his answer), and does create copies internally. What you need/want is std::ref:
callback(std::bind(test, std::ref(t)));
// ^^^^^^^^^^^
std::ref returns an std::reference_wrapper<> object that wraps a reference to your original argument. This way, the reference_wrapper object around t gets copied, and not t itself.
This allows you to choose between value semantics (assumed by default) and reference semantics (which requires your explicit intervention).
Here is a live example.