I have the following operator<<()
overload for my class with C++17 folds:
template <typename... Args>
ostream& operator <<(Args&&... args)
{
//Currently:
return (m_osCout << ... << args);
//What I need:
IF ANY OF THE parameters in args "was" of type, say TSeek,
which can be a manipulator function etc, then AFTER finishing
with the parameter pack, I would like to do some further operation
, for instance, restore the state of m_osCount
}
Is it possible what I need as described above? Any partial responses to set some directions would be appreciated...
Despite I coined the question as if I was asking for an automated stream flag restorer, please note that I am after the general solution, not particularly restoring std::cout
or o/istream object restoration.
In practice my class is a kind of mathematical object that accepts custom-types as operator arguments, some of which requires ostream's manipulators-like functions but it is generally very very inconvenient to require user to supply some finalizing operands before starting a next such usage.
One idea that came to me was to return a different kind of temporary object of a new smart type whenever TSeek
was provided in args...
list, so that after the last argument is forwarded to it, it will be destructed automatically and this really is the time that I want to do my finalizing task!
Should I proceed like this or...?