{"id":27160,"date":"2021-05-12T23:10:07","date_gmt":"2021-05-13T03:10:07","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/c-template-example-programming-code-examples-java-j2ee-j2me-ajax\/"},"modified":"2021-05-12T23:10:07","modified_gmt":"2021-05-13T03:10:07","slug":"c-template-example-programming-code-examples-java-j2ee-j2me-ajax","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=27160","title":{"rendered":"C++ Template Example #Programming Code Examples #Java\/J2EE\/J2ME #Ajax"},"content":{"rendered":"<pre style='font-size:15px;padding:10px'>\n\/* The following code example is taken from the book\n * &quot;The C++ Standard Library - A Tutorial and Reference&quot;\n * by Nicolai M. Josuttis, Addison-Wesley, 1999\n *\n * (C) Copyright Nicolai M. Josuttis 1999.\n * Permission to copy, use, modify, sell and distribute this software\n * is granted provided this copyright notice appears in all copies.\n * This software is provided &quot;as is&quot; without express or implied\n * warranty, and with no claim as to its suitability for any purpose.\n *\/\n\n#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;deque&gt;\n#include &lt;list&gt;\n#include &lt;set&gt;\n#include &lt;map&gt;\n#include &lt;string&gt;\n#include &lt;algorithm&gt;\n#include &lt;iterator&gt;\n#include &lt;functional&gt;\n#include &lt;numeric&gt;\n\nusing namespace std;\n\n\/* PRINT_ELEMENTS()\n * - prints optional C-string optcstr followed by\n * - all elements of the collection coll\n * - separated by spaces\n *\/\ntemplate &lt;class T&gt;\ninline void PRINT_ELEMENTS (const T&amp; coll, const char* optcstr=&quot;&quot;)\n{\n    typename T::const_iterator pos;\n\n    std::cout &lt;&lt; optcstr;\n    for (pos=coll.begin(); pos!=coll.end(); ++pos) {\n        std::cout &lt;&lt; *pos &lt;&lt; ' ';\n    }\n    std::cout &lt;&lt; std::endl;\n}\n\n\/* INSERT_ELEMENTS (collection, first, last)\n * - fill values from first to last into the collection\n * - NOTE: NO half-open range\n *\/\ntemplate &lt;class T&gt;\ninline void INSERT_ELEMENTS (T&amp; coll, int first, int last)\n{\n    for (int i=first; i&lt;=last; ++i) {\n        coll.insert(coll.end(),i);\n    }\n}\n\n\n\n\/\/ return whether the second object has double the value of the first\nbool doubled (int elem1, int elem2)\n{\n   return elem1 * 2 == elem2;\n}\n\nint main()\n{\n   vector&lt;int&gt; coll;\n\n   coll.push_back(1);\n   coll.push_back(3);\n   coll.push_back(2);\n   coll.push_back(4);\n   coll.push_back(5);\n   coll.push_back(5);\n   coll.push_back(0);\n\n   PRINT_ELEMENTS(coll,&quot;coll: &quot;);\n\n   \/\/ search first two elements with equal value\n   vector&lt;int&gt;::iterator pos;\n   pos = adjacent_find (coll.begin(), coll.end());\n\n   if (pos != coll.end()) {\n       cout &lt;&lt; &quot;first two elements with equal value have position &quot;\n            &lt;&lt; distance(coll.begin(),pos) + 1\n            &lt;&lt; endl;\n   }\n\n}\n\n\/*\ncoll: 1 3 2 4 5 5 0\nfirst two elements with equal value have position 5\n\n *\/\n\n<\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10194<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Ajax<br \/>Tags:Java\/J2EE\/J2MEAjax<br \/> Post Data:2017-01-02 16:04:23<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* The following code example is taken from the book * &quot;The C++ Standard Library &#8211; A Tutorial and Reference&quot; * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=27160\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-27160","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10091,"url":"http:\/\/bangla.sitestree.com\/?p=10091","url_meta":{"origin":27160,"position":0},"title":"Sort objects stored in deque","author":"","date":"July 29, 2015","format":false,"excerpt":"\/* The following code example is taken from the book \u00a0* \"The C++ Standard Library - A Tutorial and Reference\" \u00a0* by Nicolai M. Josuttis, Addison-Wesley, 1999 \u00a0* \u00a0* (C) Copyright Nicolai M. Josuttis 1999. \u00a0* Permission to copy, use, modify, sell and distribute this software \u00a0* is granted provided\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"http:\/\/bangla.sitestree.com\/?cat=1420"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":62215,"url":"http:\/\/bangla.sitestree.com\/?p=62215","url_meta":{"origin":27160,"position":1},"title":"Sort objects stored in deque #Programming Code Examples #C++ #Std Algorithms","author":"Author-Check- Article-or-Video","date":"May 15, 2021","format":false,"excerpt":"\/* The following code example is taken from the book * \"The C++ Standard Library - A Tutorial and Reference\" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10059,"url":"http:\/\/bangla.sitestree.com\/?p=10059","url_meta":{"origin":27160,"position":2},"title":"Transform binary representation into integral number using bitset","author":"","date":"July 27, 2015","format":false,"excerpt":"\/*\u00a0The\u00a0following\u00a0code\u00a0example\u00a0is\u00a0taken\u00a0from\u00a0the\u00a0book \u00a0*\u00a0\"The\u00a0C++\u00a0Standard\u00a0Library\u00a0-\u00a0A\u00a0Tutorial\u00a0and\u00a0Reference\" \u00a0*\u00a0by\u00a0Nicolai\u00a0M.\u00a0Josuttis,\u00a0Addison-Wesley,\u00a01999 \u00a0* \u00a0*\u00a0(C)\u00a0Copyright\u00a0Nicolai\u00a0M.\u00a0Josuttis\u00a01999. \u00a0*\u00a0Permission\u00a0to\u00a0copy,\u00a0use,\u00a0modify,\u00a0sell\u00a0and\u00a0distribute\u00a0this\u00a0software \u00a0*\u00a0is\u00a0granted\u00a0provided\u00a0this\u00a0copyright\u00a0notice\u00a0appears\u00a0in\u00a0all\u00a0copies. \u00a0*\u00a0This\u00a0software\u00a0is\u00a0provided\u00a0\"as\u00a0is\"\u00a0without\u00a0express\u00a0or\u00a0implied \u00a0*\u00a0warranty,\u00a0and\u00a0with\u00a0no\u00a0claim\u00a0as\u00a0to\u00a0its\u00a0suitability\u00a0for\u00a0any\u00a0purpose. \u00a0*\/ #include\u00a0<bitset> #include\u00a0<iostream> #include\u00a0<string> #include\u00a0<limits> using\u00a0namespace\u00a0std; int\u00a0main() { \u00a0\u00a0\u00a0\u00a0\/*\u00a0print\u00a0some\u00a0numbers\u00a0in\u00a0binary\u00a0representation \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0short>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<numeric_limits<unsigned\u00a0long>::digits>(267) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"10,000,000\u00a0with\u00a024\u00a0bits:\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<24>(1e7)\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0\/*\u00a0transform\u00a0binary\u00a0representation\u00a0into\u00a0integral\u00a0number \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"\\\"1000101011\\\"\u00a0as\u00a0number:\u00a0\u00a0\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0bitset<100>(string(\"1000101011\")).to_ulong()\u00a0<<\u00a0endl; } \u00a0\/*\u00a0 267\u00a0as\u00a0binary\u00a0short:\u00a0\u00a0\u00a0\u00a0\u00a00000000100001011 267\u00a0as\u00a0binary\u00a0long:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a000000000000000000000000100001011 10,000,000\u00a0with\u00a024\u00a0bits:\u00a0100110001001011010000000 1000101011\"\u00a0as\u00a0number:\u00a0\u00a0555 \u00a0*\/\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0 \/\/ create a bitset that is 8 bits long bitset<8> bs;\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"http:\/\/bangla.sitestree.com\/?cat=1420"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10554,"url":"http:\/\/bangla.sitestree.com\/?p=10554","url_meta":{"origin":27160,"position":3},"title":"Pointers","author":"","date":"August 29, 2015","format":false,"excerpt":"\/* The following code example is taken from the book \u00a0* \"The C++ Standard Library - A Tutorial and Reference\" \u00a0* by Nicolai M. Josuttis, Addison-Wesley, 1999 \u00a0* \u00a0* (C) Copyright Nicolai M. Josuttis 1999. \u00a0* Permission to copy, use, modify, sell and distribute this software \u00a0* is granted provided\u2026","rel":"","context":"In &quot;Ajax&quot;","block_context":{"text":"Ajax","link":"http:\/\/bangla.sitestree.com\/?cat=1418"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10552,"url":"http:\/\/bangla.sitestree.com\/?p=10552","url_meta":{"origin":27160,"position":4},"title":"C++ Template Example","author":"","date":"August 29, 2015","format":false,"excerpt":"\/* The following code example is taken from the book \u00a0* \"The C++ Standard Library - A Tutorial and Reference\" \u00a0* by Nicolai M. Josuttis, Addison-Wesley, 1999 \u00a0* \u00a0* (C) Copyright Nicolai M. Josuttis 1999. \u00a0* Permission to copy, use, modify, sell and distribute this software \u00a0* is granted provided\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"http:\/\/bangla.sitestree.com\/?cat=1420"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10064,"url":"http:\/\/bangla.sitestree.com\/?p=10064","url_meta":{"origin":27160,"position":5},"title":"Use bitset with enum together","author":"","date":"July 27, 2015","format":false,"excerpt":"\/*\u00a0The\u00a0following\u00a0code\u00a0example\u00a0is\u00a0taken\u00a0from\u00a0the\u00a0book \u00a0*\u00a0\"The\u00a0C++\u00a0Standard\u00a0Library\u00a0-\u00a0A\u00a0Tutorial\u00a0and\u00a0Reference\" \u00a0*\u00a0by\u00a0Nicolai\u00a0M.\u00a0Josuttis,\u00a0Addison-Wesley,\u00a01999 \u00a0* \u00a0*\u00a0(C)\u00a0Copyright\u00a0Nicolai\u00a0M.\u00a0Josuttis\u00a01999. \u00a0*\u00a0Permission\u00a0to\u00a0copy,\u00a0use,\u00a0modify,\u00a0sell\u00a0and\u00a0distribute\u00a0this\u00a0software \u00a0*\u00a0is\u00a0granted\u00a0provided\u00a0this\u00a0copyright\u00a0notice\u00a0appears\u00a0in\u00a0all\u00a0copies. \u00a0*\u00a0This\u00a0software\u00a0is\u00a0provided\u00a0\"as\u00a0is\"\u00a0without\u00a0express\u00a0or\u00a0implied \u00a0*\u00a0warranty,\u00a0and\u00a0with\u00a0no\u00a0claim\u00a0as\u00a0to\u00a0its\u00a0suitability\u00a0for\u00a0any\u00a0purpose. \u00a0*\/ #include\u00a0<bitset> #include\u00a0<iostream> using\u00a0namespace\u00a0std; int\u00a0main() { \u00a0\u00a0\u00a0\u00a0\/*\u00a0enumeration\u00a0type\u00a0for\u00a0the\u00a0bits \u00a0\u00a0\u00a0\u00a0\u00a0*\u00a0-\u00a0each\u00a0bit\u00a0represents\u00a0a\u00a0color \u00a0\u00a0\u00a0\u00a0\u00a0*\/ \u00a0\u00a0\u00a0\u00a0enum\u00a0Color\u00a0{\u00a0red,\u00a0yellow,\u00a0green,\u00a0blue,\u00a0white,\u00a0black,\u00a0\/\/..., \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0numColors\u00a0}; \u00a0\u00a0\u00a0\u00a0\/\/\u00a0create\u00a0bitset\u00a0for\u00a0all\u00a0bits\/colors \u00a0\u00a0\u00a0\u00a0bitset<numColors>\u00a0usedColors; \u00a0\u00a0\u00a0\u00a0\/\/\u00a0set\u00a0bits\u00a0for\u00a0two\u00a0colors \u00a0\u00a0\u00a0\u00a0usedColors.set(red); \u00a0\u00a0\u00a0\u00a0usedColors.set(blue); \u00a0\u00a0\u00a0\u00a0\/\/\u00a0print\u00a0some\u00a0bitset\u00a0data \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"bitfield\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0\"\u00a0<<\u00a0usedColors \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"number\u00a0\u00a0\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0\"\u00a0<<\u00a0usedColors.count() \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0cout\u00a0<<\u00a0\"bitfield\u00a0of\u00a0unused\u00a0colors:\u00a0\"\u00a0<<\u00a0~usedColors \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<<\u00a0endl; \u00a0\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0any\u00a0color\u00a0is\u00a0used \u00a0\u00a0\u00a0\u00a0if\u00a0(usedColors.any())\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0loop\u00a0over\u00a0all\u00a0colors \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for\u00a0(int\u00a0c\u00a0=\u00a00;\u00a0c\u00a0<\u00a0numColors;\u00a0++c)\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0the\u00a0actual\u00a0color\u00a0is\u00a0used \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0(usedColors[(Color)c])\u00a0{ \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/... \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} \u00a0\u00a0\u00a0\u00a0} } \/*\u00a0 bitfield\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a0001001 number\u00a0\u00a0\u00a0of\u00a0used\u00a0colors:\u00a0\u00a0\u00a02 bitfield\u00a0of\u00a0unused\u00a0colors:\u00a0110110 \u00a0*\/","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"http:\/\/bangla.sitestree.com\/?cat=1420"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27160"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/27160\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27160"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}