Closed redboltz closed 6 years ago
I noticed that my code has some mistakes.
std::ostream&
version should be https://wandbox.org/permlink/XYopHIUqt44OCYDO
It outputs compilation errors.
std::reference_wrapper<std::ostream>>
version should be https://wandbox.org/permlink/HjbLE8WkLgGEK6Kd
It outputs expected results.
I wrote lifetime trace code and it works as I expected. https://wandbox.org/permlink/YnSyXpchg8k2nT6V
So I can use the following pattern to return the reference that is passed as the argument.
T& mem_func(T& t) const {
return te::call<std::reference_wrapper<T>>(
[](auto const& self, auto& t) {
return std::ref(self.mem_func(t));
},
*this,
t);
}
I wrote the following example based on README.md.
It works fine. https://wandbox.org/permlink/qkfHT6Zg3Mk9qbCS
I tried to modify
to
Then I got errors.
https://wandbox.org/permlink/YbEudxsv1oVSgmgC
It seems that
te
tries to copystd::ostream
.If I changed the return value type from
std::ostream&
tostd::ostream*
, then the code works as I expected.https://wandbox.org/permlink/BexYhlEqmbgam6AV
I noticed that in this case,
std::reference_wrapper
might help. I updated the reference version as follows:https://wandbox.org/permlink/wJ5HBSmk2eGiMMZ5
I think that
std::reference_wrapper
version is elegant.Is this a right way to return reference from
te::call
?