{"id":4110,"date":"2020-11-16T12:20:06","date_gmt":"2020-11-16T10:20:06","guid":{"rendered":"https:\/\/mariusbancila.ro\/blog\/?p=4110"},"modified":"2021-03-19T15:35:50","modified_gmt":"2021-03-19T13:35:50","slug":"the-little-functions-that-matter","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/","title":{"rendered":"The little functions that matter"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Starting with C++20, some very useful functions for searching have been added to some standard containers, such as <code>std::map<\/code>, <code>std::set<\/code>, and <code>std::string<\/code>. These have been required for a long time and it&#8217;s good to see that the committee finally agreed upon their value. I hope this is the beginning of some wonderful additions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Maps and sets<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A typical operation when working with maps is to check if a given key exists. How do you do this in C++17? Well, it&#8217;s simple:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">std::map&lt;int, std::string> m{ {1, \"one\"}, {2, \"two\"}, {3, \"three\"} };\n\nif (m.find(1) != m.end())\n{\n   std::cout &lt;&lt; \"key found!\\n\";\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Although it may be simple it&#8217;s not user-friendly at all. For this reason, many have written their own <code>contains()<\/code> function that takes a map and a key and returns a boolean indicating whether the map contains the key. This is no longer necessarily in C++20 where <code>std::map<\/code> has a <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/map\/contains\" target=\"_blank\" rel=\"noopener noreferrer\"><code>contains()<\/code><\/a> method.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">std::map&lt;int, std::string> m{ {1, \"one\"}, {2, \"two\"}, {3, \"three\"} };\n\nif (m.contains(1))\n{\n   std::cout &lt;&lt; \"key found!\\n\";\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The same is true for <code>std::set<\/code> too.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">std::set&lt;int> s{ 1, 2, 3 };\nif (s.contains(1))\n{\n   std::cout &lt;&lt; \"key found!\\n\";\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In fact, a <code>contains()<\/code> function has been added to the following types in C++20:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/map\" target=\"_blank\" rel=\"noopener noreferrer\">std::map<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/multimap\" target=\"_blank\" rel=\"noopener noreferrer\">std::multimap<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/unordered_map\" target=\"_blank\" rel=\"noopener noreferrer\">std::unordered_map<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/unordered_multimap\" target=\"_blank\" rel=\"noopener noreferrer\">std::unordered_multimap<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/set\" target=\"_blank\" rel=\"noopener noreferrer\">std::set<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/multiset\" target=\"_blank\" rel=\"noopener noreferrer\">std::multiset<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/unordered_set\" target=\"_blank\" rel=\"noopener noreferrer\">std::unordered_set<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/container\/unordered_multiset\" target=\"_blank\" rel=\"noopener noreferrer\">std::unordered_multiset<\/a><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Strings<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A similar problem concerns strings. Often, we need to know if a string contains another string. This is how you do it in C++17:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">std::string text{\"The quick brown fox jumps over the lazy dog\"};\n\nif (text.find(\"fox\") != std::string::npos)\n{\n   std::cout &lt;&lt; \"fox found!\\n\";\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A particular case related to strings is finding a substring at the beginning and end of the string. Searching at the beginning is relatively simple:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if (text.find(\"The quick\") == 0)\n{\n   std::cout &lt;&lt; \"right start\\n\";\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But searching at the end requires a helper function. A possible implementation is this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">bool ends_with(std::string const &amp; text, std::string const &amp; substr)\n{\n   if (substr.size() > text.size()) return false;\n   return std::equal(text.begin() + text.size() - substr.size(), text.end(), substr.begin());\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Which can be used as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if (ends_with(text, \"lazy dog\"))\n{\n   std::cout &lt;&lt; \"right end\\n\";\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(<strong>Note<\/strong>: You can find alternative implementations for such a function <a href=\"https:\/\/stackoverflow.com\/questions\/874134\/find-out-if-string-ends-with-another-string-in-c\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This have been greatly simplified in C++20 where <code>std::basic_string<\/code> and <code>std::basic_string_view<\/code> have two more methods: <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string\/starts_with\" target=\"_blank\" rel=\"noopener noreferrer\">starts_with()<\/a> and <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string\/ends_with\" target=\"_blank\" rel=\"noopener noreferrer\">ends_with()<\/a>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if (text.starts_with(\"The quick\"))\n{\n   std::cout &lt;&lt; \"right start\\n\";\n}\n\nif(text.ends_with(\"lazy dog\"))\n{\n   std::cout &lt;&lt; \"right end\\n\";\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, there is a huge miss in C++20: a function for checking if a string contains a substring. Now, during the <a href=\"https:\/\/herbsutter.com\/2020\/11\/13\/trip-report-autumn-iso-c-standards-meeting-virtual\/\" target=\"_blank\" rel=\"noopener noreferrer\">last C++ ISO committee meeting<\/a>, such a method has been added to C++23 (<a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2020\/p1679r3.html\" target=\"_blank\" rel=\"noopener noreferrer\">P1679<\/a>). This will enable us to write the following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if (text.contains(\"fox\"))\n{\n   std::cout &lt;&lt; \"fox found!\\n\";\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And that is how we always wanted to write code.<br><img decoding=\"async\" src=\"https:\/\/i.memeful.com\/media\/post\/BRkm0vw_700wa_0.gif\" alt=\"Thank you!\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">But&#8230;<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You should keep in mind that these new string functions are case sensitive. They do not take a predicate to allow you to customize the way the search is done. Therefore, if you need to perform case-insensitive searching, then you still need to implement that yourself. A possible implementation for <code>contains()<\/code>, <code>starts_with()<\/code>, and <code>ends_with()<\/code> that performs case-insensitive search is shown here:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">bool contains_ci(std::string const &amp; text, std::string const &amp; substr)\n{\n   if (substr.length() > text.length()) return false;\n\n   auto it = std::search(\n      text.begin(), text.end(),\n      substr.begin(), substr.end(),\n      [](char ch1, char ch2) { \n         return std::toupper(ch1) == std::toupper(ch2); });\n\n   return it != text.end();\n}\n\nbool starts_with_ci(std::string const&amp; text, std::string const&amp; substr)\n{\n   if (substr.length() > text.length()) return false;\n\n   auto it = std::search(\n      text.begin(), text.begin() + substr.length(),\n      substr.begin(), substr.end(),\n      [](char ch1, char ch2) {\n         return std::toupper(ch1) == std::toupper(ch2); });\n\n   return it == text.begin();\n}\n\nbool ends_with_ci(std::string const&amp; text, std::string const&amp; substr)\n{\n   if (substr.length() > text.length()) return false;\n\n   auto it = std::search(\n      text.rbegin(), text.rbegin() + substr.length(),\n      substr.rbegin(), substr.rend(),\n      [](char ch1, char ch2) {\n         return std::toupper(ch1) == std::toupper(ch2); });\n\n   return it == text.rbegin();\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And these can be used as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if (contains_ci(text, \"FOX\"))\n{\n   std::cout &lt;&lt; \"fox found!\\n\";\n}\n\nif (starts_with_ci(text, \"THE QUICK\"))\n{\n   std::cout &lt;&lt; \"right start\\n\";\n}\n\nif (ends_with_ci(text, \"LAZY DOG\"))\n{\n   std::cout &lt;&lt; \"right end\\n\";\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Starting with C++20, some very useful functions for searching have been added to some standard containers, such as <tt>std::map<\/tt>, <tt>std::set<\/tt>, and <tt>std::string<\/tt>. These have been required for a long time and it&#8217;s good to see that the committee finally agreed upon their value. I hope this is the beginning of some wonderful additions.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7],"tags":[451,543,632,333],"class_list":["post-4110","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-c20","tag-c23","tag-stl"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"description\" content=\"A short look at the new contains() methods for maps, sets, and strings in C++20 and C++23.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,c++20,c++23,stl,containers\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"The little functions that matter\" \/>\n\t\t<meta property=\"og:description\" content=\"A short look at the new contains() methods for maps, sets, and strings in C++20 and C++23.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2020-11-16T10:20:06+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2021-03-19T13:35:50+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"The little functions that matter\" \/>\n\t\t<meta name=\"twitter:description\" content=\"A short look at the new contains() methods for maps, sets, and strings in C++20 and C++23.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#article\",\"name\":\"The little functions that matter\",\"headline\":\"The little functions that matter\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i.memeful.com\\\/media\\\/post\\\/BRkm0vw_700wa_0.gif\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#articleImage\"},\"datePublished\":\"2020-11-16T12:20:06+02:00\",\"dateModified\":\"2021-03-19T15:35:50+02:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#webpage\"},\"articleSection\":\"C++, C++, c++20, C++23, STL\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#listItem\",\"name\":\"The little functions that matter\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#listItem\",\"position\":5,\"name\":\"The little functions that matter\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/\",\"name\":\"The little functions that matter\",\"description\":\"A short look at the new contains() methods for maps, sets, and strings in C++20 and C++23.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/11\\\/16\\\/the-little-functions-that-matter\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2020-11-16T12:20:06+02:00\",\"dateModified\":\"2021-03-19T15:35:50+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"The little functions that matter","description":"A short look at the new contains() methods for maps, sets, and strings in C++20 and C++23.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/","robots":"max-image-preview:large","keywords":"c++,c++20,c++23,stl,containers","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#article","name":"The little functions that matter","headline":"The little functions that matter","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/i.memeful.com\/media\/post\/BRkm0vw_700wa_0.gif","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#articleImage"},"datePublished":"2020-11-16T12:20:06+02:00","dateModified":"2021-03-19T15:35:50+02:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#webpage"},"articleSection":"C++, C++, c++20, C++23, STL"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#listItem","name":"The little functions that matter"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#listItem","position":5,"name":"The little functions that matter","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/","name":"The little functions that matter","description":"A short look at the new contains() methods for maps, sets, and strings in C++20 and C++23.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2020-11-16T12:20:06+02:00","dateModified":"2021-03-19T15:35:50+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"The little functions that matter","og:description":"A short look at the new contains() methods for maps, sets, and strings in C++20 and C++23.","og:url":"https:\/\/mariusbancila.ro\/blog\/2020\/11\/16\/the-little-functions-that-matter\/","article:published_time":"2020-11-16T10:20:06+00:00","article:modified_time":"2021-03-19T13:35:50+00:00","twitter:card":"summary","twitter:title":"The little functions that matter","twitter:description":"A short look at the new contains() methods for maps, sets, and strings in C++20 and C++23."},"aioseo_meta_data":{"post_id":"4110","title":"The little functions that matter","description":"A short look at the new contains() methods for maps, sets, and strings in C++20 and C++23.","keywords":[{"label":"C++","value":"C++"},{"label":"C++20","value":"C++20"},{"label":"C++23","value":"C++23"},{"label":"STL","value":"STL"},{"label":"containers","value":"containers"}],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-636965221168c","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":{"businessInfo":{"name":"","urls":{"website":"","aboutPage":"","contactPage":""},"address":{"line1":"","line2":"","zip":"","city":"","state":"","country":""},"contact":{"email":"","phone":"","fax":""},"ids":{"vatID":"","taxID":"","chamberID":""},"payment":{"priceIndication":"","currenciesAccepted":"","methodsAccepted":""},"areaServed":""},"openingHours":{"show":false,"closedLabel":"","open24h":false,"open24hLabel":"","open247":false,"use24hFormat":false,"twoSets":false,"timezone":"","hours":[]}},"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:02:54","updated":"2025-12-12 07:55:32","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Starting with C++20, some very useful functions for searching have been added to some standard containers, such as std::map, std::set, and std::string. These have been required for a long time and it's good to see that the committee finally agreed upon their value. I hope this is the beginning of some wonderful additions.","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">c++20<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++23<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">STL<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">c++20<\/span>","<span class=\"advgb-post-tax-term\">C++23<\/span>","<span class=\"advgb-post-tax-term\">STL<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 6 years ago","modified":"Updated 6 years ago"},"absolute_dates":{"created":"Posted on November 16, 2020","modified":"Updated on March 19, 2021"},"absolute_dates_time":{"created":"Posted on November 16, 2020 12:20 pm","modified":"Updated on March 19, 2021 3:35 pm"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-14i","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=4110"}],"version-history":[{"count":15,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4110\/revisions"}],"predecessor-version":[{"id":4246,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4110\/revisions\/4246"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=4110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=4110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=4110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}