Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't see any reason for them to be implementation dependent.</p> <p>This is comething that I use, for the actual manipulator, create a function that returns an instance of the following helper. If you need to store the data, just store it inside the helper, some global variable, singleton, etc...</p> <pre><code> /// One argument manipulators helper template &lt; typename ParType &gt; class OneArgManip { ParType par; std::ostream&amp; (*impl)(std::ostream&amp;, const ParType&amp;); public: OneArgManip(std::ostream&amp; (*code)(std::ostream&amp;, const ParType&amp;), ParType p) : par(p), impl(code) {} // calls the implementation void operator()(std::ostream&amp; stream) const { impl(stream,par); } // a wrapper that allows us to use the manipulator directly friend std::ostream&amp; operator &lt;&lt; (std::ostream&amp; stream, const OneArgManip&lt;ParType&gt;&amp; manip) { manip(stream); return stream; } }; </code></pre> <p>Example of a manipulator based on this:</p> <pre><code>OneArgManip&lt;unsigned&gt; cursorMoveUp(unsigned c) { return OneArgManip&lt;unsigned&gt;(cursorMoveUpI,c); } std::ostream&amp; cursorMoveUpI(std::ostream&amp; stream, const unsigned&amp; c) { stream &lt;&lt; "\033[" &lt;&lt; c &lt;&lt; "A"; return stream; } </code></pre> <p>For some explanation:</p> <ol> <li>u use the manipulator, that returns a new instance of the helper bound to an implementation of the helper</li> <li>stream tries to process the helper, that invokes the <code>&lt;&lt;</code> overload on the helper</li> <li>that invokes the <code>()</code> operator on the helper</li> <li>that invokes the real implementation of the helper with the parameter passed from the original manipulator call</li> </ol> <p>If you want I can post 2 param and 3 param helpers as well. The principle is the same though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload