<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ola Sk</title>
    <description>The latest articles on Forem by Ola Sk (@olask).</description>
    <link>https://forem.com/olask</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F282307%2Fb007f098-24f3-48b0-bda3-6c2070d6e95c.png</url>
      <title>Forem: Ola Sk</title>
      <link>https://forem.com/olask</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/olask"/>
    <language>en</language>
    <item>
      <title>Database normalization may be harmful to efficiency on large scale analytics projects.</title>
      <dc:creator>Ola Sk</dc:creator>
      <pubDate>Sun, 05 Jan 2020 13:46:07 +0000</pubDate>
      <link>https://forem.com/olask/normalization-may-be-harmful-to-efficiency-on-large-scale-analytics-projects-2jb9</link>
      <guid>https://forem.com/olask/normalization-may-be-harmful-to-efficiency-on-large-scale-analytics-projects-2jb9</guid>
      <description>&lt;p&gt;If the select queries to your relational database return big tables, additionally if you used one or more join statement in that query, let me guess it wasn't quick process to fetch the resulting table. JOIN operation adds a computation step for each record fetched. They accumulate over the number of records, or rows, for which records from a linked table need to be fetched. The worse it gets, the more joins there are in the query. This results in a computational expense that you might avoid using denormalized table design.&lt;/p&gt;

&lt;p&gt;To decide which approach in a design to use to optimize the number of computations and the storage efficiency of your database, you need to consider the frequency of &lt;code&gt;update&lt;/code&gt; and &lt;code&gt;select&lt;/code&gt; operations and how many of them are going to result in queries returning a big number of records.&lt;/p&gt;

&lt;p&gt;If you do not perform any separate analysis on a certain feature of a dataset (contained in one column), so in other words, if that data has a secondary relevance, you may want to consider merging the column with some other column with similar characteristics. &lt;/p&gt;

&lt;p&gt;To back up the decision about merging/adding a summary column, consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;whether your data to merge do not change too frequently. UPDATE, just like SELECT queries have their prices in terms of the number of computations performed. You "pay" for both of them, either it's updating some columns in a database upon the change of value in another column or users of your database waiting longer for the queries to JOIN the pieces of data.&lt;/li&gt;
&lt;li&gt;one other thing to consider is the size of the pool of records that will usually gonna be returned from queries for analysis. You may want to think of any possible questions that may emerge and possible queries that may need to be performed in certain scenarios of analysis and consider the sizes of possible returns from those queries. If the data returned from most of the queries are gonna be big, you may save time for fetching records that are rather contained in a fewer number of cells that you do not need to JOIN before getting the results from RDBMS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To sum this up, choosing the design—deciding whether to merge columns / add a summary column (denormalization practices)—aims at minimizing the time of return from the query, which involves minimizing the number of computations needed. It comes down to a trade-off between normalized and denormalized design, that should be carefully chosen and be mainly determined by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the frequency of changes (UPDATE) in the data that involve computation if the table contains a summary column that needs to be updated along with a changing value in another column,&lt;/li&gt;
&lt;li&gt;and the sizes and frequency of, especially big, SELECT queries.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But here again, there usually are not many updates in analytical DBs specifically, so I conclude that this type of database may benefit hugely from careful denormalization.&lt;/p&gt;

</description>
      <category>database</category>
      <category>bigdata</category>
      <category>sql</category>
      <category>analysis</category>
    </item>
    <item>
      <title>Jason Turner's gift C++ tutorial for Christmas</title>
      <dc:creator>Ola Sk</dc:creator>
      <pubDate>Tue, 31 Dec 2019 20:13:54 +0000</pubDate>
      <link>https://forem.com/olask/jason-s-turner-gift-c-tutorial-for-christmas-1a4l</link>
      <guid>https://forem.com/olask/jason-s-turner-gift-c-tutorial-for-christmas-1a4l</guid>
      <description>&lt;p&gt;Jason Turner has hit a 200 informational videos on modern C++ features this Christmas season. He's a multiple time speaker at CppCon—the biggest C++ conference and does industrial trainings on C++. He just came up with a tutorial series on C++ available on his YouTube channel. I personally enjoy watching his C++ weekly series, but never am able to catch up will all the episodes anyway. I highly recommend any adept of programming in C++ to take a look and hopefully stay for longer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/3hGSlUGEXtA"&gt;https://youtu.be/3hGSlUGEXtA&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy learning.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>lambdas</category>
    </item>
    <item>
      <title>Books to understand Causal Inference and Structured Causal Modeling (SCM) from level ~0</title>
      <dc:creator>Ola Sk</dc:creator>
      <pubDate>Mon, 23 Dec 2019 19:06:25 +0000</pubDate>
      <link>https://forem.com/olask/what-is-it-required-to-understand-causal-inference-2n81</link>
      <guid>https://forem.com/olask/what-is-it-required-to-understand-causal-inference-2n81</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EvLsm1BZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/6016/0%2ApBV_CUr_y_GF3WHG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EvLsm1BZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/6016/0%2ApBV_CUr_y_GF3WHG" alt="Photo by [Campaign Creators](https://unsplash.com/@campaign_creators?utm_source=medium&amp;amp;utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral)" width="800" height="579"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I did some research and I’m coming to you with a few books that I found maybe the proper way to understand Causal Inference.&lt;/p&gt;

