Commit c8ad790f authored by Adam Simpkins's avatar Adam Simpkins Committed by Dave Watson

fix Cursor's copy constructor

Summary:
The Cursor class didn't provide a copy constructor accepting a
"const Cursor&".  The existing constructor only accepted references to
non-const Cursor.

This updates the constructor to also accept "const Cursor&".  I also
made the template parameter checking more strict, so that it only
accepts other CursorBase classes.  This prevents the compiler from
thinking that a Cursor can be constructed from any other possible type
when performing overload resolution.

Test Plan: Ran all of the folly cursor tests.

Reviewed By: davejwatson@fb.com

FB internal diff: D1208428
parent 9f95e046
...@@ -199,12 +199,17 @@ class CursorBase { ...@@ -199,12 +199,17 @@ class CursorBase {
// Make all the templated classes friends for copy constructor. // Make all the templated classes friends for copy constructor.
template <class D, typename B> friend class CursorBase; template <class D, typename B> friend class CursorBase;
template <class T> /*
explicit CursorBase(const T& cursor) { * Copy constructor.
crtBuf_ = cursor.crtBuf_; *
offset_ = cursor.offset_; * This also allows constructing a CursorBase from other derived types.
buffer_ = cursor.buffer_; * For instance, this allows constructing a Cursor from an RWPrivateCursor.
} */
template <class OtherDerived, class OtherBuf>
explicit CursorBase(const CursorBase<OtherDerived, OtherBuf>& cursor)
: crtBuf_(cursor.crtBuf_),
offset_(cursor.offset_),
buffer_(cursor.buffer_) {}
// reset cursor to point to a new buffer. // reset cursor to point to a new buffer.
void reset(BufType* buf) { void reset(BufType* buf) {
...@@ -461,8 +466,8 @@ class Cursor : public detail::CursorBase<Cursor, const IOBuf> { ...@@ -461,8 +466,8 @@ class Cursor : public detail::CursorBase<Cursor, const IOBuf> {
explicit Cursor(const IOBuf* buf) explicit Cursor(const IOBuf* buf)
: detail::CursorBase<Cursor, const IOBuf>(buf) {} : detail::CursorBase<Cursor, const IOBuf>(buf) {}
template <class CursorType> template <class OtherDerived, class OtherBuf>
explicit Cursor(CursorType& cursor) explicit Cursor(const detail::CursorBase<OtherDerived, OtherBuf>& cursor)
: detail::CursorBase<Cursor, const IOBuf>(cursor) {} : detail::CursorBase<Cursor, const IOBuf>(cursor) {}
}; };
...@@ -481,8 +486,8 @@ class RWCursor ...@@ -481,8 +486,8 @@ class RWCursor
: detail::CursorBase<RWCursor<access>, IOBuf>(buf), : detail::CursorBase<RWCursor<access>, IOBuf>(buf),
maybeShared_(true) {} maybeShared_(true) {}
template <class CursorType> template <class OtherDerived, class OtherBuf>
explicit RWCursor(CursorType& cursor) explicit RWCursor(const detail::CursorBase<OtherDerived, OtherBuf>& cursor)
: detail::CursorBase<RWCursor<access>, IOBuf>(cursor), : detail::CursorBase<RWCursor<access>, IOBuf>(cursor),
maybeShared_(true) {} maybeShared_(true) {}
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment