tag:blogger.com,1999:blog-33334170170435224512026-01-23T00:42:30.973-08:00Inspired Codejrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-3333417017043522451.post-49831843962452206122021-05-08T17:52:00.001-07:002021-05-08T17:52:26.343-07:00 Moore's Law<p>I think many people interested in technology are familiar with <a href="https://en.wikipedia.org/wiki/Moore%27s_law" target="_blank">Moore's law</a>.</p><p>It's basically the observation that the number of transistors that can be fitted on chips doubles about every two years. This density of transisters per square millimeter is related to the process size, for example the latest generation of high end CPUs and GPUs are using 7 nanometer technology, with 5 nm in development.</p><p>The assumption or perhaps implied implication of Moore's Law is that you would expect that this means the price per transistor would be proportionally getting less. For every square millimeter of silicon wafer you have, you are over time able to make more and more transistors on there. It was as if Moore's Law was a proxy for the price per transistor.</p><p>You could be forgiven for thinking that it means that year after year for a given amount of money you can buy an ever more powerful computer. I previously thought that was what it meant in practice.</p><p>However shinking the process size has slowly been getting more and more expensive to do. This has been the case since 28 nm. Since then the price per transistor has been going up for smaller and smaller process sizes. Let that sink in for a moment, the price per transistor has been going up, not down.</p><p>So for a 7nm chip, with more transistors, and with a higher price per transistor, it is no wonder newer CPUs and GPUs are costing more. And add to that some inflation happening in the economy as well as some supply chain issues due to COVID, it's no wonder that various products are seeing some pretty high prices at the moment.</p><p>Also it's worth trying to appreciate the supply side. One of the main suppliers is TSMC, based in Taiwan. There are fewer and fewer fabrication facilities for the smaller and smaller process sizes as the required investment increases. There are constraints on finding large enough areas of industrial land with ready access to the large amounts of water and electricity, this requires years of planning with consultation with government to have these facilities.</p><p>With fewer places able to make the newer process size chips, obviously supply is an issue. There is more fagility with fewer suppliers. <a href="https://en.wikipedia.org/wiki/Antifragility">https://en.wikipedia.org/wiki/Antifragility</a> This makes the production sensitive to any stressors/failures leading to high volitility. And there have been stressors in the form of COVID and also crypto mining demand.</p><p>Intel announced recently that they will create a new plant in Arizona:</p><p><a href="https://newsroom.intel.com/wp-content/uploads/sites/11/2021/03/Intel-Arizona-manufacturing-15073363.pdf">https://newsroom.intel.com/wp-content/uploads/sites/11/2021/03/Intel-Arizona-manufacturing-15073363.pdf</a></p><p>It will probably be several years until it will be able to produce anything, but they did this with consultation and cooperation from the Arizona government and also the Biden administration. It's a $20 billion dollar investment that will help provide production security for the US and US companies like Intel, Nvidia and Apple.</p><p><br /></p>jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-38147449250980896442019-12-05T05:00:00.012-08:002020-12-18T04:09:51.227-08:00Ranges, views, pipesSomething I've always liked about UNIX systems is the idea of a collection of tools which can be combined together using pipes to do all kinds of interesting things relatively easily.<br />
<br />
For example:<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"> cat wordlist.txt | sort | uniq | wc -l</span><br />
<br />
This takes a list of words on each line from the input file, pipes it through a command to sort the input and then filters out any repeated lines and finally counts the number of lines, which will tell you the number of unique words/lines in the input file. You can also filter these with commands like grep and sed, as well as use sed and tr to translate the input and so on.<br />
<br />
Under the hood, UNIX starts a process for each of these commands. Each process reads from stdin and writes to stdout, however when piped, these are joined together where the output of ones becomes the input of the next in the chain. When they are waiting for input and none is currently available, the OS will not schedule that process and schedule another which is ready to run. One that is ready will read from its stdin and write to its stdout which will then have the effect of making another process ready to run again because it now has input that can be read. So it is actually the scheduler of the OS which is making some of the magic happen. A not so smart OS implementation might allow the first process to run to completion and buffer all of its output to then start the next process and feed it all of the buffered output from the first command in to it. This obviously will work for simple cases, but doesn't scale to long running chains of commands or ones where there is a very large amount of data processed which can not all fit in memory.<br />
<br />
I've often thought, it would be neat to do something like this in C++ code to express how a chain of processes could be linked up together. You can always chain up function calls in C++, and it has always been possible to override the pipe operator. Chaining function calls together is something you can do with an API designed for being used in that way such as this example using Qt:<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"> QString("Format : %1 %2 %2").arg(1).arg(2).arg(3);</span><br />
<br />
This though is along the lines of the 2nd type of OS implementation strategy for pipes where each command is run to completion one at a time without doing the smart thing. Examples where the pipe operator are used can also be found in Qt, such as how flags are combined. See the documentation for https://doc.qt.io/qt-5/qflags.html#Q_DECLARE_OPERATORS_FOR_FLAGS which generates the operator for combining flags.<br />
<br />
Putting it together, and it should be possible to define a pipe operator which joins together things which are iterable, and have something similar to UNIX style pipes in C++ code, for example:<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"> cat("wordlist.txt") | sort() | uniq()</span><br />
<br />
More idiomatic for C++ would be:<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"> cat("wordlist.txt").sort().uniq();</span><br />
<div>
<br /></div>
<div>
And that is the way you would join up things in C# also when using LINQ and iterables.</div>
<div>
However if really want to push onwards towards replicating UNIX pipes and adding syntactic sugar to replicate the syntax of a UNIX shell, then it may be even possible to drop the round braces in places, such as from the sort and uniq:</div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<span style="font-family: "courier new" , "courier" , monospace;"> cat("wordlist.txt") | sort | uniq > out;</span><br />
<div>
<br /></div>
<div>
Where 'sort', 'uniq' and 'out' would need to be objects instead of functions. But the pipe operator for the particular pair of types can be made to call specific functions on the objects, which is then how these can be glued together. Specifically:</div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">// A class which does sorting</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">class SortClass { public: SortClass(); };</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">// An object called 'sort'</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">SortClass sort;</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">// A class which does uniq</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">class UniqClass { public: UniqClass(); };</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">// An object called 'uniq'</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">UniqClass uniq;</span></div>
</div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">// A pipe operator to combine these</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">operator|(SortClass&, UniqClass&);</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">sort | uniq;</span></div>
<div>
<br /></div>
<div>
And it seems like something like this is coming to C++ in the form of the Ranges Library:</div>
<div>
<br /></div>
<div>
<a href="https://en.cppreference.com/w/cpp/ranges">https://en.cppreference.com/w/cpp/ranges</a></div>
<div>
<br /></div>
Co-routines immediately come to mind as something else which would be nice, such as having the yield feature that exists in C#. This would make it easier to have something more similar to the first type of smart OS implementation strategy for pipes, but without necessarily using threads/processes.<br />
<br />
Some other things I've seen in other contexts that I've liked are the map/reduce/filter types of expressions in languages like javascript and python. It's more the syntax and ways in which these easily combine that is nice about them, much like what it is I like about UNIX pipes.<br />
<br />
It seems like with the Ranges Library it will be possible to have map/reduce/filter kinds of operations such as is given on the cppreference web page for the ranges library:<br />
<br />
<br />
<pre class="de1" style="background-image: none; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 0px none white; font-size: 12.8px; font-stretch: normal; line-height: 1.2em; overflow: auto; padding: 0px; vertical-align: top; width: 55em;"><span class="kw4" style="color: blue;">int</span> main<span class="br0" style="color: green;">(</span><span class="br0" style="color: green;">)</span>
<span class="br0" style="color: green;">{</span>
<a href="http://en.cppreference.com/w/cpp/container/vector" style="background-image: none; color: #003080; text-decoration: none;"><span class="kw1266">std::<span class="me2">vector</span></span></a><span class="sy1" style="color: navy;"><</span><span class="kw4" style="color: blue;">int</span><span class="sy1" style="color: navy;">></span> ints<span class="br0" style="color: green;">{</span><span class="nu0" style="color: navy;">0</span>,<span class="nu0" style="color: navy;">1</span>,<span class="nu0" style="color: navy;">2</span>,<span class="nu0" style="color: navy;">3</span>,<span class="nu0" style="color: navy;">4</span>,<span class="nu0" style="color: navy;">5</span><span class="br0" style="color: green;">}</span><span class="sy4" style="color: teal;">;</span>
<span class="kw4" style="color: blue;">auto</span> even <span class="sy1" style="color: navy;">=</span> <span class="br0" style="color: green;">[</span><span class="br0" style="color: green;">]</span><span class="br0" style="color: green;">(</span><span class="kw4" style="color: blue;">int</span> i<span class="br0" style="color: green;">)</span><span class="br0" style="color: green;">{</span> <span class="kw1" style="color: #0000dd;">return</span> <span class="nu0" style="color: navy;">0</span> <span class="sy1" style="color: navy;">==</span> i <span class="sy2" style="color: #000040;">%</span> <span class="nu0" style="color: navy;">2</span><span class="sy4" style="color: teal;">;</span> <span class="br0" style="color: green;">}</span><span class="sy4" style="color: teal;">;</span>
<span class="kw4" style="color: blue;">auto</span> square <span class="sy1" style="color: navy;">=</span> <span class="br0" style="color: green;">[</span><span class="br0" style="color: green;">]</span><span class="br0" style="color: green;">(</span><span class="kw4" style="color: blue;">int</span> i<span class="br0" style="color: green;">)</span> <span class="br0" style="color: green;">{</span> <span class="kw1" style="color: #0000dd;">return</span> i <span class="sy2" style="color: #000040;">*</span> i<span class="sy4" style="color: teal;">;</span> <span class="br0" style="color: green;">}</span><span class="sy4" style="color: teal;">;</span>
<span class="kw1" style="color: #0000dd;">for</span> <span class="br0" style="color: green;">(</span><span class="kw4" style="color: blue;">int</span> i <span class="sy4" style="color: teal;">:</span> ints <span class="sy3" style="color: #000040;">|</span> std<span class="sy4" style="color: teal;">::</span><span class="me2">views</span><span class="sy4" style="color: teal;">::</span><span class="me2">filter</span><span class="br0" style="color: green;">(</span>even<span class="br0" style="color: green;">)</span> <span class="sy3" style="color: #000040;">|</span> std<span class="sy4" style="color: teal;">::</span><span class="me2">views</span><span class="sy4" style="color: teal;">::</span><span class="me2">transform</span><span class="br0" style="color: green;">(</span>square<span class="br0" style="color: green;">)</span><span class="br0" style="color: green;">)</span> <span class="br0" style="color: green;">{</span>
<a href="http://en.cppreference.com/w/cpp/io/cout" style="background-image: none; color: #003080; text-decoration: none;"><span class="kw1755">std::<span class="me2">cout</span></span></a> <span class="sy1" style="color: navy;"><<</span> i <span class="sy1" style="color: navy;"><<</span> <span class="st0" style="color: green;">' '</span><span class="sy4" style="color: teal;">;</span>
<span class="br0" style="color: green;">}</span>
<span class="br0" style="color: green;">}</span></pre>
<br />
<br />
The yield keyword in C# for expressing iteration over something and returning the elements without having to turn the code inside out to make it an iterator is nice, and the general way iterables and LINQ can be used in C# to do interesting things. This is along the lines of co-routines, and C++ looks to be adding them. From what I understand of how yield is implemented in C#, using threads isn't required for making yield work.<br />
<br />
If a language is designed to support co-routines, essentially the execution of a function can be suspended by jumping to another location if the state of the stack is preserved, and then the function resumed by jumping back if the stack and execution continues where it was previously. Typically you would think a thread is how you might do this because each thread has its own stack. If manually turning a function inside-out to make it in to a co-routine, the manual procedure is to turn all stack allocations in to something contained in a structure which represents the state to be preserved. This state also needs to track where in the function it was, so when it resumes being executed, it can jump to the previous location. When recursion is involved, the solution is that this structure is an array of this state to the maximum recursion depth and the current depth is also tracked. You can manually convert a function in C/C++ to be able to be used this way, but it is ugly and the resulting code is not as elegant when compared to the same code in C# written using yield. And it looks like in C++20 this will become an option which is quite exciting:<br />
<br />
<a href="https://en.cppreference.com/w/cpp/language/coroutines">https://en.cppreference.com/w/cpp/language/coroutines</a><br />
<br />
It appears as though the state which is preserved which would have otherwise been on the stack is dynamically allocated using new. I wonder how it deals with recursive functions. Possibly dynamically allocating the state isn't always needed, if hand rolling a conversion of a function to act similar to a co-routine, it is possible to allocate that state on the stack at the call-site and pass that down to the call of the co-routine as an input parameter, and then what you want is the language which supports co-routines to do that for you, and if not possible to allocate it from the stack to otherwise allocate it from the heap, but this is a pretty minor issue compared with the bigger problem which will be solved. Compared with the ranges library, I'm more excited about the addition of the coroutines, as trying to emulate coroutines without actual language support for them is hacky at best, or if not hacky, very inelegant.<br />
<br />
About emulating the ranges library, that is something I've attempted with my own flavour on things. For example, the example given using ranges is this:<br />
<br />
<pre class="de1" style="background-image: none; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 0px none white; font-size: 12.8px; font-stretch: normal; line-height: 1.2em; overflow: auto; padding: 0px; vertical-align: top; width: 55em;"><span class="kw1" style="color: #0000dd;"> for</span> <span class="br0" style="color: green;">(</span><span class="kw4" style="color: blue;">int</span> i <span class="sy4" style="color: teal;">:</span> ints <span class="sy3" style="color: #000040;">|</span> std<span class="sy4" style="color: teal;">::</span><span class="me2">views</span><span class="sy4" style="color: teal;">::</span><span class="me2">filter</span><span class="br0" style="color: green;">(</span>even<span class="br0" style="color: green;">)</span> <span class="sy3" style="color: #000040;">|</span> std<span class="sy4" style="color: teal;">::</span><span class="me2">views</span><span class="sy4" style="color: teal;">::</span><span class="me2">transform</span><span class="br0" style="color: green;">(</span>square<span class="br0" style="color: green;">)</span><span class="br0" style="color: green;">)</span> <span class="br0" style="color: green;">{</span>
<a href="http://en.cppreference.com/w/cpp/io/cout" style="background-image: none; color: #003080; text-decoration: none;"><span class="kw1755">std::<span class="me2">cout</span></span></a> <span class="sy1" style="color: navy;"><<</span> i <span class="sy1" style="color: navy;"><<</span> <span class="st0" style="color: green;">' '</span><span class="sy4" style="color: teal;">;</span>
<span class="br0" style="color: green;">}</span></pre>
<br />
Why is there the need to expose the for loop, and why isn't there a terminal print object to pipe in to which can do the output as above. My take on this would be to have a syntax like this:<br />
<br />
<pre class="de1" style="background-image: none; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 0px none white; font-size: 12.8px; font-stretch: normal; line-height: 1.2em; overflow: auto; padding: 0px; vertical-align: top; width: 55em;"><span class="kw1" style="color: #0000dd;"> </span>ints <span class="sy3" style="color: #000040;">|</span> <span class="me2">filter</span><span class="br0" style="color: green;">(</span>even<span class="br0" style="color: green;">)</span> <span class="sy3" style="color: #000040;">|</span> <span class="me2">transform</span><span class="br0" style="color: green;">(</span>square<span class="br0" style="color: green;">) | print;</span></pre>
<pre class="de1" style="background-image: none; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 0px none white; font-size: 12.8px; font-stretch: normal; line-height: 1.2em; overflow: auto; padding: 0px; vertical-align: top; width: 55em;"></pre>
So below is my implementation of my flavour of something similar to the C++20 ranges library that will however work with C++14 now, or with some effort could be made to work with C++11 if you don't mind making the code more verbose. I'm personally happy to target C++14 as my minimum, so have designed this code to require C++14. Here it is:<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<br />
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">//</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// C++ Views and Pipes</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// by John Ryland</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// (c) Copyright 2019</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">//</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>////////</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// BRIEF //</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">/*</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> Requires C++14, but would not be impossible to support C++11 with effort.</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> Compile with:</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> g++ --std=c++14 pipe-tests.cpp -o pipe-tests</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> Examples of what it can do:</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> to_array({"one","two","three","four","five"}) | reverse</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> | filter([](std::string a){ return a == "two"; }) | print;</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> This is C++ code, and it takes the list of strings and turns them in to a</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> std::array, then pipes it through </span><span style="font-family: "courier new" , "courier" , monospace;">a reverse function which causes the</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> iteration to happen in reverse, then pipes this through a filter which</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> is defined with an inline lambda which removes any items which equal "two",</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> and finally it prints out the result.</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> The lambdas don't need to be inline, it can be nicer to define a function</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> like this:</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> auto odd = [](int x) -> bool { return (x & 1) == 1; };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> Then it can be used like this:</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::vector<int> v = {1,2,3,4,5};</int></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | match(odd) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> This takes as input a std::vector of items, and wraps it in a view which is</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> piped to a matching function which </span><span style="font-family: "courier new" , "courier" , monospace;">will only pass through items where the</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> lambda returns true for the item. Internally the vector is not copied, simply</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> the iteration is what is varied. Next it prints out the result.</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> More complicated examples can be made:</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(1,101) | reverse | filter(odd) | first(5) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> This one uses the range function which generates items. At no point is an</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> actual </span><span style="font-family: "courier new" , "courier" , monospace;">list or vector of numbers made in </span><span style="font-family: "courier new" , "courier" , monospace;">memory. However it will print the</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> last 5 odd </span><span style="font-family: "courier new" , "courier" , monospace;">numbers working backwards from 101 as might be expected from</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> the commands.</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">*/</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>///////////</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// INCLUDES //</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>///////////</span></div>
<div style="background-color: white; font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<div style="color: rgba(0, 0, 0, 0.85); font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="color: #643820; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">#include </span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;"><</span><span style="color: #c41a16; font-family: "courier new" , "courier" , monospace;">cstdio</span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;">></span></div>
<div style="color: #643820; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">#include </span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;"><</span><span style="color: #c41a16; font-family: "courier new" , "courier" , monospace;">cstring</span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;">></span></div>
<div style="color: #643820; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">#include </span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;"><</span><span style="color: #c41a16; font-family: "courier new" , "courier" , monospace;">vector</span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;">></span></div>
<div style="color: #c41a16; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #643820;">#include </span></span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;"><</span><span style="font-family: "courier new" , "courier" , monospace;">iostream</span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;">></span></div>
<div style="color: #643820; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">#include </span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;"><</span><span style="color: #c41a16; font-family: "courier new" , "courier" , monospace;">sstream</span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;">></span></div>
<div style="color: #643820; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">#include </span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;"><</span><span style="color: #c41a16; font-family: "courier new" , "courier" , monospace;">array</span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;">></span></div>
<div style="color: #643820; font-stretch: normal; line-height: normal;"><span style="font-family: "courier new" , "courier" , monospace;">#include </span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;"><</span><span style="color: #c41a16; font-family: "courier new" , "courier" , monospace;">regex</span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;">></span></div><div style="color: #643820; font-stretch: normal; line-height: normal;"><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new" , "courier" , monospace;"><span style="color: #643820; font-family: "courier new" , "courier" , monospace;">#include </span></span><span style="caret-color: rgb(186, 0, 8); color: #ba0008; font-family: "courier new", courier, monospace;"><functional></span></div>
<div style="color: #643820; font-family: Menlo; font-stretch: normal; line-height: normal;">
<span style="color: #c41a16;"><br /></span></div>
</div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>//////////////</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// TYPE TRAITS //</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>//////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Container Traits ///////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> T, </span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> _ = </span><b>void</b><span color="rgba(0 , 0 , 0 , 0.85)">></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>struct</b></span> <span style="color: #0b4f79;">has_container_traits</span> : std::false_type {};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)">... Ts></span></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>struct</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>has_container_traits_helper<span color="rgba(0 , 0 , 0 , 0.85)"> {};</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> T></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>struct</b></span> <span style="color: #0b4f79;">has_container_traits</span><<span style="color: #0f68a0;">T</span>, <span style="color: #0f68a0;">std</span>::<span style="color: #0f68a0;">conditional_t</span><<span style="color: #9b2393;"><b>false</b></span>, has_container_traits_helper<</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// Const Container Trails:</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>typename</b></span> T::value_type,</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>typename</b></span> T::const_iterator,</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>typename</b></span> T::const_reverse_iterator,</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>decltype</b></span>(std::declval</span><span style="font-family: "courier new", courier, monospace;"><T></span><span style="font-family: "courier new", courier, monospace;">().crbegin()),</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>decltype</b></span>(std::declval</span><span style="font-family: "courier new", courier, monospace;"><T></span><span style="font-family: "courier new", courier, monospace;">().crend()),</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>decltype</b></span>(std::declval</span><span style="font-family: "courier new", courier, monospace;"><T></span><span style="font-family: "courier new", courier, monospace;">().cbegin()),</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>decltype</b></span>(std::declval</span><span style="font-family: "courier new", courier, monospace;"><T></span><span style="font-family: "courier new", courier, monospace;">().cend())</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">>, <span style="color: #9b2393;"><b>void</b></span>>> : <span style="color: #9b2393;"><b>public</b></span> <span style="color: #0f68a0;">std</span>::<span style="color: #0f68a0;">true_type</span> {};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> Container,</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>typename</b></span> std::enable_if<has_container_traits<Container><has_container_traits ontainer="">{}, <span style="color: #9b2393;"><b>bool</b></span>>::type = <span style="color: #9b2393;"><b>true</b></span>></has_container_traits></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>struct</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>is_container</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span><b>using</b><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #0f68a0;">type</span><span color="rgba(0 , 0 , 0 , 0.85)"> = </span><b>bool</b><span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> Container></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">is_container_t</span> = <span style="color: #9b2393;"><b>typename</b></span> is_container<Container><container>::type;</container></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// View Traits ////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> T, </span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> _ = </span><b>void</b><span color="rgba(0 , 0 , 0 , 0.85)">></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>struct</b></span> <span style="color: #0b4f79;">has_view_traits</span> : std::false_type {};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)">... Ts></span></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>struct</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>has_view_traits_helper<span color="rgba(0 , 0 , 0 , 0.85)"> {};</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> T></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>struct</b></span> <span style="color: #0b4f79;">has_view_traits</span><<span style="color: #0f68a0;">T</span>, <span style="color: #0f68a0;">std</span>::<span style="color: #0f68a0;">conditional_t</span><<span style="color: #9b2393;"><b>false</b></span>, has_view_traits_helper<</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// View Traits:</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>typename</b></span> T::element_type,</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>decltype</b></span>(std::declval</span><span style="font-family: "courier new", courier, monospace;"><T></span><span style="font-family: "courier new", courier, monospace;">().first()),</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>decltype</b></span>(std::declval</span><span style="font-family: "courier new", courier, monospace;"><T></span><span style="font-family: "courier new", courier, monospace;">().last()),</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>decltype</b></span>(std::declval</span><span style="font-family: "courier new", courier, monospace;"><T></span><span style="font-family: "courier new", courier, monospace;">().next()),</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>decltype</b></span>(std::declval</span><span style="font-family: "courier new", courier, monospace;"><T></span><span style="font-family: "courier new", courier, monospace;">().previous()),</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>decltype</b></span>(std::declval</span><span style="font-family: "courier new", courier, monospace;"><T></span><span style="font-family: "courier new", courier, monospace;">().current())</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">>, <span style="color: #9b2393;"><b>void</b></span>>> : <span style="color: #9b2393;"><b>public</b></span> <span style="color: #0f68a0;">std</span>::<span style="color: #0f68a0;">true_type</span> {};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> View,</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>typename</b></span> std::enable_if<has_view_traits<View><has_view_traits iew="">{}, <span style="color: #9b2393;"><b>bool</b></span>>::type = <span style="color: #9b2393;"><b>true</b></span>></has_view_traits></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>struct</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>is_view</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span><b>using</b><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #0f68a0;">type</span><span color="rgba(0 , 0 , 0 , 0.85)"> = </span><b>bool</b><span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> View></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">is_view_t</span> = <span style="color: #9b2393;"><b>typename</b></span> is_view<View><view>::type;</view></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>/////////////</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// VIEW TYPES //</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>/////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Container View /////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> Container, <span style="color: #9b2393;"><b>typename</b></span> BaseType, is_container_t<BaseType><basetype> = <span style="color: #9b2393;"><b>true</b></span>></basetype></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>container_wrapper_view</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">container_wrapper_view</span>(Container a_container)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_container(a_container)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// implements View</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">element_type</span> = <span style="color: #9b2393;"><b>typename</b></span> BaseType::value_type;</span></div>
<div style="background-color: white; font-stretch: normal; line-height: normal;">
<span style="color: rgba(0, 0, 0, 0.85); font-family: "courier new" , "courier" , monospace; font-size: 12px;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">first</span>() { m_it = m_container.cbegin(); </span><span style="color: rgba(0, 0, 0, 0.85); font-family: "courier new", courier, monospace; font-size: 12px;">return !m_container.empty(); }</span></div>
<div style="background-color: white; font-stretch: normal; line-height: normal;">
<span style="color: rgba(0, 0, 0, 0.85); font-family: "courier new" , "courier" , monospace; font-size: 12px;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">last</span>() </span><span style="background-color: transparent; color: rgba(0, 0, 0, 0.85); font-family: "courier new" , "courier" , monospace; font-size: 12px;">{ m_it = </span><span style="background-color: transparent; color: rgba(0, 0, 0, 0.85); font-family: "courier new", courier, monospace; font-size: 12px;">std</span><span style="color: rgba(0, 0, 0, 0.85); font-family: "courier new", courier, monospace; font-size: 12px;">::prev(m_container.cend());</span><span style="background-color: transparent; font-size: 12px;"><span style="color: rgba(0, 0, 0, 0.850980392156863); font-family: courier new, courier, monospace;"> </span></span><span style="color: rgba(0, 0, 0, 0.85); font-family: "courier new", courier, monospace; font-size: 12px;">return !m_container.empty(); }</span></div>
<div style="background-color: white; font-stretch: normal; line-height: normal;">
<span style="color: rgba(0, 0, 0, 0.85); font-family: "courier new" , "courier" , monospace; font-size: 12px;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">next</span>() </span><span style="color: rgba(0, 0, 0, 0.85); font-family: "courier new" , "courier" , monospace; font-size: 12px;">{ m_it = </span><span style="color: rgba(0, 0, 0, 0.85); font-family: "courier new", courier, monospace; font-size: 12px;">std::next(m_it); return m_it != m_container.cend(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">previous</span>() { if (m_it != m_container.cbegin()) { m_it = std::prev(m_it); return true; } return false; }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>const</b></span> <span style="color: #0f68a0;">element_type</span>& <span style="color: #0f68a0;">current</span>() { <span style="color: #9b2393;"><b>return</b></span> *m_it; }</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>private</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">Container</span> <span style="color: #0f68a0;">m_container</span>;</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #9b2393;"><b>typename</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>BaseType<span color="rgba(0 , 0 , 0 , 0.85)">::</span>const_iterator<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_it<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Range View /////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> T></span></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>range_view</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">range_view</span>(T start, T end)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_start(start)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> , m_end(end)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// implements View</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #9b2393;"><b>using</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>element_type<span color="rgba(0 , 0 , 0 , 0.85)"> = T;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">first</span>() { m_current = m_start; <span style="color: #9b2393;"><b>return</b></span> m_start <= m_end; }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">last</span>() { m_current = m_end; <span style="color: #9b2393;"><b>return</b></span> m_start <= m_end; }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">next</span>() { ++m_current; <span style="color: #9b2393;"><b>return</b></span> m_current <= m_end; }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">previous</span>() { --m_current; <span style="color: #9b2393;"><b>return</b></span> m_current >= m_start; }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>const</b></span> <span style="color: #0f68a0;">T</span>& <span style="color: #0f68a0;">current</span>() { <span style="color: #9b2393;"><b>return</b></span> m_current; }</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>private</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>T<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_current<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>T<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_start<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>T<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_end<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Match View ////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> ParentView, <span style="color: #9b2393;"><b>typename</b></span> Functor, is_view_t<ParentView><parentview> = <span style="color: #9b2393;"><b>true</b></span>></parentview></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>match_view</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">element_type</span> = <span style="color: #9b2393;"><b>typename</b></span> ParentView::element_type;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">match_view</span>(<span style="color: #9b2393;"><b>const</b></span> ParentView& a_parentView, <span style="color: #9b2393;"><b>const</b></span> Functor& a_match)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_parentView(a_parentView)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> , m_match(a_match)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// implements View</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">first</span>() { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.first()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; <span style="color: #9b2393;"><b>return</b></span> nextValid(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">last</span>() { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.last()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; <span style="color: #9b2393;"><b>return</b></span> previousValid(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">next</span>() { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.next()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; <span style="color: #9b2393;"><b>return</b></span> nextValid(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">previous</span>() { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.previous()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; <span style="color: #9b2393;"><b>return</b></span> previousValid(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>const</b></span> <span style="color: #0f68a0;">element_type</span>& <span style="color: #0f68a0;">current</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.current(); }</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>private</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">nextValid</span>() { <span style="color: #9b2393;"><b>while</b></span> (!m_match(m_parentView.current())) { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.next()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; } <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>true</b></span>; }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">previousValid</span>() { <span style="color: #9b2393;"><b>while</b></span> (!m_match(m_parentView.current())) { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.previous()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; } <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>true</b></span>; }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>ParentView<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_parentView<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>Functor<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_match<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Filter View ////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> ParentView, is_view_t<ParentView><parentview> = <span style="color: #9b2393;"><b>true</b></span>></parentview></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span> <span style="color: #0b4f79;">filter_view</span> : <span style="color: #9b2393;"><b>public</b></span> match_view<ParentView, std::function<<parentview span="" std::function="" style="color: #9b2393;"><b>bool(typename ParentView::element_type)>></b></parentview></span></div><div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;"><span style="font-family: "courier new", courier, monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// inherits View</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">element_type</span> = <span style="color: #9b2393;"><b>typename</b></span> ParentView::element_type;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">function_type</span> = std::function<<span style="color: #9b2393;"><b>bool</b></span>(element_type)>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">filter_view</span>(<span style="color: #9b2393;"><b>const</b></span> ParentView& a_parentView, <span style="color: #9b2393;"><b>const</b></span> function_type& a_filter)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : match_view<ParentView, function_type><parentview function_type="">(a_parentView, [a_filter](element_type a_item) { <span style="color: #9b2393;"><b>return</b></span> !a_filter(a_item); })</parentview></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Transform View /////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> ParentView, <span style="color: #9b2393;"><b>typename</b></span> Functor, <span style="color: #9b2393;"><b>typename</b></span> ReturnType, is_view_t<ParentView><parentview> = <span style="color: #9b2393;"><b>true</b></span>></parentview></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>transform_view</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">parent_element_type</span> = <span style="color: #9b2393;"><b>typename</b></span> ParentView::element_type;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">transform_view</span>(<span style="color: #9b2393;"><b>const</b></span> ParentView& a_parentView, <span style="color: #9b2393;"><b>const</b></span> Functor& a_transform)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_parentView(a_parentView)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> , m_transform(a_transform)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// implements View</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">element_type</span> = ReturnType;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">first</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.first(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">last</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.last(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">next</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.next(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">previous</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.previous(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">element_type</span> <span style="color: #0f68a0;">current</span>() { <span style="color: #9b2393;"><b>return</b></span> m_transform(m_parentView.current()); } <span style="color: #5d6c79;">// NOTE: Transformed elements are returned by value</span></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>private</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>ParentView<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_parentView<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>Functor<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_transform<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Reverse View ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> ParentView, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><ParentView> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>reverse_view</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">reverse_view</span>(<span style="color: #9b2393;"><b>const</b></span> ParentView& view)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_parent(view)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// implements View</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">element_type</span> = <span style="color: #9b2393;"><b>typename</b></span> ParentView::element_type;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">first</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parent.last(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">last</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parent.first(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">next</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parent.previous(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">previous</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parent.next(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>const</b></span> <span style="color: #0f68a0;">element_type</span>& <span style="color: #0f68a0;">current</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parent.current(); }</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>private</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>element_type<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_current<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>ParentView<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_parent<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Skip View //////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> ParentView, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><ParentView> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>skip_view</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">element_type</span> = <span style="color: #9b2393;"><b>typename</b></span> ParentView::element_type;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">skip_view</span>(<span style="color: #9b2393;"><b>const</b></span> ParentView& a_parentView, size_t a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_parentView(a_parentView)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> , m_count(a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// implements View</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">first</span>() { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.first()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; <span style="color: #9b2393;"><b>return</b></span> nextValid(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">last</span>() { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.last()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; <span style="color: #9b2393;"><b>return</b></span> previousValid(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">next</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.next(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">previous</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.previous(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>const</b></span> <span style="color: #0f68a0;">element_type</span>& <span style="color: #0f68a0;">current</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.current(); }</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>private</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">nextValid</span>() { <span style="color: #9b2393;"><b>while</b></span> (m_count >= <span style="color: #1c00cf;">1</span>) { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.next()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; m_count--; } <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>true</b></span>; }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">previousValid</span>() { <span style="color: #9b2393;"><b>while</b></span> (m_count >= <span style="color: #1c00cf;">1</span>) { <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.previous()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>; m_count--; } <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>true</b></span>; }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>ParentView<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_parentView<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">size_t</span> <span style="color: #0f68a0;">m_count</span>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Take View //////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> ParentView, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><ParentView> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>take_view</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">element_type</span> = <span style="color: #9b2393;"><b>typename</b></span> ParentView::element_type;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">take_view</span>(<span style="color: #9b2393;"><b>const</b></span> ParentView& a_parentView, size_t a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_parentView(a_parentView)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> , m_count(a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// implements View</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">first</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.first(); }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">last</span>() {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> size_t count = m_count - <span style="color: #1c00cf;">1</span>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>if</b></span> (count <= <span style="color: #1c00cf;">0</span> || !m_parentView.first()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>while</b></span> (count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>if</b></span> (!m_parentView.next()) <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>false</b></span>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> count--;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> <span style="color: #9b2393;"><b>true</b></span>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> } </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">next</span>() { m_count--; <span style="color: #9b2393;"><b>return</b></span> (m_count > <span style="color: #1c00cf;">0</span>) ? m_parentView.next() : <span style="color: #9b2393;"><b>false</b></span>; }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> <span style="color: #0f68a0;">previous</span>() { m_count--; <span style="color: #9b2393;"><b>return</b></span> (m_count > <span style="color: #1c00cf;">0</span>) ? m_parentView.previous() : <span style="color: #9b2393;"><b>false</b></span>; }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>const</b></span> <span style="color: #0f68a0;">element_type</span>& <span style="color: #0f68a0;">current</span>() { <span style="color: #9b2393;"><b>return</b></span> m_parentView.current(); }</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>private</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>ParentView<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_parentView<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">size_t</span> <span style="color: #0f68a0;">m_count</span>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>///////////</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// WRAPPERS //</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>///////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Container Wrapper //////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// creates a const reference container view</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> Container, is_container_t<Container><container> = <span style="color: #9b2393;"><b>true</b></span>></container></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">container_view</span>(<span style="color: #9b2393;"><b>const</b></span> Container& a_container)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> container_wrapper_view<<span style="color: #9b2393;"><b>const</b></span> Container&, Container>(a_container);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// creates a container view by value</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> Container, is_container_t</span><span style="font-family: "courier new", courier, monospace;"><Container> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">container_copy_view</span>(<span style="color: #9b2393;"><b>const</b></span> Container& a_container)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> container_wrapper_view</span><span style="font-family: "courier new", courier, monospace;"><Container, Container></span><span style="font-family: "courier new", courier, monospace;">(a_container);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Range Wrapper //////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> T></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">range</span>(T start, T end)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> range_view<T><t>(start, end);</t></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Array Wrapper //////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>class</b></span> T, std::size_t N, std::size_t... I></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>constexpr</b></span> <span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">to_array_impl</span>(T (&a)[N], std::index_sequence<I...><i ...="">)</i></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> std::array<std::remove_cv_t<T><std::remove_cv_t>, N>{ { a[I]... } };</std::remove_cv_t></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>class</b></span> T, std::size_t N, std::size_t... I></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>constexpr</b></span> <span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">to_array_impl</span>(T (&&a)[N], std::index_sequence</span><span style="font-family: "courier new", courier, monospace;"><I...></span><i ...="" style="font-family: "courier new", courier, monospace;">)</i></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> std::array</span><span style="font-family: "courier new", courier, monospace;"><std::remove_cv_t<T></span><std::remove_cv_t style="font-family: "courier new", courier, monospace;">,</std::remove_cv_t><span style="font-family: "courier new", courier, monospace;"> N>{ { std::move(a[I])... } };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<br /></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<br /></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>class</b></span> T, std::size_t N></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>constexpr</b></span> <span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">to_array</span>(T (&a)[N])</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> to_array_impl(a, std::make_index_sequence<N><n>{});</n></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>class</b></span> T, std::size_t N></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>constexpr</b></span> <span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">to_array</span>(T (&&a)[N])</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> to_array_impl(std::move(a), std::make_index_sequence</span><span style="font-family: "courier new", courier, monospace;"><N></span><span style="font-family: "courier new", courier, monospace;">{});</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Print Wrapper /////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>print_class</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// No state, just the class as a tag</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Reverse Wrapper ////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>reverse_class</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// No state, just the class as a tag</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Match Wrapper //////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> Functor></span></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>match_class</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">match_class</span>(Functor&& a_m)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_m(a_m)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>Functor<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_m<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Filter Wrapper /////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> Functor></span></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>filter_class</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">filter_class</span>(Functor&& a_f)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_f(a_f)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>Functor<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_f<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Transform Wrapper //////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> Functor></span></span></div>
<div style="background-color: white; color: #0b4f79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>class</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>transform_class</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">transform_class</span>(Functor&& t)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_t(t)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>Functor<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_t<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>///////////</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// COMMANDS //</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>///////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Print Command //////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">print_class<span color="rgba(0 , 0 , 0 , 0.85)"> </span>print<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Reverse Command ////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">reverse_class<span color="rgba(0 , 0 , 0 , 0.85)"> </span>reverse<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Match Command //////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> Functor></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">match</span>(Functor&& a_m)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> match_class<Functor><functor>(std::forward</functor></span><span style="font-family: "courier new", courier, monospace;"><Functor></span><span style="font-family: "courier new", courier, monospace;">(a_m));</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Grep Command ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Match a regular expression</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">grep</span>(<span style="color: #9b2393;"><b>const</b></span> std::string& a_re)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::regex re(a_re);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> f = [re](<span style="color: #9b2393;"><b>const</b></span> std::string& a_s) { <span style="color: #9b2393;"><b>return</b></span> std::regex_search(a_s, re); };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> match_class<<span style="color: #9b2393;"><b>decltype</b></span>(f)>(std::move(f));</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Filter Command /////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> Functor></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">filter</span>(Functor&& a_f)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> filter_class</span><span style="font-family: "courier new", courier, monospace;"><Functor></span><span style="font-family: "courier new", courier, monospace;">(std::forward</span><span style="font-family: "courier new", courier, monospace;"><Functor></span><span style="font-family: "courier new", courier, monospace;">(a_f));</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Take Command ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>class</b><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #0b4f79;">take</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">take</span>(size_t a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_count(a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>size_t<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_count<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Head Command ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">head</span> = take;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// First Command //////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">first</span> = take;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Last Command ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>class</b><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #0b4f79;">last</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">last</span>(size_t a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_count(a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>size_t<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_count<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Tail Command ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">tail</span> = last;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Skip Command ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>class</b><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #0b4f79;">skip</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">skip</span>(size_t a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_count(a_count)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>size_t<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_count<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Drop Command ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>using</b></span> <span style="color: #0f68a0;">drop</span> = skip;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Transform Command //////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> Functor></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">transform</span>(Functor&& a_f)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> transform_class</span><span style="font-family: "courier new", courier, monospace;"><Functor></span><span style="font-family: "courier new", courier, monospace;">(std::forward</span><span style="font-family: "courier new", courier, monospace;"><Functor></span><span style="font-family: "courier new", courier, monospace;">(a_f));</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Convert Command ////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>template</b><span color="rgba(0 , 0 , 0 , 0.85)"> <</span><b>typename</b><span color="rgba(0 , 0 , 0 , 0.85)"> Functor></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #0f68a0;">convert</span>(Functor&& a_f)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> transform_class</span><span style="font-family: "courier new", courier, monospace;"><Functor></span><span style="font-family: "courier new", courier, monospace;">(std::forward</span><span style="font-family: "courier new", courier, monospace;"><Functor></span><span style="font-family: "courier new", courier, monospace;">(a_f));</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Join Command ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>class</b><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #0b4f79;">join</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">join</span>(<span style="color: #9b2393;"><b>const</b></span> std::string& s)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_s(s)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>std<span color="rgba(0 , 0 , 0 , 0.85)">::</span>string<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_s<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Split Command //////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>class</b><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #0b4f79;">split</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><b>public</b><span color="rgba(0 , 0 , 0 , 0.85)">:</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #0f68a0;">split</span>(<span style="color: #9b2393;"><b>const</b></span> std::string& a_delimiters)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> : m_delimiters(a_delimiters)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>std<span color="rgba(0 , 0 , 0 , 0.85)">::</span>string<span color="rgba(0 , 0 , 0 , 0.85)"> </span>m_delimiters<span color="rgba(0 , 0 , 0 , 0.85)">;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>////////</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// PIPES //</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Container Pipe /////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> Container, <span style="color: #9b2393;"><b>typename</b></span> View, is_container_t<Container><container> = <span style="color: #9b2393;"><b>true</b></span>></container></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> Container& c, <span style="color: #9b2393;"><b>const</b></span> View& v)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> container_view(c) | v;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Array Pipe /////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> ArrayT, std::size_t ArrayN, <span style="color: #9b2393;"><b>typename</b></span> View></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> ArrayT (&a)[ArrayN], <span style="color: #9b2393;"><b>const</b></span> View& v)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> c = to_array(a);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> container_view(c) | v;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Reverse Pipe ///////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, is_view_t<View><view> = <span style="color: #9b2393;"><b>true</b></span>></view></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v1, <span style="color: #9b2393;"><b>const</b></span> reverse_class& r)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> reverse_view</span><span style="font-family: "courier new", courier, monospace;"><View></span><span style="font-family: "courier new", courier, monospace;">(v1);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Match Pipe ////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, <span style="color: #9b2393;"><b>typename</b></span> Functor, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v1, <span style="color: #9b2393;"><b>const</b></span> match_class<Functor><functor>& m)</functor></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> match_view</span><span style="font-family: "courier new", courier, monospace;"><View, Functor></span><span style="font-family: "courier new", courier, monospace;">(v1, m.m_m);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Filter Pipe ////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, <span style="color: #9b2393;"><b>typename</b></span> Functor, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v1, <span style="color: #9b2393;"><b>const</b></span> filter_class<Functor><functor>& f)</functor></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> filter_view</span><span style="font-family: "courier new", courier, monospace;"><View></span><span style="font-family: "courier new", courier, monospace;">(v1, f.m_f);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Take Pipe //////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v1, <span style="color: #9b2393;"><b>const</b></span> take& t)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> take_view</span><span style="font-family: "courier new", courier, monospace;"><View></span><span style="font-family: "courier new", courier, monospace;">(v1, t.m_count);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Last Pipe //////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v1, <span style="color: #9b2393;"><b>const</b></span> last& l)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> v1 | reverse | take(l.m_count) | reverse;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Skip Pipe //////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v1, <span style="color: #9b2393;"><b>const</b></span> skip& s)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> skip_view</span><span style="font-family: "courier new", courier, monospace;"><View></span><span style="font-family: "courier new", courier, monospace;">(v1, s.m_count);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Transform Pipe /////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, <span style="color: #9b2393;"><b>typename</b></span> Functor, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v1, <span style="color: #9b2393;"><b>const</b></span> transform_class<Functor><functor>& t)</functor></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> transform_view<View, Functor, <view functor="" span="" style="color: #9b2393;"><b>decltype(t.m_t(typename View::element_type()))>(v1, t.m_t);</b></view></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Join Pipe //////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #0f68a0;">std</span>::<span style="color: #0f68a0;">string</span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> std::string& s, <span style="color: #9b2393;"><b>const</b></span> join& j)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span><b>return</b><span color="rgba(0 , 0 , 0 , 0.85)"> s;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #0f68a0;">std</span><span color="rgba(0 , 0 , 0 , 0.85)">::</span><span style="color: #0f68a0;">string</span><span color="rgba(0 , 0 , 0 , 0.85)"> </span><b>operator</b><span color="rgba(0 , 0 , 0 , 0.85)">|(</span><b>const</b><span color="rgba(0 , 0 , 0 , 0.85)"> </span><b>char</b><span color="rgba(0 , 0 , 0 , 0.85)">* s, </span><b>const</b><span color="rgba(0 , 0 , 0 , 0.85)"> join& j)</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #9b2393; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span><b>return</b><span color="rgba(0 , 0 , 0 , 0.85)"> s;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #0f68a0;">std</span>::<span style="color: #0f68a0;">string</span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& c, <span style="color: #9b2393;"><b>const</b></span> join& j)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::stringstream ss;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::string deliminator = j.m_s;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> apply(c, [&ss, deliminator](<span style="color: #9b2393;"><b>const</b></span> <span style="color: #9b2393;"><b>auto</b></span>& a, <span style="color: #9b2393;"><b>bool</b></span> f, <span style="color: #9b2393;"><b>bool</b></span> l) { ss << a; <span style="color: #9b2393;"><b>if</b></span> (!l) ss << deliminator; } );</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> ss.str();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Split Pipe /////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>auto</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v1, <span style="color: #9b2393;"><b>const</b></span> split& s)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #0e0eff; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #5d6c79;">// </span>https://stackoverflow.com/questions/236129/how-do-i-iterate-over-the-words-of-a-string</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::string str = v1 | join(<span style="color: #c41a16;">""</span>);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::string delimiters = s.m_delimiters;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::vector<std::string><std::string> tokens;</std::string></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::size_t start = <span style="color: #1c00cf;">0</span>, end, length = str.length();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>while</b></span> (length && start < length + <span style="color: #1c00cf;">1</span>)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> end = str.find_first_of(delimiters, start);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>if</b></span> (end == std::string::npos)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> end = length;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::string token = std::string(str.data() + start, end - start);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> tokens.push_back(token);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> start = end + <span style="color: #1c00cf;">1</span>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// Unfortunately we need to make a copy here as 'tokens' is on the stack. Possibly this</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// could be improved if have a string_spans implementation as a 'view' in to the original data.</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>return</b></span> container_copy_view<std::vector<std::string><std::vector std::string="">>(tokens);</std::vector></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Print Pipe /////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>void</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v1, <span style="color: #9b2393;"><b>const</b></span> print_class& r)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> apply(v1, [](<span style="color: #9b2393;"><b>const</b></span> <span style="color: #9b2393;"><b>auto</b></span>& a, <span style="color: #9b2393;"><b>bool</b></span> f, <span style="color: #9b2393;"><b>bool</b></span> l) { std::cout << a; <span style="color: #9b2393;"><b>if</b></span> (!l) std::cout << <span style="color: #c41a16;">","</span>; } );</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>void</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> std::string& s, <span style="color: #9b2393;"><b>const</b></span> print_class& r)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << s << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// Apply Pipe /////////////////////////////////////////////////////////////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, <span style="color: #9b2393;"><b>typename</b></span> Functor, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>void</b></span> <span style="color: #0f68a0;">for_each</span>(<span style="color: #9b2393;"><b>const</b></span> View& a_iterable, Functor&& f)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> View it = a_iterable; </span>// takes a copy of the view, views should be cheap to copy</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>if</b></span> (it.first())</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>do</b></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> f(it.current());</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> } <span style="color: #9b2393;"><b>while</b></span> (it.next());</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, <span style="color: #9b2393;"><b>typename</b></span> Functor, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>void</b></span> <span style="color: #0f68a0;">apply</span>(<span style="color: #9b2393;"><b>const</b></span> View& a_iterable, Functor&& f)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> first = <span style="color: #9b2393;"><b>true</b></span>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>bool</b></span> last = <span style="color: #9b2393;"><b>false</b></span>;</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> View it = a_iterable; </span>// takes a copy of the view, views should be cheap to copy</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>if</b></span> (it.first())</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>do</b></span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> {</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> current = it.current();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> last = !it.next();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> f(current, first, last);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> first = <span style="color: #9b2393;"><b>false</b></span>;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> } <span style="color: #9b2393;"><b>while</b></span> (!last);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> }</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> View, is_view_t</span><span style="font-family: "courier new", courier, monospace;"><View> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>void</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> View& v, <span style="color: #9b2393;"><b>const</b></span> std::function<<span style="color: #9b2393;"><b>void</b></span>(<span style="color: #9b2393;"><b>typename</b></span> View::element_type)>& f)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> for_each(v, f);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>template</b></span> <<span style="color: #9b2393;"><b>typename</b></span> Container, is_container_t</span><span style="font-family: "courier new", courier, monospace;"><</span><span style="font-family: "courier new", courier, monospace;">Container</span><span style="font-family: "courier new", courier, monospace;">> </span><span style="font-family: "courier new", courier, monospace;">= </span><span style="color: #9b2393; font-family: "courier new", courier, monospace;"><b>true</b></span><span style="font-family: "courier new", courier, monospace;">></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>void</b></span> <span style="color: #9b2393;"><b>operator</b></span>|(<span style="color: #9b2393;"><b>const</b></span> Container& c, <span style="color: #9b2393;"><b>const</b></span> std::function<<span style="color: #9b2393;"><b>void</b></span>(<span style="color: #9b2393;"><b>typename</b></span> Container::value_type)>& f)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::for_each(c.begin(), c.end(), f);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>////////</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// DEMOS //</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>////////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>void</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>demo1<span color="rgba(0 , 0 , 0 , 0.85)">()</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Demo"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> strings = to_array({<span style="color: #c41a16;">"one"</span>,<span style="color: #c41a16;">"two"</span>,<span style="color: #c41a16;">"three"</span>,<span style="color: #c41a16;">"four"</span>,<span style="color: #c41a16;">"five"</span>});</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Printing strings"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Reversing strings"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Matching strings with 'o'"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | match([](std::string a){ <span style="color: #9b2393;"><b>return</b></span> a.find(<span style="color: #c41a16;">"o"</span>) != std::string::npos; }) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #c41a16; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> std::cout << </span>"Grepping strings for 'one|two|four'"<span color="rgba(0 , 0 , 0 , 0.85)"> << std::endl;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | grep(<span style="color: #c41a16;">"one|two|four"</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #c41a16; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> std::cout << </span>"Filtering strings without 'o'"<span color="rgba(0 , 0 , 0 , 0.85)"> << std::endl;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | filter([](std::string a){ <span style="color: #9b2393;"><b>return</b></span> a.find(<span style="color: #c41a16;">"o"</span>) == std::string::npos; }) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Taking 3 strings"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | take(<span style="color: #1c00cf;">3</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Head 3 strings"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | head(<span style="color: #1c00cf;">3</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"First 3 strings"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | first(<span style="color: #1c00cf;">3</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Last 3 strings"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | last(<span style="color: #1c00cf;">3</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Tail 3 strings"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | tail(<span style="color: #1c00cf;">3</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Skipping 2 strings"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | skip(<span style="color: #1c00cf;">2</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Dropping 2 strings"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | drop(<span style="color: #1c00cf;">2</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #c41a16; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> std::cout << </span>"Transforming strings to lengths"<span color="rgba(0 , 0 , 0 , 0.85)"> << std::endl;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | transform([](std::string a) { <span style="color: #9b2393;"><b>return</b></span> a.length(); }) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #c41a16; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> std::cout << </span>"Converting strings to lengths"<span color="rgba(0 , 0 , 0 , 0.85)"> << std::endl;</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | convert([](std::string a) { <span style="color: #9b2393;"><b>return</b></span> a.size(); }) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Joining strings with '.'"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | join(<span style="color: #c41a16;">"."</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << <span style="color: #c41a16;">"Splitting strings with '.'"</span> << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> strings | join(<span style="color: #c41a16;">"."</span>) | split(<span style="color: #c41a16;">"."</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>void</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>demo2<span color="rgba(0 , 0 , 0 , 0.85)">()</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// Functions</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> printer = [](<span style="color: #9b2393;"><b>auto</b></span> x) { std::cout << x << <span style="color: #c41a16;">","</span>; };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> newline = []() { std::cout << std::endl; };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// Input</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::vector<<span style="color: #9b2393;"><b>int</b></span>> v = {<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">2</span>,<span style="color: #1c00cf;">3</span>,<span style="color: #1c00cf;">4</span>,<span style="color: #1c00cf;">5</span>};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// Normal way</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>for</b></span> (<span style="color: #9b2393;"><b>auto</b></span> i : v)</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> printer(i);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// C++11 functional way</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::for_each(v.begin(), v.end(), printer);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// Improved way</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> v | printer;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> newline();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// Best way</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> v | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span>// More interesting options </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> v | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>///////</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">// MAIN //</span></div>
<div style="background-color: white; color: #5d6c79; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(93 , 108 , 121 , 0.34902)" style="font-stretch: normal; line-height: normal;">///</span>///////</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #0f68a0; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="color: #9b2393;"><b>int</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> </span>main<span color="rgba(0 , 0 , 0 , 0.85)">()</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">{</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> demo1();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> demo2();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::stringstream ss;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> printer = [](<span style="color: #9b2393;"><b>auto</b></span> x) { std::cout << x << <span style="color: #c41a16;">","</span>; };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> newline = []() { std::cout << std::endl; };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> odd = [](<span style="color: #9b2393;"><b>int</b></span> x) -> <span style="color: #9b2393;"><b>bool</b></span> { <span style="color: #9b2393;"><b>return</b></span> (x & <span style="color: #1c00cf;">1</span>) == <span style="color: #1c00cf;">1</span>; };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> as_string = [](<span style="color: #9b2393;"><b>auto</b></span> x) -> std::string { <span style="color: #9b2393;"><b>return</b></span> std::to_string(x); };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>int</b></span> v2[] = {<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">2</span>,<span style="color: #1c00cf;">3</span>,<span style="color: #1c00cf;">4</span>,<span style="color: #1c00cf;">5</span>};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> v2 | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>int</b></span> v3[]{<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">2</span>,<span style="color: #1c00cf;">3</span>,<span style="color: #1c00cf;">4</span>,<span style="color: #1c00cf;">5</span>};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> v3 | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> v4 = to_array<<span style="color: #9b2393;"><b>int</b></span>>({<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">2</span>,<span style="color: #1c00cf;">3</span>,<span style="color: #1c00cf;">4</span>,<span style="color: #1c00cf;">5</span>});</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> v4 | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> to_array({<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">2</span>,<span style="color: #1c00cf;">3</span>,<span style="color: #1c00cf;">4</span>,<span style="color: #1c00cf;">5</span>}) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::string(<span style="color: #c41a16;">"13,15,66,42,23"</span>) | split(<span style="color: #c41a16;">","</span>) | join(<span style="color: #c41a16;">"."</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #c41a16;">"13,15,66,42,23"</span> | split(<span style="color: #c41a16;">","</span>) | join(<span style="color: #c41a16;">"."</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #c41a16;">"13,15,66,42,23"</span> | split(<span style="color: #c41a16;">","</span>) | grep(<span style="color: #c41a16;">"3"</span>) | join(<span style="color: #c41a16;">"."</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: #c41a16; font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"><span color="rgba(0 , 0 , 0 , 0.85)"> </span><span style="color: #9b2393;"><b>auto</b></span><span color="rgba(0 , 0 , 0 , 0.85)"> sl = </span>"13,15,66,42,23,123"<span color="rgba(0 , 0 , 0 , 0.85)"> | split(</span>","<span color="rgba(0 , 0 , 0 , 0.85)">);</span></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> s = sl | join(<span style="color: #c41a16;">"."</span>);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << s << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> newline();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">15</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::cout << (range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">15</span>) | transform(as_string) | join(<span style="color: #c41a16;">","</span>)) << std::endl;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<br /></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> for_each(range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">15</span>), printer);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> newline();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> for_each(reverse_view<range_view<int>>(range(10,15)), printer);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> newline();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> for_each(range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">14</span>) | reverse | filter(odd), printer);</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> newline();</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> std::vector<<span style="color: #9b2393;"><b>int</b></span>> v = {<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">2</span>,<span style="color: #1c00cf;">3</span>,<span style="color: #1c00cf;">4</span>,<span style="color: #1c00cf;">5</span>};</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | match(odd) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | filter(odd) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | reverse | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | reverse | reverse | filter(odd) | reverse | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | reverse | filter(odd) | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | filter(odd) | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> container_view(v) | reverse | filter(odd) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"> </span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">14</span>) | reverse | filter(odd) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">15</span>) | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">15</span>) | reverse | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">15</span>) | filter(odd) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">15</span>) | reverse | filter(odd) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">15</span>) | reverse | filter(odd) | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">10</span>,<span style="color: #1c00cf;">14</span>) | reverse | filter(odd) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">101</span>) | reverse | filter(odd) | take(<span style="color: #1c00cf;">5</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">101</span>) | reverse | filter(odd) | head(<span style="color: #1c00cf;">5</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">101</span>) | reverse | filter(odd) | first(<span style="color: #1c00cf;">5</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">101</span>) | reverse | first(<span style="color: #1c00cf;">5</span>) | reverse | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">101</span>) | last(<span style="color: #1c00cf;">5</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">101</span>) | tail(<span style="color: #1c00cf;">5</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">6</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> range(<span style="color: #1c00cf;">1</span>,<span style="color: #1c00cf;">6</span>) | skip(<span style="color: #1c00cf;">3</span>) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: #9b2393;"><b>auto</b></span> filt = [](std::string a){ <span style="color: #9b2393;"><b>return</b></span> a == <span style="color: #c41a16;">"BAD"</span>; };</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> to_array({<span style="color: #c41a16;">"five"</span>,<span style="color: #c41a16;">"BAD"</span>,<span style="color: #c41a16;">"four"</span>,<span style="color: #c41a16;">"three"</span>,<span style="color: #c41a16;">"BAD"</span>,<span style="color: #c41a16;">"two"</span>,<span style="color: #c41a16;">"one"</span>}) | reverse | filter(filt) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;"> to_array({<span style="color: #c41a16;">"one"</span>,<span style="color: #c41a16;">"two"</span>,<span style="color: #c41a16;">"three"</span>,<span style="color: #c41a16;">"four"</span>,<span style="color: #c41a16;">"five"</span>}) | reverse | filter([](std::string a){ <span style="color: #9b2393;"><b>return</b></span> a == <span style="color: #c41a16;">"two"</span>; }) | print;</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal;">
<span style="font-family: "courier new" , "courier" , monospace;">}</span></div>
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<br />
<div style="background-color: white; color: rgba(0, 0, 0, 0.85); font-size: 12px; font-stretch: normal; line-height: normal; min-height: 14px;">
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<br />jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-67702280005377999782017-06-27T08:16:00.000-07:002017-06-27T08:33:44.537-07:00C++11 and some efficiency improvements<br />
I recently learnt a few new things.<br />
<br />
<h3>
shared_ptr</h3>
<br />
First is that using std::make_shared<t> is actually not only good because of it's better exception safety (the primary reason I hear people promoting it), but it is actually better because it is infact more efficient and saves space.</t><br />
<br />
To understand this, first lets explain what a shared_ptr is. It is basically a wrapper around a raw pointer. What the wrapper provides is reference counting. So a shared_ptr is two things, the raw pointer and a reference count associated with that raw pointer. Actually this is a slight simplification, because of weak pointers, the reference count is two counts, a weak count and a strong count, and both these are put in a structure called the control block for the shared_ptr, but conceptually this is the reference count part of it (in fact there is a bit more than this too, including the deleter etc, and this gets hidden via type eraser, but that is far more detail than is needed for discussion here). So a shared_ptr is two pointers, one to the object being managed, and another to the reference count (or control block). The reference count needs to be a pointer so that multiple shared_ptr instances can be referring and updating the one shared reference count associated with the object. Because shared_ptr has a constructor that takes a raw pointer, when constructed this way, there is only one choice and that is to dynamically allocate the reference count. Hence two dynamic allocations with this strategy, one for the allocation of the object that is passed in this way, and a second for the reference count. More allocations can mean memory fragmentation. What std::make_shared<t> does is to essentially create a struct of T and reference count together and allocate this with one allocation. So one less dynamic memory allocation. Makes the deletion simpler too. And so that is why using make_shared to create a shared_ptr is better.</t><br />
<br />
Whilst thinking about this, I realised a few things too. Firstly, unqiue_ptr obviously doesn't require a reference count and therefore doesn't require a second dynamic memory allocation ever. I did always scratch my head as to why in C++11 there was make_shared but no make_unique (although added later), but it kind of makes sense that is doesn't add quite as much, the only thing is the exception safety which to be honest I don't lose sleep over as much as the efficiency of these things in the common case compared with the exceptional cases. The provision of make_shared is far more valuable that adding make_unique from this point of view. And thinking about it even more, whist I do know that implementations are in fact doing this make_shared optimisation, another optimisation I'm not so sure about which can be done is that in the case make_shared is not used, that second dynamic memory allocation for the reference count / control block, could be deferred until time as there is a second reference. This practically makes the cost of shared_ptr equal to that of unique_ptr when they are used equivalently. You would obviously for semantic reasons choose appropriately, but I think there is little need to chose from a performance point of view.<br />
<br />
So the main take away should be always use make_shared to construct your shared_ptrs when you can, there is no extra dynamic memory allocation, the cost is that of allocating a minimal bit of extra house keeping information together with your object (assuming your object is not of some trivial size like < 32 bytes, consider making a copy of the object instead when it is small, obviously consider your individual situation when evaluating if shared_ptr is right for you). For that second dynamic memory allocation when it is needed, I have imagined there could possibly be schemes in which it is possible to do away with it with a more complex strategy. The idea I had was something like a doubly linked list between active shared_ptr objects to a shared object. As a shared_ptr object goes out of scope, it removes itself from the doubly linked list, patching the other ones to keep it all chained together. The last one removed will know it is because it's prev and next pointers will become null. I'm not sure if anyone has implemented a reference counting scheme doing this. It obviously gets more complex when dealing with weak and strong references, and also it much more maintenance work making this more complex and more likely to break and also isn't so nice from a memory access pattern point of view, jumping about too much.<br />
<br />
<h3>
Final</h3>
The next thing I learnt recently is the keyword in C++11 'final'. It is possible similar to in Java to be able to mark implementations of interfaces as final. You can do this on the class or on a specific virtual member function. What the semantics of this means is that you can not override it further in the inheritance hierarchy. When a class is marked final, it can not be inherited from, and when a member function is marked final, a subclass can not override it. This is great from a semantics point of view, you can protect an implementation from being overridden as you are marking it as intended to be the final and last in that chain of inheritance, this lets you write it in a way that you don't need to design for unintended uses. But really the thing that makes me interested about final isn't so much being able to express some kind of semantic intent in your implementation, whilst that is important and cool, what I like is that it allows the compiler to do some things to make the code more efficient, and that is actually how I came across this, I theorised that when you have virtual functions and a vtable, you wouldn't need to do a virtual dispatch if you had knowledge that in the context of the pointer you have and the function being called that it wasn't further derived. And from this realisation that I thought that a final keyword actually would mean that you could make things more efficient that I searched about this and found that not only did C++11 add this, that in fact from more research that implementations are doing this optimisation already and avoid the virtual dispatch when final is used and your pointer is of the type where final was declared.<br />
<br />
What does it mean from a practical point of view? Well it may change they way you might structure and write code involving virtuals. Firstly you will want to start decorating your classes with final. That is the first step. Next you will want to defer casting to a base pointer as late as possible, but also after you have done so, what you may then prefer to do after this if doing multiple dispatches with a given object, you might find that it will be faster to dynamically cast the object to the derived cast it is and do the multiple virtual calls with this pointer than to use the base pointer to speed up special fast path cases. I don't think you would have been able to as easily sped up a fast path like this without removing the general purpose virtual functions or without more intrusive changes.<br />
<br />
<h3>
String literals</h3>
Something that annoys me about C/C++ is that there is no distinction between literal objects and other objects in the types for them. For example take string literals, such as "blah" in the code, this is a string of bytes, 'b', 'l', 'a', 'h', 0 which is const, and exists in the statically initialised section of the program and exists for the duration of the execution. But generally its type is "const char *". If I new an array of chars, I'll get a "char *" which is readily convertible to a "const char *". This is mutable. It exists only as long as I say it exists. It is quite a different beast to a string literal. What I really want is to be able to provide APIs which can distinguish between these and do something different depending on how it was called, either with an immutable string literal or with a mutable array or chars. Sometimes you want to know that it is a string literal so you don't need to make a copy so can make an optimisation. Other times it can be for better security so you have tighter control over what and where something can be passed in to a function.<br />
<br />
So how can it be done. It can be done using templates, the only downside is that generally this will expose the implementation to the header, although this could just be used as a shim.<br />
<br />
For example:<br />
<br />
template <size_t n=""></size_t><span style="font-family: "menlo"; font-size: 11px;"><size_t N></span><br />
void DoSomethingWithLiteral(const char (&a_str)[N])<br />
{<br />
// a_str is a string literal<br />
}<br />
<br />
Basically that is it. A function that looks like that will only accept string literals. Beware that providing other functions with the same name that the overloading doesn't resolve to the call with a string literal ending up going to the overload instead of the intended one. Obviously always test, and then more template magic can be used to disambiguate the calls, that is doable now.<br />
<br />
A few more things about string literals.<br />
<br />
String literal operators. New in C++11 is user defined literal operator overloads. This is neat and basically allows for defining units to scalar values in a natural way. In English when talking about values in certain units, the way it is expressed is such as 50kmh, or 10kg, or 5s or 10days etc. The pattern is a scalar value (e.g. integer value) followed by a suffix which is an abbreviation for the units. So in traditional C++ the typical way would be to make a type, for example a type called kilograms or kg, e.g.: class kg {}; and you could make a constructor that took an int (or float) so then you could express it something like: kg(50); And could do "kg(50) + kg(10);" etc. And could provide conversion operators to convert from the type kg to the type g so you could do "kg(1) + g(500)" etc. But this is not so natural. a literal operator essentially lets you define a conversion operator from int to your type but expressed like 1kg or 500g, so you can write instead "1kg + 500g". It kind of reminds me a bit of python how you can express things like: "some string".split() where you can call methods on literals. And in C++ it is also not limited to ints, you can do this for string literals too, so could convert a string literal to a std::string for example with something like "blah"_s.<br />
<br />
One more thing about string literals.<br />
<br />
I wrote about logging not long ago here: <a href="http://inspired-code.blogspot.com.au/2017/05/avoiding-heap-allocation-with-strings.html">Avoiding heap allocation with strings</a><br />
<br />
Something I realise that I didn't mention is that you can forward the arguments using templates better than what I demonstrated. The use of va_list isn't needed if you pass via templates. Obviously though the issue with that is then you need to expose everything in the header file, so the demonstrated method is fine if you want to hide the implementation details.<br />
<br />
Here is a slightly improved way:<br />
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">template</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> <</span><span style="font-variant-ligatures: no-common-ligatures;"><span style="color: #ba2da2;">size_t N</span></span><span style="color: black; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">typename</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> ...Ts></span></div>
<div style="color: #4e2800; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">void</span><span style="font-variant-ligatures: no-common-ligatures;"> Logger(</span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">enum</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">LogLevel</span><span style="font-variant-ligatures: no-common-ligatures;"> a_level,</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">const</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">char (</span><span style="font-variant-ligatures: no-common-ligatures;">&a_fmt)[N], </span>Ts&& ...a_args)</div>
<div style="color: #4e2800; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">{</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #4e2800; font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="color: #4e2800; font-variant-ligatures: no-common-ligatures;"> msgSiz = </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">std</span><span style="color: #4e2800; font-variant-ligatures: no-common-ligatures;">::</span><span style="color: #3e1e81; font-variant-ligatures: no-common-ligatures;">snprintf</span><span style="color: #4e2800; font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">nullptr</span><span style="color: #4e2800; font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="color: #4e2800; font-variant-ligatures: no-common-ligatures;">, a_fmt, a_args...) + </span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="color: #4e2800; font-variant-ligatures: no-common-ligatures;">;</span></div>
<div style="color: #4e2800; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">char</span><span style="font-variant-ligatures: no-common-ligatures;"> msg[msgSiz];</span></div>
<div style="color: #4e2800; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> ::</span><span style="color: #3e1e81; font-variant-ligatures: no-common-ligatures;">snprintf</span><span style="font-variant-ligatures: no-common-ligatures;">(msg, msgSiz, a_fmt, a_args...);</span></div>
<div style="color: #4e2800; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="background-color: white; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif; font-size: 13px;"> ...</span></div>
<span style="background-color: white; color: #4e2800; font-family: "arial" , "tahoma" , "helvetica" , "freesans" , sans-serif; font-size: 13px;">}</span><br />
<br />
You'll notice it is slightly less lines of code than the original. It perfectly forwards the arguments, and does so without all the fuss of using va_lists. Also another subtle change is the way in which a_fmt is passed in. Instead of being passed as a const char*, it is passed and preserved as a string literal. This has some benefits, security and efficiency. First is the compiler at compile time can make checks as to the arguments match with the format provided, it also forces the a_fmt that is passed to be a string literal so there is no possibility that at runtime a maliciously formed a_fmt string will be passed to this.<br />
<br />
It may not be appropriate in the above case, but in some cases it is possible to forward declare a template without providing the body in the header and declaring the body of the template in the source file. In the above case there are too many varying parameters to the template to be able to instantiate all the required uses of it in a single cpp file. But there are cases where templates can be used where it is reasonable that each expansion of the template for each type can be anticipated and hidden but provided in a cpp file. This is generally preferable if it can be done, which leads to the next thing I learnt recently which is a good things to know.<br />
<br />
<h3>
Headers and forward declarations</h3>
<br />
I was reading "Effective C++" by Scott Meyers, the books are over 20 years old, but there is still value to be gained from them. Obviously some advice is dated and a reading of any older text book needs to be made in context, but sometimes there are things you just didn't realised and somehow missed, in fact it seems a lot of people have missed this particular point which I will elaborate on, as I have rarely seen this practised if ever.<br />
<br />
It involves the forward declaration of types, and then defining functions in terms of them not just by pointer or reference, but also by value.<br />
<br />
The example from the book goes something like this:<br />
<br />
#pragma once // Perhaps another blog post about using pragma once ?<br />
#ifndef BIRTHDAY_H<br />
#define BIRTHDAY_H<br />
<br />
class Date; // this is the forward declaration<br />
<br />
Date getMyBirthday(); // return the date of my birthday<br />
void setMyBirthday(Date a_date); // set the date of my birthday<br />
<br />
#endif // BIRTHDAY_H<br />
<br />
<br />
I didn't realise this was possible, but I tried it and it is indeed possible. I don't know why, but I thought that you would at least need to make the Date used in the function prototypes need to be references or pointers when you don't yet know the details of what the Date class is. But this is great that this actually works.<br />
<br />
It works if you think about it, because you only need to know the details of what Date is when you go to implement those functions or when you go to call those functions, so you can defer inclusion of date.h until that time rather than forcing it in to the header.<br />
<br />
I think that was my confusion, if not including date.h inside birthday.h, then I could neither implement birthday.cpp nor make use of the functions in birthday.h that depended on Date (say e.g. in main.cpp for sake of simplicity), and logically assumed that the fix was to include date.h inside of birthday.h. But that is the fallacy. That actually isn't the fix you are looking for. The fix you really want is to include date.h in both birthday.cpp and main.cpp. This seems to contravene the DRY principle (don't repeat yourself). But it is really what is better. As much as possible, you want to not include headers in your headers, it only leads to more headers being included and so on which leads to longer compile times. This chain of headers including headers means that 1000s of function prototypes are pulled in, when in fact in a given cpp file, it may only use 100s or less of external functions to itself. Being more explicit inside the cpp files of what is included is preferable to implicitly including much more from headers including other headers.<br />
<br />
I think this is something I am going to try to adopt more if I can.<br />
<br />
Some gotchas and possible solutions. Where you do need to know the details of an object and its size is when you use it as a member variable. e.g.:<br />
<br />
class Date;<br />
class Birthday {<br />
public:<br />
int dayOfMonth();<br />
int month();<br />
private:<br />
Date date;<br />
... other members<br />
};<br />
<br />
Now this won't work. You can't figure out the sizeof(Birthday) without knowing the sizeof(Date). You can't do "new Birthday". I'm pretty sure this won't compile as is.<br />
<br />
If you really don't want to include date.h or if Date was a bit more of a heavy weight object, a workaround would be to wrap it in a shared_ptr or unique_ptr, and this goes back to one of the original points in this blog about the efficiency of such.<br />
<br />
Anyway, possibly exposing all the private member variables in a class is not great if you can avoid it, and if you do go the route of wrapping in unqiue_ptr or shared_ptr any of the members, why not then combine all the private members together in to a struct and wrap that entire struct in a smart pointer. This is essentially what is called a pimpl. Once you do that, you can hide all of that implementation detail in the cpp file. It looks like this in the header:<br />
<br />
<br />
#pragma once<br />
<br />
class Birthday {<br />
public:<br />
int dayOfMonth();<br />
int month();<br />
private:<br />
struct Pimpl;<br />
std::shared_ptr<Pimpl><pimpl>;</pimpl><br />
};<br />
<div>
<br /></div>
<br />
In the cpp file you can then do what ever you like:<br />
<br />
<br />
#include "Birthday.h"<br />
<br />
struct Birthday::Pimpl<br />
{<br />
// put anything you like in here<br />
// change it as often and as much as you like<br />
};<br />
<br />
<br />
Make sure the Birthday constructor (not shown) uses make_shared for efficiency!<br />
<br />
I might write more in another blog about this pattern of pimpl in a shared_ptr.<br />
<br />
<br />jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-39157119826976753372017-06-07T04:43:00.001-07:002017-06-07T07:36:54.585-07:00Array of Structures and Structures of Arrays<br />
It can be time consuming and painful to recode data structures in a program to better improve efficiency by optimising the data layout to group data together which will be accessed together.<br />
<br />
The goal is to improve cache utilisation. You don't want to iterate an array of structures where you are only accessing some of the members of each item. Say each item in the array is a struct of 32 bytes in size, but we only access 4 bytes of each one as we loop. We have loaded up our cache lines with loads of data we aren't even going to touch resulting in sub-optimal efficiency. An alternative approach in this scenario is to re-arrange the data in to a structure holding arrays for each member. When accessing the one member at a time when iterating, the cache will be used more efficiently as the cache lines will be filled up with only the data we are accessing. Alternatively re-writing the code to work on each item as a whole at a time might be an option, but it also might not be possible or be sub-optimal.<br />
<br />
Conversely if the data is arranged as structures of arrays and when iterating multiple members are accessed at the same time, there might be related problems, but it is less likely. You still may want to try both approaches to see what works best for given data structures and their access patterns.<br />
<br />
But it's not trivial in C/C++ to rearrange the data like this without having to re-write any code which deals with this data. You can't simply flick a switch and the compiler automagically figures out how to re-arrange the code generation to access the data in the alternative layout. Being able to do that would be pretty cool. Jonathan Blow claims in his Jai programming language to have the ability to do just that. Currently Jai isn't released so all we know is from presentations of this language, but it appears to work by decorating the declaration of the array with something which says how it will be laid out and the language generates the appropriate code without the programmer needing to change the code which is accessing it.<br />
<br />
Now I would like to be able to do something similar in C/C++, so I had a bit of a think about it and have come up with this basic idea on how it might be possible to achieve something that comes close. Unfortunately to make it work requires some macros and templates, but nothing too fancy.<br />
<br />
<br />
Here is the basic idea we want to arrive at:<br />
<br />
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">template</span><span style="font-variant-ligatures: no-common-ligatures;"> <</span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="font-variant-ligatures: no-common-ligatures;"> SIZE></span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">struct</span><span style="font-variant-ligatures: no-common-ligatures;"> SomeStructure</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">{</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">int</span><span style="font-variant-ligatures: no-common-ligatures;"> m_someMember[SIZE];</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">float</span><span style="font-variant-ligatures: no-common-ligatures;"> m_someOtherMember[SIZE];</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: black; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures;">// you could put anything in here, just each one needs to have "[SIZE]" added to the end</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">};</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<span style="font-variant-ligatures: no-common-ligatures;">Then we can create arrays either way like </span><span style="font-variant-ligatures: no-common-ligatures;">this</span><span style="font-variant-ligatures: no-common-ligatures;">:</span><br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">// As an array of structures</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">SomeStructure<</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="font-variant-ligatures: no-common-ligatures;">> AoS_array[</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1000</span><span style="font-variant-ligatures: no-common-ligatures;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">// As a structure of arrays</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">SomeStructure</span><span style="font-variant-ligatures: no-common-ligatures;"><</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1000</span><span style="font-variant-ligatures: no-common-ligatures;">> SoA_array[</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="font-variant-ligatures: no-common-ligatures;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<br /></div>
<span style="font-variant-ligatures: no-common-ligatures;">When we want to access them we </span><span style="font-variant-ligatures: no-common-ligatures;">do</span><span style="font-variant-ligatures: no-common-ligatures;"> one of these:</span><br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">int</span><span style="font-variant-ligatures: no-common-ligatures;"> x = AoS_array[n].m_someMember[</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="font-variant-ligatures: no-common-ligatures;">];</span></div>
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">int</span><span style="font-variant-ligatures: no-common-ligatures;"> x = SoA_array[</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="font-variant-ligatures: no-common-ligatures;">].m_someMember[n];</span></div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;"><br /></span></div>
<div>
<br /></div>
<div>
Notice we need to swap the indexes. But we can do that easily with a macro if we know which type of array it is. One simple way I came up with was making a macro for when declaring an array which also sets a const bool which the accessing macro can use.</div>
<div>
<br /></div>
So here are the macros:<br />
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">#define DECLARE_STRUCT_BEGIN(StructName) \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> template <size_t size=""> \</size_t></span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> struct StructName \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> {</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">#define MEMBER(t, name) \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> t name[SIZE];</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">#define DECLARE_STRUCT_END(StructName) \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> };</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">#define MAKE_AOS(array, S, SIZE) \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> S<</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="font-variant-ligatures: no-common-ligatures;">> array[SIZE]; \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> const bool array##_isSOA = false;</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">#define MAKE_SOA(array, S, SIZE) \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> S<size> array[</size></span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="font-variant-ligatures: no-common-ligatures;">]; \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> const bool array##_isSOA = true;</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">#define GET(array, a, n) \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> ((array##_isSOA) ? array[</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="font-variant-ligatures: no-common-ligatures;">].a[n] : array[n].a[</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="font-variant-ligatures: no-common-ligatures;">])</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<br /></div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;"><br /></span></div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;">Probably this could be tweaked and improved, but it gets the idea across as to how it could be possible. I think it is fairly self explanatory.</span></div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;"><br /></span></div>
<div>
Usage example:</div>
<div>
<br /></div>
<div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">DECLARE_STRUCT_BEGIN</span><span style="color: black; font-variant-ligatures: no-common-ligatures;">(S)</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">MEMBER</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">int</span><span style="font-variant-ligatures: no-common-ligatures;">, a)</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">MEMBER</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">int</span><span style="font-variant-ligatures: no-common-ligatures;">, b)</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">MEMBER</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">int</span><span style="font-variant-ligatures: no-common-ligatures;">, c)</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">DECLARE_STRUCT_END</span><span style="color: black; font-variant-ligatures: no-common-ligatures;">(S)</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">MAKE_AOS</span><span style="font-variant-ligatures: no-common-ligatures;">(array1, S, </span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">100</span><span style="font-variant-ligatures: no-common-ligatures;">)</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">MAKE_SOA</span><span style="font-variant-ligatures: no-common-ligatures;">(array3, S, </span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">100</span><span style="font-variant-ligatures: no-common-ligatures;">)</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">void</span><span style="font-variant-ligatures: no-common-ligatures;"> test()</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">{</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">MAKE_AOS</span><span style="font-variant-ligatures: no-common-ligatures;">(array2, </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">S</span><span style="font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">100</span><span style="font-variant-ligatures: no-common-ligatures;">)</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">for</span><span style="font-variant-ligatures: no-common-ligatures;"> (</span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">int</span><span style="font-variant-ligatures: no-common-ligatures;"> i = </span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="font-variant-ligatures: no-common-ligatures;">; i < </span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">100</span><span style="font-variant-ligatures: no-common-ligatures;">; i++)</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> {</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">GET</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">array1</span><span style="font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">a</span><span style="font-variant-ligatures: no-common-ligatures;">, i) = i;</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">GET</span><span style="font-variant-ligatures: no-common-ligatures;">(array2, </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">a</span><span style="font-variant-ligatures: no-common-ligatures;">, i) = i;</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">GET</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">array3</span><span style="font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">a</span><span style="font-variant-ligatures: no-common-ligatures;">, i) = i;</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> }</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">}</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"><br /></span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"><br /></span></div>
</div>
<div>
I think I may be able to improve on this with templates instead of macros to to make the syntax more appealing, but just having something that works is a start and makes it a synch to switch the data structures to and from AoS to SoA to try out different layouts without mammoth amounts of work.<br />
<br />
Also referring to my other post about serialisation and de-serialization (<a href="http://inspired-code.blogspot.com.au/p/automating-object-serializationdeserial.html">http://inspired-code.blogspot.com.au/p/automating-object-serializationdeserial.html</a>) you could work the macros together where I presented a DECLARE_CLASS and DECLARE_MEMBER macro to automagically generate the code for serialising and de-serializing a structure, it shouldn't be too hard to combine the macros to combine the two ideas of declaring a structure/class that generates the serialisation and deserialisation and also is easy to switch from SoA to AoS. That is another improvement direction that this could be taken.<br />
<br />
<br />
Along the lines of using templates to reduce the use of macros, possibly this is one direction to take it to do the declaring of an SOA or AOS and the consistent accessing in to either without relying on the preprocessor:<br />
<br />
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #ba2da2; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">template</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> <</span><span style="font-variant-ligatures: no-common-ligatures;">typename</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> T></span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">struct</span><span style="font-variant-ligatures: no-common-ligatures;"> ArrayAccessor</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">{</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">explicit</span><span style="font-variant-ligatures: no-common-ligatures;"> ArrayAccessor(</span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">std</span><span style="font-variant-ligatures: no-common-ligatures;">::</span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">function</span><span style="font-variant-ligatures: no-common-ligatures;"><t amp="" span=""><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="font-variant-ligatures: no-common-ligatures;">)> func) : </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">m_getter</span><span style="font-variant-ligatures: no-common-ligatures;">(func) {}</span></t></span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">inline</span><span style="font-variant-ligatures: no-common-ligatures;"> T& </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">operator</span><span style="font-variant-ligatures: no-common-ligatures;">[](</span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">std</span><span style="font-variant-ligatures: no-common-ligatures;">::</span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="font-variant-ligatures: no-common-ligatures;"> idx) {</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">return</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">m_getter</span><span style="font-variant-ligatures: no-common-ligatures;">(idx);</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> }</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">std</span><span style="font-variant-ligatures: no-common-ligatures;">::</span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">function</span><span style="font-variant-ligatures: no-common-ligatures;"><t amp="" span=""><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="font-variant-ligatures: no-common-ligatures;">)> m_getter;</span></t></span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">};</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #ba2da2; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">template</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> <</span><span style="font-variant-ligatures: no-common-ligatures;">template</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"><</span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="color: black; font-variant-ligatures: no-common-ligatures;">> </span><span style="font-variant-ligatures: no-common-ligatures;">class</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> t, </span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> SIZE></span></div>
<div style="color: #ba2da2; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">struct</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> SOA</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">{</span></div>
<div style="color: #ba2da2; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: black; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures;">template</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> <</span><span style="font-variant-ligatures: no-common-ligatures;">typename</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> T></span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">ArrayAccessor</span><span style="font-variant-ligatures: no-common-ligatures;"><t> get(T (t<size>::*memberPtr)[SIZE]) {</size></t></span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">return</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">ArrayAccessor</span><span style="font-variant-ligatures: no-common-ligatures;"><t>([&](size_t idx)->T& { </t></span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">return</span><span style="font-variant-ligatures: no-common-ligatures;"> (</span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">m_array</span><span style="font-variant-ligatures: no-common-ligatures;">[</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="font-variant-ligatures: no-common-ligatures;">].*memberPtr)[idx]; });</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> }</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> t<size> m_array[</size></span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="font-variant-ligatures: no-common-ligatures;">];</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">};</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #ba2da2; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">template</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> <</span><span style="font-variant-ligatures: no-common-ligatures;">template</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"><</span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="color: black; font-variant-ligatures: no-common-ligatures;">> </span><span style="font-variant-ligatures: no-common-ligatures;">class</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> t, </span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> SIZE></span></div>
<div style="color: #ba2da2; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">struct</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> AOS</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">{</span></div>
<div style="color: #ba2da2; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: black; font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures;">template</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> <</span><span style="font-variant-ligatures: no-common-ligatures;">typename</span><span style="color: black; font-variant-ligatures: no-common-ligatures;"> T></span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">ArrayAccessor</span><span style="font-variant-ligatures: no-common-ligatures;"><t> get(T (t<</t></span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="font-variant-ligatures: no-common-ligatures;">>::*memberPtr)[</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="font-variant-ligatures: no-common-ligatures;">]) {</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">return</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">ArrayAccessor</span><span style="font-variant-ligatures: no-common-ligatures;"><t>([&](size_t idx)->T& { </t></span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">return</span><span style="font-variant-ligatures: no-common-ligatures;"> (</span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">m_array</span><span style="font-variant-ligatures: no-common-ligatures;">[idx].*memberPtr)[</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="font-variant-ligatures: no-common-ligatures;">]; });</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> }</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> t<</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="font-variant-ligatures: no-common-ligatures;">> m_array[SIZE];</span></div>
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">};</span></div>
</div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;"><br /></span></div>
<div>
<br />
<br />
Then to declare an array as SOA or AOS you would do:<br />
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">SOA</span><span style="font-variant-ligatures: no-common-ligatures;"><</span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">S</span><span style="font-variant-ligatures: no-common-ligatures;">,</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1000</span><span style="font-variant-ligatures: no-common-ligatures;">> array4;</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">AOS</span><span style="font-variant-ligatures: no-common-ligatures;"><</span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">S</span><span style="font-variant-ligatures: no-common-ligatures;">,</span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1000</span><span style="font-variant-ligatures: no-common-ligatures;">> array5;</span></div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;"><br /></span></div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;">Access can be made to be the same:</span></div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;"><br /></span></div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;"><div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">#define ARRAY_MEMBER(array, member) \</span></div>
<div style="color: #78492a; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> array.get(&std::remove_reference<decltype array.m_array="" span=""><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="font-variant-ligatures: no-common-ligatures;">])>::type::member)</span></decltype></span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<span style="font-variant-ligatures: no-common-ligatures;"></span><br /></div>
<br />Usage:<br />
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
<br /></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">ARRAY_MEMBER</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">array4</span><span style="font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">a</span><span style="font-variant-ligatures: no-common-ligatures;">)[</span><span style="color: #31595d; font-variant-ligatures: no-common-ligatures;">i</span><span style="font-variant-ligatures: no-common-ligatures;">] = i;</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal; min-height: 13px;">
</div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">ARRAY_MEMBER</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">array5</span><span style="font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">a</span><span style="font-variant-ligatures: no-common-ligatures;">)[</span><span style="color: #31595d; font-variant-ligatures: no-common-ligatures;">i</span><span style="font-variant-ligatures: no-common-ligatures;">] = i;</span></div>
<div>
<span style="font-variant-ligatures: no-common-ligatures;"><br /></span></div>
<br />Ideally the templates could work out the type without needing so much typing or macros, but that is left as an exercise for the reader.</span></div>
<br /></div>
jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-84508593313013498062017-05-30T06:59:00.001-07:002017-05-30T06:59:24.873-07:00Avoiding heap allocation with strings<br />
I was wanting to debug my memory allocations and hit a problem. The logging code that prints out useful information to help debug and trace the program is itself allocating memory. This is particularly pronounced with the string manipulations it does and with creating formatted strings from a variable list of arguments.<br />
<br />
It got me thinking. Firstly when one has a std::string object, particularly if that object itself was on the stack, it still allocates off the heap, it is too bad there is no way to allocate off the stack as the lifetime of the object is on the stack anyway. This is just how it is in C/C++. You can sort of do variable sized allocations off the stack, such as alloca or a variable sized array, such as:<br />
<br />
size_t var = i * 10;<br />
char array[var];<br />
<br />
Depending on the compiler, that can work. But anyway, this is no good for a general kind of string class as the lifetime of this is the scope it is created in so won't persist when the function returns. The same applies for alloca.<br />
<br />
But I really want to solve this and completely avoid making heap allocations while logging. The main culprit is formatting a string from a format argument and a variable list of arguments.<br />
<br />
<br />
So the first thing to do is work out the required size for this variable sized array to format in to.<br />
<br />
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">void</span><span style="font-variant-ligatures: no-common-ligatures;"> Logger(</span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">enum</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">LogLevel</span><span style="font-variant-ligatures: no-common-ligatures;"> a_level,</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">const</span><span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">char</span><span style="font-variant-ligatures: no-common-ligatures;">* a_fmt, </span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">va_list</span><span style="font-variant-ligatures: no-common-ligatures;"> a_args)</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;">{</span></div>
<div style="color: #008400; font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">va_list</span><span style="font-variant-ligatures: no-common-ligatures;"> args2;</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">va_copy</span><span style="font-variant-ligatures: no-common-ligatures;">(args2, a_args);</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #703daa; font-variant-ligatures: no-common-ligatures;">size_t</span><span style="font-variant-ligatures: no-common-ligatures;"> msgSiz = </span><span style="color: #4f8187; font-variant-ligatures: no-common-ligatures;">std</span><span style="font-variant-ligatures: no-common-ligatures;">::</span><span style="color: #3e1e81; font-variant-ligatures: no-common-ligatures;">vsnprintf</span><span style="font-variant-ligatures: no-common-ligatures;">(</span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">nullptr</span><span style="font-variant-ligatures: no-common-ligatures;">, </span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">0</span><span style="font-variant-ligatures: no-common-ligatures;">, a_fmt, a_args) + </span><span style="color: #272ad8; font-variant-ligatures: no-common-ligatures;">1</span><span style="font-variant-ligatures: no-common-ligatures;">;</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #ba2da2; font-variant-ligatures: no-common-ligatures;">char</span><span style="font-variant-ligatures: no-common-ligatures;"> msg[msgSiz];</span></div>
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> ::</span><span style="color: #3e1e81; font-variant-ligatures: no-common-ligatures;">vsnprintf</span><span style="font-variant-ligatures: no-common-ligatures;">(msg, msgSiz, a_fmt, args2);</span></div>
<br />
<div style="font-family: Menlo; font-size: 11px; line-height: normal;">
<span style="font-variant-ligatures: no-common-ligatures;"> </span><span style="color: #78492a; font-variant-ligatures: no-common-ligatures;">va_end</span><span style="font-variant-ligatures: no-common-ligatures;">(args2);</span></div>
...<br />
}<br />
<br />
<br />
Now msg contains the formatted string and without using the heap. The only tricky thing is having to make a copy of the va_list because it gets consumed in the first call to vsnprintf and we need a fresh copy to pass to the 2nd call to it we make.<br />
<br />
That wasn't too hard :)<br />
<br />
<br />jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-73911300669959349922016-03-24T07:10:00.001-07:002016-03-24T07:10:21.744-07:00Reflection in C++<span style="font-size: x-small;">Topics: C++, </span><span style="font-size: x-small;">Serialization, Reflection, Templates, JSON, Visitor pattern</span><br />
<br />
I've posted a new article here titled "<i>Automating Object Serialization/De-serialization in C++</i>":<br />
<br />
<a href="http://inspired-code.blogspot.com.au/p/automating-object-serializationdeserial.html">http://inspired-code.blogspot.com.au/p/automating-object-serializationdeserial.html</a><br />
<br />
<h3>
Overview</h3>
<br />
Some languages support reflection better than others. C++ has its runtime type information system which is reasonably limited. It won't help you much if you are doing serialization and de-serialization, so you end up writing a lot of boiler-plate code which feels like you are repeating yourself a lot.
<br />
<br />
Serialization though is just one example. In the article I give a bit of a run down on some of the alternatives and present a solution which reduces how much you have to repeat yourself.
<br />
In the end, this is an example of all you should end up needing to write to define and declare a struct with members and the code needed for being able to serialize/de-serialize it:
<br />
<br />
<pre class="brush:cpp;"> DECLARE_CLASS(Color)
DECLARE_MEMBER(int, red)
DECLARE_MEMBER(int, green)
DECLARE_MEMBER(int, blue)
END_DECLARE_CLASS</pre>
<br />
That is it. No duplicated info anywhere. I show how this isn't locked in to just serializing/de serializing too, and give examples of hashing and other uses. In follow up articles, I can elaborate on some of those other uses and the details of those.
<br />
<br />
Full article here:<br />
<br />
<a href="http://inspired-code.blogspot.com.au/p/automating-object-serializationdeserial.html">http://inspired-code.blogspot.com.au/p/automating-object-serializationdeserial.html</a><br />
<br />
<br />jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-59985733206621024392016-03-21T04:41:00.001-07:002016-03-21T04:41:03.372-07:00Using C++ Template Meta-Programming to expose C functions in Lua<br />
I've written an article on auto-magical language bindings, which you can find here: <a href="http://inspired-code.blogspot.com/p/automagical-language-bindings-using-c.html">http://inspired-code.blogspot.com/p/automagical-language-bindings-using-c.html</a><br />
<br />
The specifics of the article shows how to expose C functions to lua.<br />
<br />
The summary is, all you need to do to expose a function is add it to the list of exposed functions wrapped with the macro AUTO_BIND_C_FUNTION_TO_LUA such as in the following code snippet:<br />
<br />
<pre class="brush:cpp;">
</pre>
<pre class="brush:cpp;">// Some function prototypes to expose
void someFunc(int arg1, int arg2, const char* arg3);
void anotherFunc(const char* arg1, double arg2, int arg2);
// ... etc ...
</pre>
<pre class="brush:cpp;">// Import table
static const struct luaL_Reg scriptCallableFunctions[] =
{
AUTO_BIND_C_FUNTION_TO_LUA(someFunc)
AUTO_BIND_C_FUNTION_TO_LUA(anotherFunc)
// ... etc ...
};
</pre>
<pre class="brush:cpp;">
</pre>
<pre class="brush:cpp;">// Register all the functions we want wrapped
void registerLuaBindings(lua_State* L)
{
// Register all of our bindings
for (luaL_Reg r : scriptCallableFunctions) {
lua_pushcclosure(L, r.func, 0);
lua_setglobal(L, r.name);
}
}
</pre>
<br />
That certainly simplifies the work of exposing a function to Lua. I believe the approach could be adapted relatively easily for possibly other languages, such as python also.<br />
<br />
Hope you like it.
<br />
<br />jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-35200069988170472212016-03-20T05:26:00.000-07:002017-06-07T07:39:30.546-07:00Idiomatic way in C++ to test debug/release etc<h2>
Idiomatic way in C++ to test debug/release etc.</h2>
<br />
<br />
This is just a quick post on how one can improve their code by removing some #ifdefs and doing things a better way.<br />
<br />
It is common to see this style of code:<br />
<br />
<br />
<pre class="brush:cpp;">void SomeFunction(int x)
{
...
#ifndef NDEBUG // Double negative - if ! ! debug - eg: is debug
...
// extra debug checks
...
#else
...
#endif
...
}
</pre>
<br />
<br />
Usually NDEBUG is the define that is checked for release/debug checking as it is defined in the C standard in regards to assert.h. I don't know of any other defines the language specifies in relation to release/debug modes. So typically release builds will have NDEBUG defined, and non-release builds do not.<br />
<br />
However using preprocessor checks is not very idiomatic C++. It also means the preprocessor hides part of the code from the compiler, skipping important compiler checks of the other half of the code, which means that if not regularly compiling all the permutations of defines that some sides of #if conditions can rot and then require additional maintenance when enabling them. Better is to have the compiler parse both sides and allow it to determine that one side of the branch is never taken and allow the compiler to eliminate it.<br />
<br />
So what is a good way to formulate turning a define in to an idiomatic way to test this in C++?<br />
<br />
One can do this in a header:<br />
<br />
<br />
<pre class="brush:cpp;">enum BuildType
{
#ifndef NDEBUG
isRelease = 0,
isDebug = 1
#else
isDebug = 0,
isRelease = 1
#endif
};
</pre>
<br />
<br />
And then in code check the condition like this:<br />
<br />
<br />
<pre class="brush:cpp;">void SomeFunction(int x)
{
...
if ( isDebug ) {
...
// extra debug checks
...
} else {
...
}
...
}
</pre>
<br />
<br />
Using an enum means that we don't need to create any variables to do this.<br />
<br />
Obviously you can extrapolate this to testing for things besides debug/release. Also in the place where we declare the enum, if wanting to make it a runtime setting, instead of compile time setting, it becomes quite trivial to change that.
<br />
Where this doesn't work so well is if using #ifdef to choose between two options that will either work or not depending on the compiler or target platform, eg if one side is iOS code and the other Win32 code, obviously it may not be worth making the compiler able to accept both sides of the #if/#else. I believe in these cases where you have platform specific code, generally you want to hide that from the generic code and abstract the platform code and put platform specific implementations in their own separate files.
jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-44236145056856803242011-09-06T03:50:00.000-07:002011-09-06T03:50:47.995-07:00Hiring StaffThere is a subtle or perhaps not so subtle distinction between "hiring staff / adding people" and "building a team".<br />
<br />
I'm sure this doesn't just apply to software development teams but a broad range of areas. I guess you can just get a bunch of brilliant people and throw them together and hope for the best. You might get lucky. What I'm about to say I think many people should get if they have experienced working in a few different teams, so this blog is just for those that aren't quite up to speed with the distinction between "building a team" and "adding some new staff".<br />
<br />
If you think about winning sports teams, it's not entirely a sum of the talent of each individual of the team that determines the result (in team oriented sports), but rather the way they work together as a team combined with what talents they bring in combination. In all A-league teams, I'm not saying the players can be B or C grade players and the team can win, the players do need to be top class, but might not all be the best within that class if they work harmoniously with the group as a whole to bring about a win.<br />
<br />
The criteria for hiring someone should include their ability to do the job they are hired to do. That much should be obvious. But when selecting between candidates that can fulfill the basic requirements, I believe one should look to the candidate's ability to blend and complement the existing team and to compare that between the candidates. (hopefully with any luck you will have more than one candidate that fulfills the basic requirements of doing the job).<br />
<br />
So how to test or evaluate the ability for the candidate to blend? Simply invite them to join in on a team activity. If the team has lunch together, invite them along to lunch. Ask them to sit in on a team meeting, or perhaps on Friday evenings the team gather for snacks and chatting before heading home, perhaps time the interview at a time to precede such an activity and ask if they mind staying for that if you feel the candidate is someone potentially worth hiring.<br />
<br />
The idea is to disarm the candidate to feel relaxed enough to reveal more of the real them. Interviews are usually quite artificial situations. The idea is to step out from that and observe the way the candidate interacts with others in a more natural/genuine environment/situation. Then it will be possible to also ask the existing team what they think about the potential new person at a later time.<br />
<br />
I can hear some saying/thinking "but we don't have any activity like that, what do we do, everyone has lunch separately and goes home early on a Friday evening". To which I would say that it doesn't sound like much of a team environment. Sounds like there are bigger problems to resolve before adding more people in to the mix. Perhaps adding staff is trying to solve the problem of poor efficiency with more hands on deck however often adding people causes initial inefficiencies and diminishing returns as the number of interacting staff increases. New trainees drag down the existing team with questions and effort getting them up to speed. Adjusting to a new team dynamic which is upset with the changing of staff is another factor. And there is a diminishing return as the amount of communication exponentially increases with the numbers of staff interacting.<br />
<br />
Just to simply make the point if it is not clear, if it wasn't so, any project with say 5 people that takes 12 months if there was no diminishing return on more people on the project would take 10 people 6 months, 20 people 3 months, 40 people 1.5 months, 120 people 2 weeks, 240 people 1 week, 1280 people 1 day, etc. Unfortunately reality doesn't work that way, communication and coordinating over 1000 people to come together and do some task on a given day and divide the task up so the 1000 people don't spend as much time communicating with the 999 other people to ensure they do the right 0.1% of the task will take more than a day. Probably much more than a day just figuring all that out. And that's assuming a task that can be divided in to 1000 non-dependent little bits which is rarely if ever the case.<br />
<br />
Building a team also involves getting the team to do stuff together. Perhaps in some work environments it is not necessary to have a team, it really is just a set of individual efforts. I can't really think of any real concrete examples where a company is formed and contains a set of non-cooperating individuals. It's kind of not really a company, if everyone's job is unrelated to each others, then surely they don't require being a member of a company and could each operate as individuals, eg as sole proprietors. However that sounds rather lonely. Having positive social interactions is an important aspect of a job and working with others and getting stuff done.<br />
<br />
So what it comes down to is getting stuff done, and getting it done efficiently. When the team is working well together like a well oiled machine, stuff gets done, it's enjoyable and a positive environment. When there isn't any cohesion in the team, no one gets along, interactions are negative, it greatly impacts on getting stuff done. That is the bottom line.<br />
<br />
Usually the idea of adding more staff is to get more stuff done. If you are in agreement with that statement then I hope I can finish here for you. Sometimes it's to build an empire for the aggrandizement of someone with ego issues in which case I guess the idea of "building a team" must seem like a strange concept when the idea of "adding staff" fulfills faster the aim of building an empire. If this is you, keep reading. Even empires can crumble, particularly when there is rebellion. You still need relatively happy workers to build an empire. I do think most people prefer being in situations with positive social interactions over negative ones or over having a lack of human interaction for prolonged periods so I think most people want to belong to a productive working team, rather than simply a minion for the aggrandizement of an ego maniac running around pretending to look busy. Even if empire building, you need to create a cohesive group, infuse culture, create positive attitudes, promote a rewarding and productive environment all to keep the empire from rebellion.jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-31857944974375790432010-11-26T14:25:00.000-08:002010-11-26T14:25:16.052-08:00Good practise in use of source code controlGenerated files<br />
<br />
Never check-in generated files, period. I mean it. I hope by the end of the article you will be convinced too. Really there should never be a need for revisioning of a generated file. You are doing it all wrong if you think you need to. It means you don't understand what SOURCE CODE control is, I'll spell it out, it is for SOURCE material. I'm not saying you can't save those generated files somewhere for later use (ie a file server that has backups), but they shouldn't need revision control because it is not logical to have different versions of something that was generated from source material unless there is a change or different version of the corresponding source material or scripts used to generate it. A source code control or revisioning system is not a backup system, don't abuse it for this. More on this later.<br />
<br />
The source material needs versioning. Sure, if you recompile the same code 20 times you could get 20 different binaries if you do a binary diff, things like the date and time can work their way in to the binary, as too can the path from which the code was compiled depending on the compiler and flags. Which OS, compiler, version and flags was used will all have an effect. But really the scripts and makefiles used to control the compiling of the source code should be under source code control. The generated file that you were going to checkin really should be replaced with a script or equivalent that will check the pre-conditions and then run the precise commands with the precise flags that will result in that generated file being created. It should be reproducible, so there should be no need to check that generated file in. If it is not then you are doing something wrong. It might mean there is too much magic involved to reproduce compiling that code properly. That is a problem, it's a symptom that you might be doing something wrong. It might be someone wants to exercise some control over other developers or prevent others from compiling their code such that they must use their generated binaries that are checked in instead of everyone compiling from source. This means something is wrong. <br />
<br />
Either the code is fragile, brittle and breaks easily or someone is trying to hide something or trying to protect their job or some combination of these. <br />
<br />
It's not the way it should be. The code will only get better with more people compiling it and trying it with different compilers and different flags. Any code that needs a specific compiler on a particular persons computer compiled in some specific way with the magic scripts only on their computer or that only work on one persons computer setup or with some tool with restrictive licensing sounds like some funky shit that smells like something is off and you want to stay away from it because it will be a liability to you and your company. If the code you work on gets a dependency to such code, you'll be making yourself reliant on someone else, you will be giving them more power, feeding the beast. Work around the dependency, find alternatives, or try to work out the magic, ask to watch it get built. One does need to be pragmatic too, sometimes there might be no way around using critical 3rd party libraries. Obviously some stuff like Win32 API DLL dependencies can't be avoided on the windows platform, but there is a reasonable assumption MS and the DLLs won't disappear suddenly and there are alternatives like WINE that if MS went bust or decided to go 64bit only, there are fallbacks. Another strategy is design the code to be cross-platform in the beginning so no dependency on any particular OS or OS vendor. That's part of the problem of checking in generated binary files without a means to re-generate them, it limits the OS, toolchain, flags etc to just the set for which binaries were made available. Going cross-platform removes dependencies and gets developers in the mind-set of thinking about their dependencies. It's too bad that too often dependencies are only given thought after the fact when some code that works on one platform suddenly has a need to also work on other platforms. All those dependencies become painfully obvious. Digging around for a developer's old computer that worked at the company 5 years ago for his special tool he wrote in .NET that did some funky code generation for which the code to the tool wasn't checked in, only the generated code was, sounds like no one thought about the right source code control disciplines back then but now it is being paid for. <br />
<br />
Merge vs exclusive check-out<br />
<br />
Exclusive check-out model doesn't work. one user is working on something and needs other person to finish with their lock on the file. If in the office, they can just ask the person to check it in, but if that person is away, they might be stuck until they check-in their work, or they continue working in some compromised way. It just doesn't scale. Logically thinking about it and imagining if the locking was more granular down to function level or line level, one may be able to see some of the problems with the model, some concurrent changes between versions at the line or function level between users can create a non-working build. One really needs to check that the combination of changes, including the latest changes they have made and others have made, will work in combination. The exclusive check-out model doesn't magically solve that, it doesn't prevent incompatible changes happening concurrently to different files. I might remove all calls to a functions in all the code and then prepare to do the final step of removing the implementation of that function from the .h and .c files while simultaneously somewhere in the code (could be any file in the project) someone checks-in a change to call that function. The only way to prevent this is to check-out every file in the project and also lock other users from adding any files so they can't add a call to the function I am about to remove. Obviously one still needs to test the combination of the changes and correct for such types of problems when files are checked-in simultaneously. This really is a merge of sorts, but the granularity is different and the conflict is harder to detect, it's not really detected by the versioning software at all, its something that gets found by testing the latest code from the repository by compiling it and running it. Nothing substitutes testing, the versioning software can not solve incompatible changes. No, the real solution is to mark versions as working, merge in sets of changes, test the merged results, version it etc. And really the best is when the testing can be automated, but that is not always possible. There really is no merge free solution when you understand that every change needs to be checked it is compatible with all previous changes, irrespective of if it is in the same file or from a different file to one that has recently changed.<br />
<br />
Exclusive check-out is really annoying too when also checking in generated files. That has to be the worst possible thing to do. When recompiling or doing anything that causes the generated files to change, the compile can fail because it can't overwrite the read-only generated file, or it automatically checks it out which blocks others compiling. It just causes all kinds of blocking or further bad practices with kludging the file permissions. It is just horrible.<br />
<br />
Working with checked in generated files instead of generating them when the source is available is bad. It's worse when the source was available and someone takes it out of the repository to prevent others compiling it and just leaving the binaries and headers there to link with. How do people seriously think that is progress?<br />
<br />
Particularly if they are compiled with one version of the toolchain, like VS9, it then forces everyone to switch to VC9 and can't do VC6 builds anymore even if there is some need to do so. Code would be better if it is compiled and tested with more toolchains. It stops compiling the code in other configurations, eg with flags for MBCS or UNICODE etc particularly if the API is not well written, it then can force the calling code that links with the checked in binary that was compiled in a particular way to also have to be compiled in the same way to be compatible with how the API was defined and the mangled types in the function symbols of the binary to get correct linkage with it. It then sucks more when other binaries are checked in that were compiled in incompatible ways also with similar braindead APIs. It may prevent the 2 libraries being used together with one application.<br />
<br />
While the root of the problem is not just the use of the source code control system, it would be have been possible to generate the binaries as required in the correct form if the generated binaries weren't checked-in and things would be much nicer, one could make different versions of the binaries that one requires rather than being told how the binary should be generated with it in some fixed forms.<br />
<br />
The term "source code control" is bad. It uses the word "control", which is I guess is how some people use it. But i think that's part of the problem. <br />
<br />
People use it as a tool of power and control. It shouldn't be a restrictive system to inhibit changes or access. The real problem that needs solving is the one of versioning, what is needed is being able to mark versions of the software and to manage concurrent versions, merge them, branch etc. <br />
<br />
Not a centralized control system. Of course with decentralized systems, there is the question of backups. And source code control/versioning systems are that, not backup systems.<br />
<br />
Backup-proxy<br />
<br />
Please stop using the repository as a backup system. Perhaps that is why there are all the generated files checked in? Maybe that is why the server is grinding to a halt and can't handle the load of the repository? Maintaining file histories of big binary files that change nearly completely each version is not really what source code control or versioning systems are designed to handle. Smart ones detect binary files and store them differently, but can seriously bloat the store. Normally version control systems store a series of diffs, either forward or backward or both. So there might be the earliest and latest version of the file stored, and a set of differences that you can apply to get to any other version of that file. That works great for most text based files, but falls apart completely for binary files. In the case of binary files which are usually lots bigger to begin with, the repository generally needs to store a complete copy of every version of that file. Rarely it makes much sense to do a diff between 2 big binary files. Most of the time when checking out the generated files, we would be interested in the latest version of the generated file if we were at all interested in checking out generated files.<br />
<br />
VirtualMachines<br />
<br />
Using a VirtualMachine is not an excuse to avoid using source code control. Don't just make backups of the virtual machine to a multi-spanning DVD collection.<br />
Try to make the steps to setup the virtual machine repeatable or document it. VMWare and VirtualBox are scriptable, please check out the commandline commands.<br />
When setting up the virtual machine, try to do that with scripts that can be version controlled.<br />
Any files created and being edited inside the virtual machine are likely candidates to be version controlled too.<br />
Preferably use a version control system that is cross-platfom supporting the host and client OSes of the VirtualMachine, but failing that, most <br />
<br />
VirtualMachine applications and client OSes have means to share folders with the host OS which would made it possible to use the versioning control software from the host to version control the files being edited in the VM. Don't be lazy, using a VirtualMachine is not an excuse or easy way out, far from it, doing it right is hard work.<br />
<br />
Best practice<br />
1) never check-in anything generated. Make the steps to generate the output automated and as reproducible as possible<br />
2) never modify generated files unless done via an automated process<br />
3) do check-in the scripts and files that are part of the automated processes for generating the output<br />
4) do check-in and automate anything related to setting up the assumed environment, other than what might be the companies standard developer machine setup, under which development happens<br />
5) before check-in/commit changes, check-out the latest and merge changes, test, then repeat, then check-in when ready<br />
6) don't use the repository as a backup location (find alternative and more direct means of doing backups, eg if save binary builds of past version, send them to a network drive in dated folders that will get backed up, not use the repo as a backup proxy, it's not designed for that)<br />
7) do ensure there are backups of the source code control system, preferably there are backups of the repo stored off-sitejrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0tag:blogger.com,1999:blog-3333417017043522451.post-37628269749312381532010-11-23T09:44:00.000-08:002015-09-28T04:25:27.356-07:00Artifacts of Good Code<a href="http://dictionary.reference.com/browse/artifact">An artifact</a> is defined by one meaning as "<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">any</span> <span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">feature</span> <span id="hotword" name="hotword">that</span> <span id="hotword" name="hotword">is</span> <span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">not</span> <span id="hotword" name="hotword">naturally</span> <span id="hotword" name="hotword">present</span> <span id="hotword" name="hotword">but</span> <span id="hotword" name="hotword">is</span> <span id="hotword" name="hotword">a</span> <span id="hotword" name="hotword">product</span> <span id="hotword" name="hotword">of</span> <span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">an</span> <span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">extrinsic</span> <span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">agent,</span> <span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">method,</span> <span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">or</span> <span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">the</span> <span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">like...". I'm interested in the method of coding. When coding, the obvious output or product is the code itself. But I want to talk about some of the other products of good coding.</span></span><br />
<br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">If the code compiles, the binary output. The compiler messages during compilation. But these are products of compiling, not so much coding.</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;"><br />
</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">When you see good code you often know it. It looks inviting. It draws you in and lets you play with it.</span></span><br />
<br />
The kind of characteristics or products of good coding I want to talk about are what you often see when you find good code, they are correlated but I am not claiming or trying to prove causality. They are indicators. Think of it like trying to judge the appearance of the inside of someone's house by looking at their yard. Well trimmed plants, neat lawn, no weeds.<br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;"><br />
</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">So what kind of things might be in the yard of a piece of code. Some obvious things are documentation, test cases, a specification and/or requirements and/or user stories, bug tracking, use of a source code versioning system etc. Not all code has any or all of these things, but my observation is that more mature code tends to have most of these things.</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;"><br />
</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">Lets look at why. A number of these artifacts are to facilitate more than one person working on the code. They are a sign that the code wasn't developed by a single developer. More heads are better than one. It's immediately a good sign that the code hasn't been just looked at by one person, several people working on it means some review from different perspectives. It's like a house with a single occupant vs a share house.</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;"><br />
</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">Anyway we were talking about code. If the code is occupied by a few coders, some things probably will happen. Firstly some kind of source code versioning system if it isn't already being used will be introduced. It's quite hard without such systems for several people to work on the same code at the same time and expect anything to work without some kind of versioning system to mark a working version and way to combine the contributions of the coders to make and mark newer versions. Even if one person was writing the code alone, marking working versions and being able to go backwards and forwards between versions of the code is very useful, but it becomes much more necessary when several people start working on it.</span></span><br />
<br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">Often the next thing that happens when more and more people start working on the code and using it is the need for documentation. The original author knew what the function or module was meant to do and what its limitations might be by design, but if the code doesn't do what was meant or the original limitations are not sufficient or assumptions about the limitations were wrong, then without documentation its hard for others to work with or use that code. One can't change or fix a function without knowing properly what the function is intended to correctly do. That needs documenting so one can verify the implementation of the class/module/function does what is intended and the uses of it are using it as intended.</span></span><br />
<span name="hotword" style="background-color: transparent; cursor: default;"><br /></span>
<span name="hotword" style="background-color: transparent; cursor: default;">Functions shouldn't be so complicated that the intention of what they do is hard to describe, so good code tends to have nicely named functions/classes/modules too. Good code uses sensible descriptive but concise naming of functions and variables. It shows thought went in to the slicing of the program in to functions in a logical way. Hair-brained code is easy to spot, just take a sample of some of the function/class names and if you can't really guess from the name what it does, it's probably because it's a function or class that is ill defined and conceived and exists to factorize the code a certain way that isn't well aligned with any semantic meaning. Another sign of this is many functions with very similar names doing almost the same thing but with very minor variations (I mean besides operator overloading convenience functions to pass in different types). Having 10 different functions to query the same value but in different ways is a bad sign. It is probably the result of insufficient documentation because as more coders worked on something, the lack of documentation resulted in more functions added that did similar things because the original functions weren't documented about their intentions and resultantly became hard to modify and the uses of those functions were too fragile to changes in the function that new coders created new similar functions to avoid the fragility breaking everything. You can more confidently fix a broken implementation of a given API if you know what the intent is from the documentation, and then it is the callers that are broken if they depended on the broken implementation. Without good API documentation you can not make this judgement as easily.</span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;"><br />
</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">Someone on a project like this (perhaps one of the original coders if they are still around) will eventually notice how brain-dead it is all becoming. Perhaps something happens that brings to a front that the code was not documented so there was no way to know how it should have behaved compared to how the function actually behaved. Then begins the task of documenting. It's always interesting watching coders forced to write documentation for old crufty code they didn't originally write. Okay, next someone introduces a policy about swear words in the documentation, and then down a road of policies. But the point is, documentation is a sign of good code because it signifies that someone at sometime has had to stop and think for a moment about, what does this function do, what might be the limitations, what are the inputs, what are the outputs. And they'll look at the function name and hopefully stop to consider the design of it.</span></span><br />
<br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">It's okay to document what a function is intending to do, it's another thing altogether to actually check it does what it intends to. That's what testing does. Having test cases is how one does that. Without testing, there is no way to really know that something does as intended. Tests don't need to be automated, but automated is better for lots of cases. Unit tests can test at a fine grained level, but any testing and test case is a start and a good sign that someone is trying to check that something does what it's meant to do. If given code with no test cases, no sample input files, no examples, it's a sign that the code might not be tested to do what is intended for it to do. Having unit tests or various test cases is going to make it heaps easier for the coders to fix bugs and get the code doing what it's documented it should do, so it's a good sign that the code is or on it's way to doing what it is documented to do.</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;"><br />
</span></span><br />
<span id="hotword"><span id="hotword" name="hotword" style="background-color: transparent; cursor: default;">Requirements or user stories are a step up from checking the code is doing what was intended, they check what the intentions of the code should be. That might evolve (or devolve) over time, but so too should the user stories or requirements. They are a statement about what is the need for the software, what purpose will it fulfil, it gives the context and meaning to the software. It doesn't turn the code in to good code, but if the code doesn't have a context and meaning then the coders might be producing something that will have little value to anyone but maybe themselves.</span></span><br />
<br />
So these are some of the obvious ways to identify that potentially some good coding might be going on making some good code. Obviously in a company setting it is possible for managers to require that "software engineers" must use/produce the above mentioned artifacts as standard (but then they are no longer really by-products of good coding, they have been made in to the products of the output of the workers). This is a kind of cargo cult way of doing things (google cargo cult is you haven't heard of this before). This is not the way to "inspired code". In later blogs I want to write about other signs that code is good, or even inspired, not just some cargo cult coding dressing it up to look like good code.jrylandhttp://www.blogger.com/profile/02875370374934809514noreply@blogger.com0