diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-07-07 19:09:55 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2018-03-13 17:04:31 -0700 |
commit | 172f5fa738d419efda99542e2ad2a0f4db5be580 (patch) | |
tree | 49cf2358dac3b441f03f39fd7329c796ebfe474c /src/streams.h | |
parent | 2761bca99753951e1ad8bf51e3fce8fd309b4612 (diff) |
Support deserializing into temporaries
Currently, the READWRITE macro cannot be passed any non-const temporaries, as
the SerReadWrite function only accepts lvalue references.
Deserializing into a temporary is very common, however. See for example
things like 's >> VARINT(n)'. The VARINT macro produces a temporary wrapper
that holds a reference to n.
Fix this by accepting non-const rvalue references instead of lvalue references.
We don't propagate the rvalue-ness down, as there are no useful optimizations
that only apply to temporaries.
Then use this new functionality to get rid of many (but not all) uses of the
'REF' macro (which casts away constness).
Diffstat (limited to 'src/streams.h')
-rw-r--r-- | src/streams.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/streams.h b/src/streams.h index 9f86c4a163..6ba4f103da 100644 --- a/src/streams.h +++ b/src/streams.h @@ -42,7 +42,7 @@ public: } template<typename T> - OverrideStream<Stream>& operator>>(T& obj) + OverrideStream<Stream>& operator>>(T&& obj) { // Unserialize from this stream ::Unserialize(*this, obj); @@ -399,7 +399,7 @@ public: } template<typename T> - CDataStream& operator>>(T& obj) + CDataStream& operator>>(T&& obj) { // Unserialize from this stream ::Unserialize(*this, obj); @@ -543,7 +543,7 @@ public: } template<typename T> - CAutoFile& operator>>(T& obj) + CAutoFile& operator>>(T&& obj) { // Unserialize from this stream if (!file) @@ -686,7 +686,7 @@ public: } template<typename T> - CBufferedFile& operator>>(T& obj) { + CBufferedFile& operator>>(T&& obj) { // Unserialize from this stream ::Unserialize(*this, obj); return (*this); |