Defined in header <cparse/Cursor.hh>
Cursor& operator=( Cursor const& other ); // (1)
Cursor& operator=( Cursor&& other ) = delete; // (2)
- Copy assignment. Copies filename, line, column, stored position and the shared pointer to the stream. Self-assignment (
c = c) is a safe no-op. - Move assignment is deleted — see
(constructor)Notes for the rationale.
Assignment does not seek the underlying stream. After a = b, a records b's position but the shared stream's tellg() is unchanged. To make the shared stream reflect the assigned position, call restore() or safeRestore() afterwards. This is the exact pattern Parser::restoreCursor() uses.
Parameters
| Parameter | Description |
|---|---|
other | The cursor to copy from. |
Return value
*this.
Exceptions
Does not throw. Not marked noexcept in the declaration but the body copies simple members and does not perform I/O.
Notes
The shared pointer means a = b after a and b were pointing at different files does the expected thing: a now points at b's file too, and b's file stays alive as long as a does. Files opened by overload 1 of the constructor are closed when the last Cursor referring to them is destroyed.
Example
#include <cparse/Cursor.hh>
#include <sstream>
int main()
{
auto ss = std::make_shared<std::istringstream>("0123456789");
fedem::parser::Cursor c("<memory>", ss);
c.get(); c.get(); c.get(); // now at position 3
fedem::parser::Cursor saved = c; // saved records position 3
c.get(); c.get(); // now at position 5
c = saved; // c records position 3 again...
c.restore(); // ...and now the stream is seeked back
}
See also
- Cursor::(constructor) — construction, including copy.
- Cursor::restore — apply the assigned position to the underlying stream.

