\hypertarget{iterators_8h}{}\doxysection{kblib/iterators.h File Reference} \label{iterators_8h}\index{kblib/iterators.h@{kblib/iterators.h}} This file provides some iterators, ranges, iterator/range adapters, and operations that can be performed on iterators or smart pointers. {\ttfamily \#include \char`\"{}enumerate-\/contrib-\/cry.\+h\char`\"{}}\newline {\ttfamily \#include \char`\"{}enumerate-\/contrib-\/tw.\+h\char`\"{}}\newline {\ttfamily \#include \char`\"{}fakestd.\+h\char`\"{}}\newline {\ttfamily \#include \char`\"{}traits.\+h\char`\"{}}\newline {\ttfamily \#include $<$cassert$>$}\newline {\ttfamily \#include $<$iterator$>$}\newline {\ttfamily \#include $<$vector$>$}\newline {\ttfamily \#include $<$optional$>$}\newline Include dependency graph for iterators.\+h\+:\nopagebreak \begin{figure}[H] \begin{center} \leavevmode \includegraphics[width=350pt]{iterators_8h__incl} \end{center} \end{figure} This graph shows which files directly or indirectly include this file\+:\nopagebreak \begin{figure}[H] \begin{center} \leavevmode \includegraphics[width=350pt]{iterators_8h__dep__incl} \end{center} \end{figure} \doxysubsection*{Classes} \begin{DoxyCompactItemize} \item struct \mbox{\hyperlink{structkblib_1_1to__pointer__impl}{kblib\+::to\+\_\+pointer\+\_\+impl$<$ ptr $>$}} \item struct \mbox{\hyperlink{structkblib_1_1to__pointer__impl_3_01_t_01_5_01_4}{kblib\+::to\+\_\+pointer\+\_\+impl$<$ T $\ast$ $>$}} \item struct \mbox{\hyperlink{structkblib_1_1is__output__iterator__for}{kblib\+::is\+\_\+output\+\_\+iterator\+\_\+for$<$ T, E, typename $>$}} \begin{DoxyCompactList}\small\item\em Determine if T is a valid output iterator to which values of type E may be written. \end{DoxyCompactList}\item struct \mbox{\hyperlink{structkblib_1_1is__output__iterator__for_3_01_t_00_01_e_00_01void__t_3_01decltype_07_5std_1_1dec93bfaad0990f9bf6c57857b906bb5af3}{kblib\+::is\+\_\+output\+\_\+iterator\+\_\+for$<$ T, E, void\+\_\+t$<$ decltype($\ast$std\+::declval$<$ T \& $>$()++=std\+::declval$<$ const E \& $>$())$>$ $>$}} \item class \mbox{\hyperlink{classkblib_1_1counting__back__insert__iterator}{kblib\+::counting\+\_\+back\+\_\+insert\+\_\+iterator$<$ Container $>$}} \begin{DoxyCompactList}\small\item\em Like a std\+::back\+\_\+insert\+\_\+iterator, but it keeps track of how many insertions it has made, allowing an end iterator to be created. \end{DoxyCompactList}\item struct \mbox{\hyperlink{structkblib_1_1counting__back__insert__iterator_1_1proxy__iterator}{kblib\+::counting\+\_\+back\+\_\+insert\+\_\+iterator$<$ Container $>$\+::proxy\+\_\+iterator}} \item class \mbox{\hyperlink{classkblib_1_1range__t}{kblib\+::range\+\_\+t$<$ Value, Delta $>$}} \begin{DoxyCompactList}\small\item\em A range generator, similar to Python 3\textquotesingle{}s \mbox{\hyperlink{namespacekblib_a72690688922a2d4ae9a3e46ff0c1a9a9}{range()}}. \end{DoxyCompactList}\item struct \mbox{\hyperlink{structkblib_1_1range__t_1_1iterator}{kblib\+::range\+\_\+t$<$ Value, Delta $>$\+::iterator}} \begin{DoxyCompactList}\small\item\em A helper struct which acts as an iterator for the range elements, as they are generated on the fly. \end{DoxyCompactList}\item struct \mbox{\hyperlink{structkblib_1_1detail__iterators_1_1is__addable}{kblib\+::detail\+\_\+iterators\+::is\+\_\+addable$<$ T, U, typename $>$}} \item struct \mbox{\hyperlink{structkblib_1_1detail__iterators_1_1is__addable_3_01_t_00_01_u_00_01void__t_3_01decltype_07std_154f3f86b521bad5734a3fe6bbf63c54f}{kblib\+::detail\+\_\+iterators\+::is\+\_\+addable$<$ T, U, void\+\_\+t$<$ decltype(std\+::declval$<$ T \& $>$()+std\+::declval$<$ U \& $>$())$>$ $>$}} \item struct \mbox{\hyperlink{structkblib_1_1adjuster}{kblib\+::adjuster}} \item struct \mbox{\hyperlink{structkblib_1_1incrementer}{kblib\+::incrementer}} \begin{DoxyCompactList}\small\item\em A struct which increments anything it is added to. Suitable for use as a Delta type for \mbox{\hyperlink{classkblib_1_1range__t}{range\+\_\+t}}. \end{DoxyCompactList}\item struct \mbox{\hyperlink{structkblib_1_1decrementer}{kblib\+::decrementer}} \begin{DoxyCompactList}\small\item\em A struct which decrements anything it is added to. Suitable for use as a Delta type for \mbox{\hyperlink{classkblib_1_1range__t}{range\+\_\+t}}. \end{DoxyCompactList}\item class \mbox{\hyperlink{classkblib_1_1irange__t}{kblib\+::irange\+\_\+t$<$ Value, Delta $>$}} \item struct \mbox{\hyperlink{structkblib_1_1detail__enumerate_1_1force__copy__tag}{kblib\+::detail\+\_\+enumerate\+::force\+\_\+copy\+\_\+tag}} \item class \mbox{\hyperlink{classkblib_1_1enumeration}{kblib\+::enumeration$<$ T $>$}} \item class \mbox{\hyperlink{classstd_1_1tuple__size_3_1_1kblib_1_1enumeration_3_01_t_01_4_01_4}{std\+::tuple\+\_\+size$<$\+::kblib\+::enumeration$<$ T $>$ $>$}} \item class \mbox{\hyperlink{classstd_1_1tuple__element_3_010_00_01_1_1kblib_1_1enumeration_3_01_t_01_4_01_4}{std\+::tuple\+\_\+element$<$ 0, \+::kblib\+::enumeration$<$ T $>$ $>$}} \item class \mbox{\hyperlink{classstd_1_1tuple__element_3_010_00_01volatile_01_1_1kblib_1_1enumeration_3_01_t_01_4_01_4}{std\+::tuple\+\_\+element$<$ 0, volatile \+::kblib\+::enumeration$<$ T $>$ $>$}} \item class \mbox{\hyperlink{classstd_1_1tuple__element_3_010_00_01const_01volatile_01_1_1kblib_1_1enumeration_3_01_t_01_4_01_4}{std\+::tuple\+\_\+element$<$ 0, const volatile \+::kblib\+::enumeration$<$ T $>$ $>$}} \item class \mbox{\hyperlink{classstd_1_1tuple__element_3_011_00_01volatile_01_1_1kblib_1_1enumeration_3_01_t_01_4_01_4}{std\+::tuple\+\_\+element$<$ 1, volatile \+::kblib\+::enumeration$<$ T $>$ $>$}} \begin{DoxyCompactList}\small\item\em references keep the same qualifications as the original \end{DoxyCompactList}\item class \mbox{\hyperlink{classstd_1_1tuple__element_3_011_00_01const_01volatile_01_1_1kblib_1_1enumeration_3_01_t_01_4_01_4}{std\+::tuple\+\_\+element$<$ 1, const volatile \+::kblib\+::enumeration$<$ T $>$ $>$}} \begin{DoxyCompactList}\small\item\em but you can also add const to a reference \end{DoxyCompactList}\item class \mbox{\hyperlink{classstd_1_1tuple__element_3_011_00_01_1_1kblib_1_1enumeration_3_01_t_01_4_01_4}{std\+::tuple\+\_\+element$<$ 1, \+::kblib\+::enumeration$<$ T $>$ $>$}} \begin{DoxyCompactList}\small\item\em copies decay away the const \end{DoxyCompactList}\item class \mbox{\hyperlink{classstd_1_1tuple__element_3_011_00_01const_01_1_1kblib_1_1enumeration_3_01_t_01_4_01_4}{std\+::tuple\+\_\+element$<$ 1, const \+::kblib\+::enumeration$<$ T $>$ $>$}} \begin{DoxyCompactList}\small\item\em unless const is explicitly added \end{DoxyCompactList}\item class \mbox{\hyperlink{classkblib_1_1enumerator__iterator}{kblib\+::enumerator\+\_\+iterator$<$ It $>$}} \item class \mbox{\hyperlink{classkblib_1_1enumerator__t_3_01_range_00_01void_01_4}{kblib\+::enumerator\+\_\+t$<$ Range, void $>$}} \item class \mbox{\hyperlink{classkblib_1_1enumerator__t}{kblib\+::enumerator\+\_\+t$<$ It, End\+It $>$}} \item struct \mbox{\hyperlink{structkblib_1_1indirect__range}{kblib\+::indirect\+\_\+range$<$ Iter1, Iter2 $>$}} \begin{DoxyCompactList}\small\item\em Allow range-\/for iteration of an iterator pair. \end{DoxyCompactList}\item class \mbox{\hyperlink{classkblib_1_1multi__range}{kblib\+::multi\+\_\+range$<$ Iter1, End\+Iter, count $>$}} \item class \mbox{\hyperlink{classkblib_1_1multi__range_3_01_iter1_00_01_end_iter_00_010_01_4}{kblib\+::multi\+\_\+range$<$ Iter1, End\+Iter, 0 $>$}} \item struct \mbox{\hyperlink{structkblib_1_1containing__ptr}{kblib\+::containing\+\_\+ptr$<$ T $>$}} \begin{DoxyCompactList}\small\item\em A smart pointer to an object contained inside the smart pointer object. \end{DoxyCompactList}\item class \mbox{\hyperlink{classkblib_1_1transform__iterator}{kblib\+::transform\+\_\+iterator$<$ base\+\_\+iterator, operation $>$}} \begin{DoxyCompactList}\small\item\em An Input\+Iterator that applies a transformation to the elements of the range. \end{DoxyCompactList}\item struct \mbox{\hyperlink{structkblib_1_1zip__iterator}{kblib\+::zip\+\_\+iterator$<$ Input\+It1, End\+It, Input\+It2 $>$}} \item struct \mbox{\hyperlink{structkblib_1_1zip__iterator_3_01_it1_00_01_it1_00_01_it2_01_4}{kblib\+::zip\+\_\+iterator$<$ It1, It1, It2 $>$}} \item class \mbox{\hyperlink{classkblib_1_1adjacent__iterator}{kblib\+::adjacent\+\_\+iterator$<$ Forward\+It, End\+It $>$}} \begin{DoxyCompactList}\small\item\em TODO(killerbee13)\+: Implement \mbox{\hyperlink{classkblib_1_1adjacent__iterator}{adjacent\+\_\+iterator}}. \end{DoxyCompactList}\item class \mbox{\hyperlink{classkblib_1_1back__insert__iterator___f}{kblib\+::back\+\_\+insert\+\_\+iterator\+\_\+\+F$<$ Container, F $>$}} \begin{DoxyCompactList}\small\item\em An Output\+Iterator that transforms the values assigned to it before inserting them into the back of a container. \end{DoxyCompactList}\item class \mbox{\hyperlink{classkblib_1_1consume__iterator}{kblib\+::consume\+\_\+iterator$<$ F $>$}} \begin{DoxyCompactList}\small\item\em An Output\+Iterator that simply calls a provided functor for each value assigned to it. \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsection*{Namespaces} \begin{DoxyCompactItemize} \item namespace \mbox{\hyperlink{namespacekblib}{kblib}} \begin{DoxyCompactList}\small\item\em The main namespace in which all entities from kblib are defined. \end{DoxyCompactList}\item namespace \mbox{\hyperlink{namespacekblib_1_1detail__iterators}{kblib\+::detail\+\_\+iterators}} \item namespace \mbox{\hyperlink{namespacekblib_1_1detail__enumerate}{kblib\+::detail\+\_\+enumerate}} \item namespace \mbox{\hyperlink{namespacestd}{std}} \end{DoxyCompactItemize} \doxysubsection*{Functions} \begin{DoxyCompactItemize} \item {\footnotesize template$<$typename P $>$ }\\constexpr auto \mbox{\hyperlink{namespacekblib_a1c2aa67048789f77bea56734a583d3d1}{kblib\+::to\+\_\+pointer}} (P \&\&p) noexcept -\/$>$ auto $\ast$ \begin{DoxyCompactList}\small\item\em Gets a raw pointer out of any smart pointer or iterator you might pass in, without dereferencing it or relying on a \mbox{\hyperlink{namespacekblib_a951945f1ed7d42562a7e6fa8cf8f0405}{get()}} method. \end{DoxyCompactList}\item {\footnotesize template$<$typename Container , typename Comp = std\+::less$<$value\+\_\+type\+\_\+linear\+\_\+t$<$\+Container$>$$>$$>$ }\\auto \mbox{\hyperlink{namespacekblib_a7d43c2f73a1e2d35ca150b9ac3a43d58}{kblib\+::max\+\_\+element}} (Container \&c, Comp comp) -\/$>$ value\+\_\+type\+\_\+linear\+\_\+t$<$ Container $>$ $\ast$ \item {\footnotesize template$<$typename C $>$ }\\counting\+\_\+back\+\_\+insert\+\_\+iterator$<$ C $>$ \mbox{\hyperlink{namespacekblib_a459982020db617ac2a1dbd2c3e2345ea}{kblib\+::counting\+\_\+back\+\_\+inserter}} (C \&c, std\+::size\+\_\+t count=0) \item {\footnotesize template$<$typename T $>$ }\\constexpr auto \mbox{\hyperlink{namespacekblib_a5127cbe40846f5ab2a05694de92d3d2e}{kblib\+::operator+}} (T val, adjuster a) noexcept -\/$>$ enable\+\_\+if\+\_\+t$<$ not detail\+\_\+iterators\+::is\+\_\+addable$<$ T, std\+::ptrdiff\+\_\+t $>$\+::value, decltype(std\+::advance(val, a.\+adj))$>$ \item {\footnotesize template$<$typename T $>$ }\\constexpr auto \mbox{\hyperlink{namespacekblib_ab797e9d5c5989c277312518fc95667ae}{kblib\+::operator+}} (T val, incrementer) -\/$>$ T \begin{DoxyCompactList}\small\item\em Increments val. \end{DoxyCompactList}\item {\footnotesize template$<$typename T $>$ }\\constexpr auto \mbox{\hyperlink{namespacekblib_ab8c4154f71801dac0f43dcb2e1869e8b}{kblib\+::operator+}} (T val, decrementer) -\/$>$ T \begin{DoxyCompactList}\small\item\em Decrements val. \end{DoxyCompactList}\item {\footnotesize template$<$typename Value , typename Delta = int$>$ }\\constexpr auto \mbox{\hyperlink{namespacekblib_a72690688922a2d4ae9a3e46ff0c1a9a9}{kblib\+::range}} (Value min, Value max, Delta step=0) -\/$>$ range\+\_\+t$<$ Value, Delta $>$ \begin{DoxyCompactList}\small\item\em Constructs a range from beginning, end, and step amount. The range is half-\/open, that is min is in the range but max is not. If unspecified, the step is automatically either 1 or -\/1, depending on whether max \texorpdfstring{$>$}{>} min. \end{DoxyCompactList}\item {\footnotesize template$<$typename Value $>$ }\\constexpr auto \mbox{\hyperlink{namespacekblib_ac136a707b14a83235d82c267830f0cd9}{kblib\+::range}} (Value max) -\/$>$ range\+\_\+t$<$ Value, incrementer $>$ \begin{DoxyCompactList}\small\item\em Constructs a half-\/open range \mbox{[}0, max). The step is automatically determined based on the sign of max. \end{DoxyCompactList}\item {\footnotesize template$<$typename Value , typename Delta = int$>$ }\\constexpr auto \mbox{\hyperlink{namespacekblib_a75ac0367cce25b0498451e5e5c711297}{kblib\+::irange}} (Value, Value, Delta=0) \item {\footnotesize template$<$typename T1 , typename T2 $>$ }\\auto \mbox{\hyperlink{namespacekblib_1_1detail__enumerate_ac4e2d91f1419790b70ee4fcc9ba0fdff}{kblib\+::detail\+\_\+enumerate\+::get\+\_\+or}} (T1 \&\&t1, T2 \&\&t2) -\/$>$ decltype(auto) \item {\footnotesize template$<$typename T $>$ }\\auto \mbox{\hyperlink{namespacekblib_1_1detail__enumerate_a01999a441ce3915f1d6c2c85b6f650d4}{kblib\+::detail\+\_\+enumerate\+::get\+\_\+magic\+\_\+ptr}} () -\/$>$ T $\ast$ \item {\footnotesize template$<$std\+::size\+\_\+t I, typename T $>$ }\\auto \mbox{\hyperlink{namespacekblib_a554b8034891b88291ee4014c5618e41f}{kblib\+::get}} (enumeration$<$ T $>$ \&\&e) -\/$>$ decltype(auto) \item {\footnotesize template$<$std\+::size\+\_\+t I, typename T $>$ }\\auto \mbox{\hyperlink{namespacekblib_a41c0ca0fe1a53fd119fc343cf9a4040e}{kblib\+::get}} (const enumeration$<$ T $>$ \&\&e) -\/$>$ decltype(auto) \item {\footnotesize template$<$std\+::size\+\_\+t I, typename T $>$ }\\auto \mbox{\hyperlink{namespacekblib_a052e6c7d0944cda0ce9203c1036fc745}{kblib\+::get}} (volatile enumeration$<$ T $>$ \&e) -\/$>$ decltype(auto) \item {\footnotesize template$<$std\+::size\+\_\+t I, typename T $>$ }\\auto \mbox{\hyperlink{namespacekblib_a2888a4a5d49c15f73ced60c66c31dc15}{kblib\+::get}} (const volatile enumeration$<$ T $>$ \&e) -\/$>$ decltype(auto) \item {\footnotesize template$<$typename It , typename EIt $>$ }\\auto \mbox{\hyperlink{namespacekblib_a0084bbd67ea381c6954c3d82c3cd0691}{kblib\+::magic\+\_\+enumerate}} (It begin, EIt end) -\/$>$ enumerator\+\_\+t$<$ It, EIt $>$ \begin{DoxyCompactList}\small\item\em Allow access to indexes while using range-\/based for loops. \end{DoxyCompactList}\item {\footnotesize template$<$typename Range $>$ }\\auto \mbox{\hyperlink{namespacekblib_a5617b65c2a82a734f2095c16f00e316c}{kblib\+::magic\+\_\+enumerate}} (Range \&\&r) -\/$>$ auto \begin{DoxyCompactList}\small\item\em Allow access to indexes while using range-\/based for loops. Safe to use with rvalues. \end{DoxyCompactList}\item {\footnotesize template$<$typename Iter1 , typename Iter2 $>$ }\\constexpr auto \mbox{\hyperlink{namespacekblib_a893a2961c20b0657dffbbd2fe8f362c4}{kblib\+::indirect}} (Iter1 begin, Iter2 end) noexcept(noexcept(indirect\+\_\+range$<$ Iter1, Iter2 $>$\{begin, end\})) -\/$>$ indirect\+\_\+range$<$ Iter1, Iter2 $>$ \begin{DoxyCompactList}\small\item\em Create a range from an iterator pair. Primarily useful for range-\/for loops. \end{DoxyCompactList}\item {\footnotesize template$<$typename Iter1 , typename Iter2 $>$ }\\\mbox{\hyperlink{namespacekblib_adbf35ad5c1ebb477db462d817a1a03cc}{kblib\+::indirect\+\_\+range}} (Iter1, Iter2) -\/$>$ indirect\+\_\+range$<$ Iter1, Iter2 $>$ \item {\footnotesize template$<$typename Iter1 , typename Iter2 $>$ }\\auto \mbox{\hyperlink{namespacekblib_a77828de35fa34ad16a59080a4cf5ca91}{kblib\+::cry\+\_\+enumerate}} (Iter1 begin, Iter2 end) -\/$>$ auto \item {\footnotesize template$<$typename It , typename operation $>$ }\\\mbox{\hyperlink{namespacekblib_aa807d817e32edd6ed91e4f151dde9ae2}{kblib\+::transform\+\_\+iterator}} (It, operation) -\/$>$ transform\+\_\+iterator$<$ It, operation $>$ \item {\footnotesize template$<$typename base\+\_\+iterator , typename operation $>$ }\\auto \mbox{\hyperlink{namespacekblib_aed7bb6b5bb036248bdf3f0832e8404a8}{kblib\+::make\+\_\+transform\+\_\+iterator}} (base\+\_\+iterator it, operation op) noexcept(noexcept(transform\+\_\+iterator$<$ base\+\_\+iterator, operation $>$\{ it, std\+::move(op)\})) -\/$>$ transform\+\_\+iterator$<$ base\+\_\+iterator, operation $>$ \begin{DoxyCompactList}\small\item\em Factory function to make transform\+\_\+iterators. \end{DoxyCompactList}\item {\footnotesize template$<$typename base\+\_\+iterator , typename operation $>$ }\\auto \mbox{\hyperlink{namespacekblib_a05e897a858310bc166f65965eadf8f66}{kblib\+::transformer}} (base\+\_\+iterator it, operation op) noexcept(noexcept(transform\+\_\+iterator$<$ base\+\_\+iterator, operation $>$\{it, std\+::move(op)\})) -\/$>$ transform\+\_\+iterator$<$ base\+\_\+iterator, operation $>$ \begin{DoxyCompactList}\small\item\em Factory function to make transform\+\_\+iterators. \end{DoxyCompactList}\item {\footnotesize template$<$typename It , typename End\+It , typename operation $>$ }\\auto \mbox{\hyperlink{namespacekblib_a0f9b71b4a51492465cca27cdd0deeef6}{kblib\+::transform\+\_\+range}} (It begin, End\+It end, operation op) noexcept(noexcept(indirect(transform\+\_\+iterator\{begin, op\}, end))) -\/$>$ auto \item {\footnotesize template$<$typename Input\+It1 , typename End\+It , typename Input\+It2 $>$ }\\auto \mbox{\hyperlink{namespacekblib_a0768784de97af5384c76b4009f22fb31}{kblib\+::zip}} (Input\+It1 begin1, End\+It end1, Input\+It2 begin2) noexcept(zip\+\_\+iterator$<$ Input\+It1, End\+It, Input\+It2 $>$\+::is\+\_\+nothrow\+\_\+copyable) -\/$>$ zip\+\_\+iterator$<$ Input\+It1, End\+It, Input\+It2 $>$ \begin{DoxyCompactList}\small\item\em Iterate over two ranges in lockstep, like Python\textquotesingle{}s zip. \end{DoxyCompactList}\item {\footnotesize template$<$typename Range1 , typename Range2 $>$ }\\auto \mbox{\hyperlink{namespacekblib_af06b17342da0e55aff646066ce8c283d}{kblib\+::zip}} (Range1 \&\&r1, Range2 \&\&r2) noexcept(zip\+\_\+iterator$<$ decltype(begin(r1)), decltype(end(r1)), decltype(begin(r2))$>$\+::is\+\_\+nothrow\+\_\+copyable) -\/$>$ zip\+\_\+iterator$<$ decltype(begin(r1)), decltype(end(r1)), decltype(begin(r2))$>$ \begin{DoxyCompactList}\small\item\em Iterate over two ranges in lockstep, like Python\textquotesingle{}s zip. \end{DoxyCompactList}\item {\footnotesize template$<$typename F $>$ }\\auto \mbox{\hyperlink{namespacekblib_a18d941bdcaa41e86334ca14ffa954b28}{kblib\+::consumer}} (F f) -\/$>$ consume\+\_\+iterator$<$ F $>$ \begin{DoxyCompactList}\small\item\em Creates a \mbox{\hyperlink{classkblib_1_1consume__iterator}{consume\+\_\+iterator}} of deduced type F. \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsection{Detailed Description} This file provides some iterators, ranges, iterator/range adapters, and operations that can be performed on iterators or smart pointers. \begin{DoxyAuthor}{Author} killerbee \end{DoxyAuthor} \begin{DoxyDate}{Date} 2019-\/2021 \end{DoxyDate} \begin{DoxyCopyright}{Copyright} GNU General Public Licence v3.\+0 \end{DoxyCopyright} Definition in file \mbox{\hyperlink{iterators_8h_source}{iterators.\+h}}.