Defined in header <cparse/Cursor.hh>
bool isValid() const noexcept;
Returns true if the underlying stream pointer is non-null, the stream is not eof(), and the stream is not bad(). Returns false otherwise.
Note that this does not check fail() — a stream that has failed a read (say, extracting an integer from letters) is still considered "valid" by this check as long as it can be recovered.
Parameters
None.
Return value
true if the cursor has a usable stream; false otherwise.
Exceptions
noexcept. Pointer and boolean checks only.
Notes
Grammars typically use isValid() as the top-of-loop condition when consuming input character by character:
while (getCursor().isValid())
{
auto ch = getCursor().safeGet();
if (ch == '\032') break; // safe variant returned EOF sentinel
process(ch);
}
The double check (isValid() and ch == '\032') is deliberate: isValid() becomes false only after the EOF-triggering read has happened, so the safe-variant's sentinel check catches the case between the last real character and the loop test.
Example
See the class synopsis example for a representative usage.
See also
- Cursor::safeGet — the read that pairs with an
isValidloop. - Cursor::safePeek — look-ahead variant.