&lt;p&gt;The first introductory book would be: “An Introduction to Statistical Learning”. It’s a companion to the MOOC from Stanford, which offers it on its ‘lagunita’ platform along with a free certificate:&lt;/p&gt;

&lt;h2&gt;
  
  
  An Introduction to Statistical Learning
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.statlearning.com/"&gt;Free book in PDF format&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://lagunita.stanford.edu/courses/HumanitiesSciences/StatLearning/Winter2016/about"&gt;‘Statistical Learning’ MOOC on ‘lagunita&lt;/a&gt;’&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.goodreads.com/review/show/2745684471"&gt;Terran M’s Review&lt;/a&gt; on goodreads.com:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Adequate preparation for understanding “Principles and Practice of Structural Equation Modeling” would be a basic treatment of multivariate regression, such as &lt;a href="https://www.goodreads.com/book/show/737071.Data_Analysis_Using_Regression_and_Multilevel_Hierarchical_Models"&gt;Gelman and Hill&lt;/a&gt;. &lt;a href="https://www.goodreads.com/book/show/17397466.An_Introduction_to_Statistical_Learning_With_Applications_in_R"&gt;Introduction to Statistical Learning&lt;/a&gt; would also be sufficient. If you want to understand confirmatory factor analysis, you should probably already know something about factor analysis as well; I liked &lt;a href="https://www.goodreads.com/book/show/4116170.Factor_Analysis"&gt;Gorsuch&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Data Analysis Using Regression and Multilevel/Hierarchical Models
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;by &lt;a href="https://www.goodreads.com/author/show/334953.Andrew_Gelman"&gt;Andrew Gelman&lt;/a&gt;, &lt;a href="https://www.goodreads.com/author/show/341796.Jennifer_Hill"&gt;Jennifer Hill&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.goodreads.com/book/show/737071.Data_Analysis_Using_Regression_and_Multilevel_Hierarchical_Models"&gt;See on goodreads.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.goodreads.com/review/show/2803081152?book_show_action=true&amp;amp;from_review_page=1"&gt;A Mig’s review&lt;/a&gt; on goodreads.com&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A go-to book for multilevel modeling but far from my favorite books on statistics. First, one should pass all the sections on probability distributions and linear regression, since there is much better elsewhere on the same topic (and with R codes), such as &lt;a href="https://www.goodreads.com/book/show/17397466-an-introduction-to-statistical-learning?from_search=true"&gt;‘An Introduction to Statistical Learning: With Applications in R’&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Principles and Practice of Structural Equation Modeling, Fourth Edition
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.goodreads.com/review/show/2745684471"&gt;Terran M’s Review&lt;/a&gt; on goodreads.com:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is the correct first book to read on causal inference. It covers structural equation modeling (SEM), confirmatory factor analysis (CFA), and Pearl’s structured causal modeling (SCM).&lt;br&gt;
 Although this book claims to cover various software packages, the treatment is cursory and the code examples (online) are mostly uncommented; don’t expect to learn how to use the software from this book. Read this book for the principles and then also read the software manual for whatever tool you’re going to use.&lt;br&gt;
 Ironically, this book, whose title claims to be about SEM only, actually covers most of the modern causal inference, whereas Pearl’s book, with the grand title “Causality”, covers only his narrow work. This is definitely the one you want.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;For a brief introduction to using causal graphs to select your controls, see Chapter 17 of “Statistical Modeling — A Fresh Approach”. That chapter is available free from the author at &lt;a href="http://www.mosaic-web.org/go/StatisticalModeling/index-orig.html"&gt;http://www.mosaic-web.org/go/Statisti...&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For more about inferring causal graphs from the data, look for a series of papers by Colombo and Maathuis at ETH Zurich. Here are a couple of papers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://projecteuclid.org/euclid.aos/1431695638"&gt;https://projecteuclid.org/euclid.aos/...&lt;/a&gt;&lt;br&gt;
&lt;a href="https://projecteuclid.org/euclid.aos/1333567191"&gt;https://projecteuclid.org/euclid.aos/...&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These papers are also on ArXiv, and there are more from the same authors. Also, they wrote an R package:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cran.r-project.org/web/packages/pcalg/index.html"&gt;https://cran.r-project.org/web/packag...&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Elements of Statistical Learning: Data Mining, Inference, and Prediction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://web.stanford.edu/~hastie/ElemStatLearn/"&gt;https://web.stanford.edu/~hastie/ElemStatLearn/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The challenge of understanding vast amounts of data in a variety of fields such as medicine, biology, finance, and marketing has led to the development of new tools in the field of statistics and spawned new areas such as data mining, machine learning, and bioinformatics. Many of these tools have common underpinnings but are often expressed with different terminology. This book describes the important ideas in these areas in a common conceptual framework. While the approach is statistical, the emphasis is on concepts rather than mathematics. Many examples are given, with liberal use of color graphics. It should be a valuable resource for statisticians and anyone interested in data mining in science or industry. The book’s coverage is broad, from supervised learning (prediction) to unsupervised learning. The many topics include neural networks, support vector machines, classification trees and boosting — the first comprehensive treatment of this topic in any book. Trevor Hastie, Robert Tibshirani, and Jerome Friedman are professors of statistics at Stanford University. They are prominent researchers in this area: Hastie and Tibshirani developed generalized additive models and wrote a popular book of that title. Hastie wrote much of the statistical modeling software in S-PLUS and invented principal curves and surfaces. Tibshirani proposed the Lasso and is co-author of the very successful An Introduction to the Bootstrap. Friedman is the co-inventor of many data-mining tools including CART, MARS, and projection pursuit.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.goodreads.com/review/show/2745684471"&gt;Terran M’s Review&lt;/a&gt; on goodreads.com:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is an excellent second or third book on statistical modeling after you have read something with code examples and done a few real projects. It is mathematically deeper and more comprehensive than &lt;a href="https://www.goodreads.com/book/show/17397466.An_Introduction_to_Statistical_Learning_With_Applications_in_R"&gt;An Introduction to Statistical Learning: With Applications in R&lt;/a&gt; and does more to tie together how and why algorithms work. It provides no code examples, and it is also correspondingly more demanding in the mathematical background of the reader. Even if you never read all of it, it’s worthwhile owning as a reference, and a PDF is even available for free from the author: &lt;a href="https://web.stanford.edu/~hastie/ElemStatLearn/"&gt;https://web.stanford.edu/~hastie/ElemStatLearn/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Some basic differences between maths and statistics name conventions.</title>
      <dc:creator>Ola Sk</dc:creator>
      <pubDate>Wed, 11 Dec 2019 18:54:28 +0000</pubDate>
      <link>https://forem.com/olask/some-basic-differences-between-maths-and-statistics-name-conventions-1kil</link>
      <guid>https://forem.com/olask/some-basic-differences-between-maths-and-statistics-name-conventions-1kil</guid>
      <description>&lt;p&gt;I write this note because I was confused with the names used for different concepts in maths vs statistics and maybe someone else too is. It's gonna at least serve me as a small reminder.&lt;/p&gt;

&lt;p&gt;Say we have a multidimensional dataset, the data points have particular coordinates (that's what is taught in linear algebra) that in statistics are called '&lt;a href="https://www.khanacademy.org/math/ap-statistics/analyzing-categorical-ap/analyzing-one-categorical-variable/v/identifying-individuals-variables-and-categorical-variables-in-a-data-set"&gt;variables&lt;/a&gt;', and the data points themselves in n-dimensional space (with n 'variables' or 'features' as their dimensions) are called 'individuals', 'cases' or sometimes 'observations'. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Variables&lt;/code&gt; (or &lt;code&gt;features&lt;/code&gt;) can be categorical, discrete or continuous. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Data points&lt;/code&gt; or &lt;code&gt;individuals&lt;/code&gt; sometimes don't have identities (names, identifiers) and in order for a data person to clean the data (order it, look for missing or funny values, handle them in a sensible way) and start performing some statistical testing on a data set (graph the data, look at averages, standard deviations etc.), then there may be need to get them back in some kind of order after operating on them, so they need to be 'tagged'.&lt;/p&gt;

</description>
      <category>statistics</category>
      <category>dataset</category>
      <category>nameconvention</category>
      <category>datamatrices</category>
    </item>
    <item>
      <title>Review: Mathematics for Machine Learning @ Coursera. Linear Algebra; Multivariate Calculus; PCA.</title>
      <dc:creator>Ola Sk</dc:creator>
      <pubDate>Wed, 11 Dec 2019 10:54:37 +0000</pubDate>
      <link>https://forem.com/olask/review-mathematics-for-machine-learning-coursera-linear-algebra-multivariate-calculus-pca-2lmb</link>
      <guid>https://forem.com/olask/review-mathematics-for-machine-learning-coursera-linear-algebra-multivariate-calculus-pca-2lmb</guid>
      <description>&lt;p&gt;I recently was doing the &lt;a href="https://www.coursera.org/specializations/mathematics-machine-learning"&gt;Mathematics for Machine Learning specialization&lt;/a&gt; on Coursera, which consists of 3 courses. I was always trying to get deeper into Calculus, Algebra, but I was never satisfied with the quality of different materials I stumbled upon in the past and never really went with my studies far. But then this series of courses happened and I was never more motivated to learn those concepts. I enjoyed it so much. It lies a quite solid mathematical foundation under concepts of Machine Learning. Every bit of the course is applied instantly into practical settings and there are plenty of exercises in Python. I didn't know Python much before, but I programmed in C++ and a bit in JS. I studied it in the meantime. W/o that my interest in Machine Learning was merely learning some high-level functions w/o any knowledge about underlying math and statistics involved. I'm glad I got a deeper grasp of the inner workings and I want to recommend this series of courses to everyone who starts studying Machine Learning.&lt;/p&gt;

&lt;p&gt;Cheers.&lt;/p&gt;

</description>
      <category>maths</category>
      <category>machinelearning</category>
      <category>pca</category>
      <category>calculus</category>
    </item>
    <item>
      <title>STL Algorithms: Counting and Finding</title>
      <dc:creator>Ola Sk</dc:creator>
      <pubDate>Mon, 09 Dec 2019 02:08:48 +0000</pubDate>
      <link>https://forem.com/olask/stl-algorithms-counting-and-finding-21o4</link>
      <guid>https://forem.com/olask/stl-algorithms-counting-and-finding-21o4</guid>
      <description>&lt;h1&gt;
  
  
  Foreword
&lt;/h1&gt;

&lt;p&gt;(&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#counting"&gt;TL;DR&lt;/a&gt;)&lt;br&gt;
STL isn't a very big library compared to many libraries available in other languages. But it's very robust, well tested and documented and it is included with every copy of a compiler. It handles most edge cases you can think of for a particular application of functions there included. So there are definitely good reasons for which it's worth to use it. Plus there's an undergoing work by C++ Standard Committee, on developing and maintaining the library. Moreover, your code just gets more readable.&lt;br&gt;
For a person who's at least a bit familiar with what is there in an &lt;code&gt;&amp;lt;algorithm&amp;gt;&lt;/code&gt; header, the code is so much more concise. It goes without saying that we as developers should not reinvent what is out there well tested and maintained, so why to contribute to a mental burden for anyone else reading your code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I include a GitHub "Gist" for an overview of all code snippets from the article, see: &lt;a href="https://gist.github.com/ola-sk/8a95296debee637d3801797fd467c8ab"&gt;gist&lt;/a&gt;.&lt;/em&gt;&lt;br&gt;
&lt;a href="https://gist.github.com/ola-sk/8a95296debee637d3801797fd467c8ab"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xq0FNZLc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/zblc6lomdzffoifa5iys.png" alt="All code examples from the article in the github gist" width="655" height="112"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  You should also be familiar with the concepts of:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.cplusplus.com/reference/iterator/"&gt;iterators to collections&lt;/a&gt; (the &lt;code&gt;&amp;lt;algorithm&amp;gt;&lt;/code&gt; header is completely coupled with iterators),&lt;/li&gt;
&lt;li&gt;predicates (for them I don't include two first parameters in all the descriptions of functions)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Remarks:&lt;/em&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Iterators are similar to pointers: they can be dereferenced to access the value, incremented or/and decremented to iterate through elements of a container, besides, they can be passed to other functions that take iterator as its parameter, which we will se in the examples. Each container type in STL has a specific iterator designed to iterate through its elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your IDE probably won't be able to hint about the functions you could use on a particular collection since &lt;strong&gt;all of the functions from the algorithm header are free functions. They're not member functions of some collections&lt;/strong&gt;. Some collections from STL implement a few of some useful algorithms as their member functions—for those you should get autocomplete suggestions in your IDE for them, but it ain't Java-like experience.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  What is a predicate
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Condition the element must meet (usually a lambda)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A predicate is an expression that evaluates to true or false and serves as an internal switch/condition for STL algorithms to determine, basing on its value, whether the given element should or should not be considered as a subject for counting or as a result of a search.&lt;/p&gt;
&lt;h3&gt;
  
  
  1st and 2nd parameter serve the same consistent purpose for all counting/searching functions!
&lt;/h3&gt;

&lt;p&gt;All of the counting and finding functions take a range of the collection to count or search over: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1st param: iterator to the beginning of the range.&lt;/li&gt;
&lt;li&gt;2nd param: iterator to the end of the range. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There may be one or two more parameters specific for each function, but first two in order all do the same thing: declare what range of given collection we want to consider in the algorithm.&lt;/p&gt;
&lt;h3&gt;
  
  
  A collection for examples
&lt;/h3&gt;

&lt;p&gt;In the article I use this vector for all examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; 
&lt;span class="c1"&gt;//6 odd values&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Counting
&lt;/h1&gt;

&lt;p&gt;Count elements in the collection that have a particular value or meet a particular condition.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#count"&gt;count&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#countif"&gt;count_if&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#allof-noneof-anyof-and-naming-conventions-of-stl"&gt;all_of&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#allof-noneof-anyof-and-naming-conventions-of-stl"&gt;any_of&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#allof-noneof-anyof-and-naming-conventions-of-stl"&gt;none_of&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  count()
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2nd+ parameters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;3rd: value to which compare elements of a sequence in a range determined by the two iterators (1st and 2nd parameter to count function) in order to count them.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Return
&lt;/h3&gt;

&lt;p&gt;The number of elements of a given value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;//count how many entries have the target value (2)&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count_twos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;//alternative:&lt;/span&gt;
&lt;span class="c1"&gt;//int twos = count(v.begin(), v.end(), target); &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  count_if()
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2nd+ parameters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;3rd: predicate—condition the element should meet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Return
&lt;/h3&gt;

&lt;p&gt;Number of elements satisfying the condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;//count how many entries are odd&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count_odds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;count_if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[](&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; 

&lt;span class="c1"&gt;//count how many long months are there&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;month_lengths&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;}};&lt;/span&gt; 
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;long_months&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;count_if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;month_lengths&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;month_lengths&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[](&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/*elem is a pair*/&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;second&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  all_of; none_of; any_of, and naming conventions of STL
&lt;/h2&gt;

&lt;p&gt;Once you face a problem, you may find yourself splitting it into "manageable pieces". But you don't have to always do it this way. Different questions, in order to get answered, require you to formulate them well. There are many ready-made STL algorithms that are probable to do the task and most of them tend to follow a naming convention you should get comfortable with after some time.&lt;/p&gt;

&lt;p&gt;Q: Are all of these elements...? [Null; odd; high priority etc.]&lt;br&gt;
Q: Are any of these elements...?&lt;br&gt;
Q: Are none of these elements...?&lt;/p&gt;

&lt;p&gt;One way (too long) to answer these questions is to count and do some comparisons with your count:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;all_of_them_are_odd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count_odds&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; 
&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;none_of_them_is_odd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count_odds&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;any_of_them_are_odd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count_odds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's a better, STL way though:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;allof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;all_of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[](&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; 
&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;anyof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;any_of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[](&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; 
&lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;noneof&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;none_of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[](&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Finding
&lt;/h1&gt;

&lt;p&gt;Find elements in the collection that have a particular value or meet a particular condition.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#find"&gt;find&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#findif"&gt;find_if&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#findifnot"&gt;find_if_not&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#findfirstof"&gt;find_first_of&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#search"&gt;search&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#findend"&gt;find_end&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#searchn"&gt;search_n&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/olask/stl-algorithms-counting-and-finding-21o4#adjacentfind"&gt;adjacent_find&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Chain calls to searching functions
&lt;/h3&gt;

&lt;p&gt;As most of the searching functions take a pair of iterators and return an iterator to the first occurrence of an element with a given value or condition met, you can perform chain calls inside a loop, reusing the return iterators (using return iterators from the previous searches as arguments for next searches), in a loop, comparing current iterator to the end() iterator.&lt;/p&gt;

&lt;p&gt;In most of the following functions, you can pass in either a value or a lambda (predicate), so you call search_n(...) function to find a number of consecutive elements that are all returning true from some condition like e.g. being over a €1000, etc. or a consecutive elements that give the same value from the evaluation of some expression based on the value.&lt;/p&gt;

&lt;h2&gt;
  
  
  find()
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2nd+ parameters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;3rd: value to search for.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Return
&lt;/h3&gt;

&lt;p&gt;An iterator to an element in a collection (first occurrence) that has a value passed in as a third argument.&lt;br&gt;
If the element isn't found, the end() iterator of a collection is returned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// find the first zero in the collection&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;::&lt;/span&gt;&lt;span class="n"&gt;iterator&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;we_looked_for&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;we_looked_for&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is a pointer&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// find the first 2 after that 0&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// result as a "starting from" iterator&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;we_looked_for&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//find the first 'a'&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"So, find this a!"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;letter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sc"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;letter&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;letter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// result is a pointer&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  find_if()
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2nd+ parameters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;3rd: predicate; a condition that the value of an element shall meet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Return
&lt;/h3&gt;

&lt;p&gt;Iterator to an element in a collection that meets the condition (first occurrence).&lt;br&gt;
If the element isn't found, the end() iterator of a collection is returned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// find the first occurence of an odd value (in a vector)&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;find_if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[](&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;we_looked_for&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  find_if_not()
&lt;/h2&gt;

&lt;p&gt;Works exactly like find_if, except it finds the first element that doesn't return the true from the predicate.&lt;/p&gt;

&lt;p&gt;It's trivially easy to change an &lt;code&gt;equals&lt;/code&gt; to a &lt;code&gt;non-equals&lt;/code&gt;, or a &lt;code&gt;less than&lt;/code&gt; to &lt;code&gt;greater than or equal to&lt;/code&gt;. Some conditions though can be harder to negate easily, or you may go after, the code being more readable if you put explicit find_if_not in there.&lt;/p&gt;

&lt;h3&gt;
  
  
  2nd+ parameters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;3rd: predicate; condition that the value of an element shall &lt;strong&gt;not&lt;/strong&gt; meet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Return
&lt;/h3&gt;

&lt;p&gt;Iterator to an element in a collection that &lt;strong&gt;doesn't&lt;/strong&gt; meet the condition (first occurrence).&lt;br&gt;
If the element isn't found, the end() iterator of a collection is returned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// find first even value&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;find_if_not&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[](&lt;/span&gt;&lt;span class="k"&gt;auto&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;we_looked_for&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  find_first_of()
&lt;/h2&gt;

&lt;p&gt;Lets you pass in two additional arguments–iterators to a collection and whichever element of that collection is found first—that element's iterator is returned.&lt;/p&gt;

&lt;h3&gt;
  
  
  2nd+ parameters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;3rd: iterator to the beginning of the sub-range to search for.&lt;/li&gt;
&lt;li&gt;4th: iterator to the end of the sub-range.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Return
&lt;/h3&gt;

&lt;p&gt;Iterator to the first occurrence of an element, the value of which equals to any of the values from the collection of values to search for.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// here as third and fourth arguments we pass the iterators&lt;/span&gt;
&lt;span class="c1"&gt;// to the beginning and an end of a collection of values, &lt;/span&gt;
&lt;span class="c1"&gt;// one of which we wanna find.&lt;/span&gt;
&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;primes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;find_first_of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;primes&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;primes&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;we_looked_for&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  search()
&lt;/h2&gt;

&lt;p&gt;Rather than for a single value—it looks for a sequence. So in a collection of integers it may look for 1 followed by 2.&lt;br&gt;
In a collection of characters, it may look for the word "is".&lt;/p&gt;
&lt;h3&gt;
  
  
  2nd+ parameters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;3rd: iterator to the beginning of the sub-range to search for.&lt;/li&gt;
&lt;li&gt;4th: iterator to the end of the sub-range.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Return
&lt;/h3&gt;

&lt;p&gt;Iterator to the first element of the &lt;strong&gt;first&lt;/strong&gt; occurrence of the subsequence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;subsequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subsequence&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subsequence&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;we_looked_for&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  find_end()
&lt;/h2&gt;

&lt;p&gt;It's &lt;strong&gt;exactly like search&lt;/strong&gt;, with the exception that it gives you back the iterator to the first element of the &lt;strong&gt;last&lt;/strong&gt; occurrence in a collection we look for that subsequence in.&lt;/p&gt;

&lt;h3&gt;
  
  
  2nd+ parameters
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Same as &lt;code&gt;search()&lt;/code&gt; above&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Return
&lt;/h3&gt;

&lt;p&gt;Iterator to the first element of the &lt;strong&gt;last&lt;/strong&gt; occurrence of the subsequence.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;//std::vector&amp;lt;int&amp;gt; subsequence = { 2, 4 };&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subsequence&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subsequence&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;we_looked_for&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  search_n()
&lt;/h2&gt;

&lt;p&gt;Finds consequtive instances. So if you don't just wanna find a zero—you wanna find 4 0s in a row, you use search_n().&lt;/p&gt;

&lt;h3&gt;
  
  
  2nd+ parameters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;3rd: number of consecutive matches we want.&lt;/li&gt;
&lt;li&gt;4th: the value that we want to have matched.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// We're looking for two fours in a row (inside of v vector)&lt;/span&gt;
&lt;span class="c1"&gt;// The resulting iterator points to the first element (earlier in terms of an index) of the sequence that we looked for.&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;search_n&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;we_looked_for&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  adjacent_find()
&lt;/h2&gt;

&lt;p&gt;Finds two consecutive elements that have the same value—whether they are two int values for a collection of integers or two same customers for a collection of customers.&lt;br&gt;
They have to be consecutive, so it's not just that there are two elements with the same value anywhere in the collection, but they have to be right next to each other.&lt;/p&gt;
&lt;h3&gt;
  
  
  Parameters
&lt;/h3&gt;

&lt;p&gt;notice that it doesn't take any parameters besides two iterators that specify the range to look in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;adjacent_find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;begin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//there are two sixes in a row in v, &lt;/span&gt;
    &lt;span class="c1"&gt;//so the value expected is 6/&lt;/span&gt;
    &lt;span class="n"&gt;we_looked_for&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;A well named (they're usually well named with some exceptions) function says more than a comment.&lt;br&gt;
Algorithms work with any collection or part of such a collection that provides the right iterators. &lt;br&gt;
The pattern used in code samples—to prefer end(v) over v.end() is because it works on more kinds of collections and it makes no difference for a common, regarded vector.&lt;/p&gt;

&lt;h2&gt;
  
  
  Side note
&lt;/h2&gt;

&lt;p&gt;Have you set-up your C++ IDE already? You may want to take a look at &lt;a href="https://dev.to/olask/automate-building-and-debugging-a-currently-active-c-source-file-with-vs-code-on-linux-55m3"&gt;how to perform a quick and easy set-up of Visual Studio Code on Linux&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>algorithms</category>
      <category>count</category>
      <category>search</category>
    </item>
    <item>
      <title>Easy set-up: Automate building and debugging a currently active C++ source file with VS Code on Linux</title>
      <dc:creator>Ola Sk</dc:creator>
      <pubDate>Fri, 06 Dec 2019 23:32:05 +0000</pubDate>
      <link>https://forem.com/olask/automate-building-and-debugging-a-currently-active-c-source-file-with-vs-code-on-linux-55m3</link>
      <guid>https://forem.com/olask/automate-building-and-debugging-a-currently-active-c-source-file-with-vs-code-on-linux-55m3</guid>
      <description>&lt;h2&gt;
  
  
  First build, then debug
&lt;/h2&gt;

&lt;p&gt;In order to properly debug a C++ program, it needs to be built with debugging information first (-g flag with g++ compiler).&lt;/p&gt;

&lt;h3&gt;
  
  
  Set-up the development environment
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;If you're on a Linux, so you should have &lt;strong&gt;build-essential&lt;/strong&gt; installed. To install or upgrade though, here's the command: &lt;code&gt;$ sudo apt install build-essential&lt;/code&gt; This will install the necessary C/C++ development environment (compilers, libraries, linkers, etc.). &lt;code&gt;$ g++ –version&lt;/code&gt; or &lt;code&gt;$ g++ –v&lt;/code&gt; will print the version of the compiler on your system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Get the VS Code&lt;/strong&gt; (snap version available—you'll get it in "Ubuntu Software") and &lt;strong&gt;install "&lt;em&gt;C/C++&lt;/em&gt;" extension &lt;em&gt;(ms-vscode.cpptools)&lt;/em&gt; from Microsoft&lt;/strong&gt; inside of VS Code -&amp;gt; extensions. The extension provides you with C/C++ IntelliSense and debugging.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure a build system for building a single file&lt;/strong&gt;. Assuming you've created a directory for your C/C++ project and opened it inside the VS Code (you can do it from bash using &lt;code&gt;code .&lt;/code&gt; while in the project directory). This is easy to set up as long as you haven't played with configuring build tasks inside the VS Code in your project yet. If you did though, and the &lt;code&gt;tasks.json&lt;/code&gt; file was created inside the &lt;code&gt;.vscode&lt;/code&gt; directory of your project, you can leverage getting great suggestions for detected tasks for C++ programs by removing the &lt;code&gt;tasks.json&lt;/code&gt; file and choosing from the menu bar &lt;code&gt;Terminal -&amp;gt; Configure Default Build Task...&lt;/code&gt;. If there's no configuration file yet, the &lt;code&gt;Select environment&lt;/code&gt; window pops up and you get the option &lt;code&gt;C++ (GDB/LLDB)&lt;/code&gt; which you shall choose. Now you probably want to choose "g++ build active file" from the suggestion list (creates &lt;code&gt;tasks.json&lt;/code&gt; in the result).&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qAobN9Sn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/lkozi3pqiwi670pvdh85.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qAobN9Sn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/lkozi3pqiwi670pvdh85.png" alt="g++ build active file" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure the interactive debugger inside the VS Code.&lt;/strong&gt; You can't use the interactive debugger right away—it needs to set up its configuration file. If you created the "g++ build active file" and you don't have the &lt;code&gt;launch.json&lt;/code&gt; configuration file yet inside the &lt;code&gt;.vscode&lt;/code&gt; (you can try to delete it if you have one), then you should get the automatic suggestion for creating a "g++ build and debug active file". To get them, head to &lt;code&gt;Debug&lt;/code&gt;, and now either: &lt;code&gt;Open Configuration&lt;/code&gt;, &lt;code&gt;Add configuration...&lt;/code&gt; or &lt;code&gt;Start debugging&lt;/code&gt;—all options will let you configure the debugger settings if there's no configuration file yet. The &lt;code&gt;Select environment&lt;/code&gt; window pops up and you get the option &lt;code&gt;C++ (GDB/LLDB)&lt;/code&gt; which you shall choose. If you've messed up with the configuration inside the &lt;code&gt;launch.json&lt;/code&gt;, you can delete the file from the &lt;code&gt;.vscode&lt;/code&gt; directory and perform the steps above—for configuring the debugger from 0—to get the suggested configuration, which usually sets most of the things necessary. Once the set up is performed, the file named &lt;code&gt;launch.json&lt;/code&gt; indeed is created inside the &lt;code&gt;.vscode&lt;/code&gt; directory.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TxYSCm3Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/ym1bzpf73l5r2vf7d5ft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TxYSCm3Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/ym1bzpf73l5r2vf7d5ft.png" alt="Alt Text" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Content of the debugger configuration file&lt;/strong&gt; &lt;code&gt;launch.json&lt;/code&gt;—some of the arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;"preLaunchTask"—the automatic building of source files just before debugging.&lt;/strong&gt; The &lt;code&gt;"preLaunchTask"&lt;/code&gt; argument's value serves as a link to the build task (specified inside &lt;code&gt;tasks.json&lt;/code&gt; file in project's &lt;code&gt;.vscode&lt;/code&gt; directory) with the  &lt;code&gt;"label"&lt;/code&gt; argument of the same value, e.g. &lt;code&gt;"preLaunchTask": "g++ build active file",&lt;/code&gt; specified in &lt;code&gt;launch.json&lt;/code&gt; links to &lt;code&gt;"label": "g++ build active file"&lt;/code&gt; specified in &lt;code&gt;tasks.json&lt;/code&gt;. "preLaunchTask" argument sets up the task of building the file first (compiling and linking), just before running the debugger. This is because the debugger needs to operate on files that are already built with the debugging information attached to them (&lt;code&gt;-g&lt;/code&gt; option to &lt;code&gt;g++&lt;/code&gt; compiling command adds this information). &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"program"—compiled file's naming convention.&lt;/strong&gt; &lt;code&gt;"program": "${fileDirname}/${fileBasenameNoExtension}",&lt;/code&gt;. With this setup the debugger will look for the compiled file which has the same name as the source file, just w/o the &lt;code&gt;.cpp&lt;/code&gt; ending and debug it as long as it was compiled with the &lt;code&gt;-g&lt;/code&gt; option, which provides debugging information for later use by the debugger. The value of the &lt;code&gt;"program"&lt;/code&gt; should correspond to how the file which is now taken as a subject for debugging was built by the mini build system that we established in &lt;code&gt;.vscode/tasks.json&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Possible problem with permissions on Linux while debugging C++ with GDB for the first time&lt;/strong&gt;. When you run the debugger and then try to &lt;code&gt;Step Over&lt;/code&gt; or &lt;code&gt;Step Into&lt;/code&gt; while running it, the GDB debugger needs to store or access some temporary files inside the &lt;code&gt;/build&lt;/code&gt; directory in the root of your system. The problem here is that the &lt;code&gt;/build&lt;/code&gt; directory inside your system root &lt;code&gt;/&lt;/code&gt; directory may not exist yet. So once it tries to put the files inside such a path it needs to create a &lt;code&gt;/build&lt;/code&gt; directory inside a &lt;code&gt;/&lt;/code&gt; root first, which it doesn't have permissions to do so. What you can do in such a situation would be that you create a &lt;code&gt;/build&lt;/code&gt; directory yourself with sudo/su (&lt;code&gt;[]:/$ sudo mkdir build&lt;/code&gt;) and then make the &lt;code&gt;/build/&lt;/code&gt; directory that you've just created permissible. In this step you can either try &lt;code&gt;[]:/$ sudo chown -R $USER:$GROUP /build&lt;/code&gt; or if it doesn't work, all permissions may be necessary to be given &lt;code&gt;[]:/$ sudo chmod 777 /build&lt;/code&gt;. It's difficult for me to reproduce the error as I deleted the &lt;code&gt;/build&lt;/code&gt; folder on my machine and debugger doesn't look for any file in a path involving &lt;code&gt;/build&lt;/code&gt; directory anymore. I'm bringing this issue up though since it existed for me once and creating the directory manually and giving it all permissions worked for me. The important thing here is not to get an idea of giving all permissions to the root directory as you'll break your entire filesystem's permissions and make it vulnerable, you'll also lose access to sudo.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;What we've just done is that we automated the building and debugging operations inside of VS Code IDE. Every time we press the Debug button or F5, we get the currently active file built and performed debugging on instantaneously.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>vscode</category>
      <category>debugging</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
