├── .gitignore ├── Emacs └── README.md ├── QtCreator ├── QtCreator.png └── snippets.xml ├── README.md ├── STLInstructionSet.docx ├── STLInstructionSet.md ├── SlickEdit ├── SlickEdit.png └── c.als.xml ├── algorithm_mnemonics.xml ├── list.sh └── vim ├── README.md ├── cpp_algorithms.vim └── cpp_map.vim /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /Emacs/README.md: -------------------------------------------------------------------------------- 1 | # Algorithm Mnemonics 2 | 3 | ## Emacs 4 | 5 | Created by [Ludwig Pacifici](https://github.com/ludwigpacifici) the repository 6 | [algorithm-mnemonics-emacs](https://github.com/ludwigpacifici/algorithm-mnemonics-emacs) contains a version for Emacs that utilizes [YASnippet](https://github.com/joaotavora/yasnippet) to implement the [algorithm-mnemonics](https://github.com/tommybennett/algorithm-mnemonics). 7 | 8 | -------------------------------------------------------------------------------- /QtCreator/QtCreator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tommybennett/algorithm-mnemonics/e0b8c61287e0b235cf07755aa9a25b26c6d24d4a/QtCreator/QtCreator.png -------------------------------------------------------------------------------- /QtCreator/snippets.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | if (std::is_heap(std::begin($container$), std::end($container$))) { 5 | $$ 6 | } 7 | 8 | 9 | auto minmax = std::minmax_element(std::begin($container$), std::end($container$)); 10 | 11 | 12 | auto pos = std::is_heap_until(std::begin($container$), std::end($container$)); 13 | if (pos != std::end($container$)) { 14 | $$ 15 | } 16 | 17 | 18 | auto sum = std::accumulate(std::begin($container$), std::end($container$), 0, [](int total, $$) { 19 | $$ 20 | }); 21 | 22 | 23 | if (std::equal(std::begin($container$), std::end($container$), std::begin($$))) { 24 | $$ 25 | } 26 | 27 | 28 | auto sum = std::accumulate(std::begin($container$), std::end($container$), 0); 29 | 30 | 31 | std::unique_copy(std::begin($container$), std::end($container$), 32 | std::ostream_iterator<string>(std::cout, "\\n")); 33 | 34 | 35 | std::iota(std::begin($container$), std::end($container$), $$); 36 | 37 | 38 | if (std::is_sorted(std::begin($container$), std::end($container$))) { 39 | $$ 40 | } 41 | 42 | 43 | std::replace_copy(std::begin($container$), std::end($container$), std::begin($container$), $$, $$); 44 | 45 | 46 | auto pos = std::is_sorted_until(std::begin($container$), std::end($container$)); 47 | if (pos != std::end($container$)) { 48 | $$ 49 | } 50 | 51 | 52 | auto pos = std::remove(std::begin($container$), std::end($container$), $$); 53 | if (pos != std::end($container$)) { 54 | $$ 55 | } 56 | 57 | 58 | std::nth_element(std::begin($container$), std::end($container$), std::end($container$)); 59 | 60 | 61 | std::replace_if(std::begin($container$), std::end($container$), []($$) { 62 | $$ 63 | }, $$); 64 | 65 | 66 | std::replace(std::begin($container$), std::end($container$), $$, $$); 67 | 68 | 69 | $container$.erase(std::remove(std::begin($container$), std::end($container$), $$), std::end($container$)); 70 | 71 | 72 | std::transform(std::begin($container$), std::end($container$), 73 | std::begin($container$), []($$) { 74 | $$% 75 | }); 76 | 77 | 78 | std::fill_n(std::begin($container$), $$, $$); 79 | 80 | 81 | if (std::all_of(std::begin($container$), std::end($container$), []($$) { 82 | $$ 83 | })) { 84 | $$ 85 | } 86 | 87 | 88 | if (std::prev_permutation(std::begin($container$), std::end($container$))) { 89 | $$ 90 | } 91 | 92 | 93 | $container$.erase(0, $container$.find_first_not_of(" \\t\\n\\r")); 94 | 95 | 96 | std::transform(std::begin($container$), std::end($container$), std::begin($container$), [](char c) { 97 | return std::toupper(c); 98 | }); 99 | $$ 100 | 101 | 102 | std::partial_sort_copy(std::begin($container$), std::end($container$), 103 | std::begin($$), std::end($$)); 104 | 105 | 106 | auto pos = std::partition_point(std::begin($container$), std::end($container$), []($$) { 107 | $$ 108 | }); 109 | if (pos != std::end($container$)) { 110 | $$ 111 | } 112 | 113 | 114 | auto n = std::count(std::begin($container$), std::end($container$), $$); 115 | 116 | 117 | auto pos = std::unique(std::begin($container$), std::end($container$)); 118 | 119 | 120 | std::cin >> 121 | 122 | 123 | std::copy(std::begin($container$), std::end($container$), std::begin($$)); 124 | 125 | 126 | std::cout << 127 | 128 | 129 | std::copy_backward(std::begin($container$), std::end($container$), std::end($container$)); 130 | 131 | 132 | std::swap_ranges(std::begin($container$), std::end($container$), std::begin($$)); 133 | 134 | 135 | std::rotate_copy(std::begin($container$), std::begin($$), std::end($container$), 136 | std::begin($$)); 137 | 138 | 139 | auto pos = std::max_element(std::begin($container$), std::end($container$)); 140 | 141 | 142 | std::rotate(std::begin($container$), std::begin($$), std::end($container$)); 143 | 144 | 145 | std::vector<$$> $$ 146 | 147 | 148 | std::copy_if(std::begin($container$), std::end($container$), std::begin($$), 149 | []($$) { 150 | $$ 151 | }); 152 | 153 | 154 | auto n = std::count_if(std::begin($container$), std::end($container$), []($$) { 155 | $$ 156 | }); 157 | 158 | 159 | std::copy_n(std::begin($container$), $$, std::end($container$)); 160 | 161 | 162 | std::sort(std::begin($container$), std::end($container$)); 163 | 164 | 165 | auto pos = std::stable_partition(std::begin($container$), std::end($container$), []($$) { 166 | $$}); 167 | if (pos != std::end($container$)) { 168 | $$ 169 | } 170 | 171 | 172 | auto values = std::mismatch(std::begin($container$), std::end($container$), std::begin($container$)); 173 | if (values.first == std::end($container$)) { 174 | $$ 175 | } else { 176 | $$ 177 | } 178 | 179 | 180 | std::partition_copy(std::begin($container$), std::end($container$), 181 | std::begin($$), std::end($$)); 182 | 183 | 184 | std::partial_sort(std::begin($container$), std::end($container$), std::end($container$)); 185 | 186 | 187 | auto pos = std::find(std::begin($container$), std::end($container$), $$); 188 | if (pos != std::end($container$)) { 189 | $$ 190 | } 191 | 192 | 193 | std::for_each(std::begin($container$), std::end($container$), []($$) { 194 | $$ 195 | }); 196 | 197 | 198 | auto pos = std::min_element(std::begin($container$), std::end($container$)); 199 | 200 | 201 | auto pos = std::find_std::end(std::begin($container$), std::end($container$), 202 | std::begin($$), std::end($$)); 203 | if (pos != std::end($container$)) { 204 | $$ 205 | } 206 | 207 | 208 | std::merge(std::begin($container$), std::end($container$), 209 | std::begin($$), std::end($$), std::begin($$)); 210 | 211 | 212 | auto pos = std::search(std::begin($container$), std::end($container$), 213 | std::begin($$), std::end($$)); 214 | if (pos != std::end($container$)) { 215 | $$ 216 | } 217 | 218 | 219 | auto pos = std::find_if(std::begin($container$), std::end($container$), []($$) { 220 | $$ 221 | }); 222 | if (pos != std::end($container$)) { 223 | $$ 224 | } 225 | 226 | 227 | auto pos = std::partition(std::begin($container$), std::end($container$), []($$) { 228 | $$ 229 | }); 230 | if (pos != std::end($container$)) { 231 | $$ 232 | } 233 | 234 | 235 | auto pos = std::search_n(std::begin($container$), std::end($container$),$$,$$); 236 | if (pos != std::end($container$)) { 237 | $$ 238 | } 239 | 240 | 241 | if (std::any_of(std::begin($container$), std::end($container$), []($$) { 242 | $$ 243 | })) { 244 | $$ 245 | } 246 | 247 | 248 | if (std::next_permutation(std::begin($container$), std::end($container$))) { 249 | $$ 250 | } 251 | 252 | 253 | std::reverse(std::begin($container$), std::end($container$)); 254 | 255 | 256 | std::remove_copy(std::begin($container$), std::end($container$), 257 | std::begin($container$), $$); 258 | 259 | 260 | std::stable_sort(std::begin($container$), std::end($container$)); 261 | 262 | 263 | std::remove_copy_if(std::begin($container$), std::end($container$), 264 | std::begin($container$), []($$) { 265 | $$ 266 | }); 267 | 268 | 269 | std::replace_copy_if(std::begin($container$), std::end($container$), 270 | std::begin($container$), []($$) { 271 | $$ 272 | }, $$); 273 | 274 | 275 | auto pos = std::remove_if(std::begin($container$), std::end($container$), []($$) { 276 | $$ 277 | }); 278 | if (pos != std::end($container$)) { 279 | $$ 280 | } 281 | 282 | 283 | std::reverse_copy(std::begin($container$), std::end($container$), std::begin($$)); 284 | 285 | 286 | std::copy(std::begin($container$), std::end($container$), std::ostream_iterator<$$>{ 287 | %\istd::cout, "$$" 288 | }); 289 | 290 | 291 | std::sort_heap(std::begin($container$), std::end($container$)); 292 | 293 | 294 | std::push_heap(std::begin($container$), std::end($container$)); 295 | 296 | 297 | auto pos = std::find_first_of(std::begin($container$), std::end($container$), 298 | std::begin($$), std::end($$)); 299 | if (pos != std::end($container$)) { 300 | $$ 301 | } 302 | 303 | 304 | std::generate(std::begin($container$), std::end($container$), []($$) { 305 | $$ 306 | }); 307 | 308 | 309 | if (std::is_permutation(std::begin($container$), std::end($container$), std::begin($$))) { 310 | $$ 311 | } 312 | 313 | 314 | if (std::is_partitioned(std::begin($container$), std::end($container$), []($$) { 315 | $$ 316 | })) { 317 | $$ 318 | } 319 | 320 | 321 | std::make_heap(std::begin($container$), std::end($container$)); 322 | 323 | 324 | std::fill(std::begin($container$), std::end($container$), $$); 325 | 326 | 327 | auto pos = std::find_if_not(std::begin($container$), std::end($container$),[]($$) { 328 | $$ 329 | }); 330 | if (pos != std::end($container$)) { 331 | $$ 332 | } 333 | 334 | 335 | std::transform(std::begin($container$), std::end($container$), std::begin($container$), [](char c) { 336 | return std::tolower(c); }); 337 | 338 | 339 | if (std::lexigraphical_compare(std::begin($container$), std::end($container$), 340 | std::begin($$), std::end($$)) { 341 | $$ 342 | } 343 | 344 | 345 | std::random_shuffle(std::begin($container$), std::end($container$)); 346 | 347 | 348 | auto pos = std::adjacent_find(std::begin($container$), std::end($container$)); 349 | if (pos != std::end($container$)) { 350 | $$ 351 | } 352 | 353 | 354 | $container$.erase($container$.find_last_not_of(" \\t\\n\\r") + 1); 355 | 356 | 357 | std::generate_n(std::begin($container$), $$, []($$) { 358 | $$ 359 | }); 360 | 361 | 362 | if (std::none_of(std::begin($container$), std::end($container$), []($$) { 363 | $$ 364 | })) { 365 | $$ 366 | } 367 | 368 | 369 | std::pop_heap(std::begin($container$), std::end($container$)); 370 | 371 | 372 | auto pos = std::binary_search(std::begin($container$), std::end($container$), $$); 373 | if (pos != std::end($container$)) { 374 | $$ 375 | } 376 | 377 | 378 | if (std::includes(std::begin($container$), std::end($container$), 379 | std::begin($$), std::end($$))) { 380 | $$ 381 | } 382 | 383 | 384 | auto pos = std::lower_bound(std::begin($container$), std::end($container$), $$); 385 | if (pos != std::end($container$)) { 386 | $$ 387 | } 388 | 389 | 390 | auto pos = std::upper_bound(std::begin($container$), std::end($container$), $$); 391 | if (pos != std::end($container$)) { 392 | $$ 393 | } 394 | 395 | 396 | auto bounds = std::equal_range(std::begin($container$), std::end($container$), $$); 397 | 398 | 399 | auto bounds = std::equal_range(std::begin($container$), std::end($container$), $$, 400 | []($$,$$) { $$ }); 401 | 402 | 403 | auto pos = std::set_union(std::begin($container$), std::end($container$), 404 | std::begin($$), std::end($$), std::begin($$)); 405 | 406 | 407 | auto pos = std::set_intersection(std::begin($container$), std::end($container$), 408 | std::begin($$), std::end($$), std::begin($$)); 409 | 410 | 411 | auto pos = std::set_difference(std::begin($container$), std::end($container$), 412 | std::begin($$), std::end($$), std::begin($$)); 413 | 414 | 415 | auto pos = std::set_symmetric_difference(std::begin($container$), 416 | std::end($container$), std::begin($$), std::end($$), std::begin($$)); 417 | 418 | 419 | std::inplace_merge(std::begin($container$), std::end($container$), std::end($container$)); 420 | 421 | 422 | std::move(std::begin($container$), std::end($container$), std::begin($container$)); 423 | 424 | 425 | std::move_backward(std::begin($container$), std::end($container$), std::end($container$)); 426 | 427 | 428 | std::swap($container$, $$); 429 | 430 | 431 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Algorithm Mnemonics: Increase Productivity with STL Algorithms 2 | 3 | ## Begin 4 | 5 | For the impatient, a picture is worth 764 words, here is a video demonstrating algorithm mnemonics: 6 | 7 | [Video Demonstration of Algorithm Mnemonics](https://www.youtube.com/watch?v=uzc2OWVZPnM) 8 | 9 | Are you tired of typing begin and end? Do you keep looking up the STL algorithms in a reference? Would you like to use STL algorithms more? 10 | 11 | Introducing algorithm mnemonics. 12 | 13 | Algorithm mnemonics is a way to operate at a higher level while constructing code. Similar to mnemonics in assembly language, there is a mnemonic for every STL algorithm. I call this the STL Instruction Set. The entire STL Instruction Set is listed in the word document called STLInstructionSet.docx. 14 | 15 | Many editors include a capability called abbreviations, aliases, template expansion, surround text, or simply code snippets. This feature allows you to expand a code template into the editor by typing an abbreviated form of the expanded text. Algorithm mnemonics is a method of maximizing the use of these facilities in your editor. 16 | 17 | If your editor doesn’t have this capability, it can most likely be implemented using the language of the editor. I provide examples of how I have implemented it in [SlickEdit](http://www.slickedit.com) and vim below. You can use these examples to foster an idea of how you could implement it in your editor of choice. 18 | 19 | ## How does it work? 20 | 21 | There are different ways algorithm mnemonics can be implemented in an editor. It depends on which editing facility you use or if you implement the facility yourself. I will describe how it works in general and then show specific examples in [SlickEdit](http://www.slickedit.com) and vim. 22 | 23 | In this example, let’s use the STL algorithm **std::count_if**. The algorithm mnemonic is **cni**. In the following code, you would type the container **v**: 24 | 25 | 26 | ``` 27 | std::vector v; 28 | v 29 | ``` 30 | 31 | followed by **cni**: 32 | 33 | ``` 34 | std::vector v; 35 | vcni 36 | ``` 37 | 38 | the editor would then recognize this sequence and expand to: 39 | 40 | 41 | ``` 42 | std::vector v; 43 | auto n = std::count_if( begin( v ), end( v ), []( ) { 44 | 45 | } ); 46 | ``` 47 | 48 | You would then tab through each _placeholder_ to fill out the algorithm. 49 | 50 | This is just one style, there are many different ways it could be implemented and invoked by the editor. The style you use will probably be dictated by the facility of the editor, unless of course you implement it yourself. 51 | 52 | ## SlickEdit 53 | 54 | I use [SlickEdit](http://www.slickedit.com) in vim emulation mode as my primary editor. In [SlickEdit](http://www.slickedit.com), there is a command called _surround_text_. When _surround_text_ is invoked with _Command-S_ key binding, a dialog is displayed, you type the letters of the mnemonic, hit enter, and it surrounds the previous word at the cursor with the expanded text. If you type the container before invoking _surround_text_, the _surround_text_ command will surround the container with the expanded text. _Voilà!_ 55 | 56 | ![SlickEdit Demonstration](https://github.com/tommybennett/algorithm-mnemonics/blob/master/SlickEdit/SlickEdit.png) 57 | 58 | You can then step through the _placeholders_ to fill out the algorithm. 59 | 60 | The video I used in the presentation was made using [SlickEdit](http://www.slickedit.com). Here is a link to the video demonstrating algorithm mnemonics: 61 | 62 | [Video Demonstration of Algorithm Mnemonics](https://www.youtube.com/watch?v=uzc2OWVZPnM) 63 | 64 | ## vim 65 | 66 | Created by [Dawid Kurek](https://github.com/dawikur) the repository 67 | [algorithm-mnemonics.vim](https://github.com/dawikur/algorithm-mnemonics.vim) contains a version for vim that utilizes [ultisnips](https://github.com/SirVer/ultisnips) for vim snippets. 68 | 69 | I created a facility for vim available in the vim directory [algorithm-mnemonics-vim](https://github.com/tommybennett/algorithm-mnemonics/tree/master/vim). It doesn’t support tabbing through the _placeholders_. It only expands the algorithm. You have to use your vim nimbleness to navigate and fill out the algorithm. In vim, you type the container, _Control-K_, followed by the mnemonic and it expands. 70 | 71 | ## Emacs 72 | 73 | Created by [Ludwig Pacifici](https://github.com/ludwigpacifici) the repository 74 | [algorithm-mnemonics-emacs](https://github.com/ludwigpacifici/algorithm-mnemonics-emacs) contains a version for Emacs that utilizes [YASnippet](https://github.com/joaotavora/yasnippet) to implement the [algorithm-mnemonics](https://github.com/tommybennett/algorithm-mnemonics). 75 | 76 | ## Visual Studio Code 77 | 78 | Created by [David Brötje](https://github.com/davidbroetje) the repository [algorithm-mnemonics-vscode](https://github.com/davidbroetje/algorithm-mnemonics-vscode) contains a version for the [Visual Studio Code](https://code.visualstudio.com) editor. 79 | 80 | ## QtCreator 81 | 82 | Created by [Vahid Dzanic](https://github.com/vahid-dzanic) the directory [algorithm-mnemonics/QtCreator](https://github.com/tommybennett/algorithm-mnemonics/tree/master/QtCreator) contains a version for the [QtCreator](https://www.qt.io/ide) development environment. 83 | 84 | ![QtCreator Demonstration](https://github.com/tommybennett/algorithm-mnemonics/blob/master/QtCreator/QtCreator.png) 85 | 86 | ## End 87 | 88 | Once you have added this to your editor, I suggest you go through each algorithm, use it in a real working example, or unit test. Going through each algorithm will _tattoo_ the mnemonics and STL algorithms on your brain. You will then be able to _summon_ them at will. 89 | 90 | You might be asking yourself if it is worth taking the time to implement this in your editor. I can only tell you this. There is no better feeling than when I am down in the trenches, wired in, cranking out code, and I notice a place where I can use a STL algorithm. I deploy the mnemonic and it is almost like code exploding on my screen. I often call the mnemonics small code generators or code grenades. They detonate with a key press and blast on the screen. 91 | 92 | You will begin to actively seek places to use an algorithm. What can be better than that? Eliminating raw loops with the mere thought of _three letters_ and you keep on moving. 93 | 94 | It is pure joy. 95 | 96 | -------------------------------------------------------------------------------- /STLInstructionSet.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tommybennett/algorithm-mnemonics/e0b8c61287e0b235cf07755aa9a25b26c6d24d4a/STLInstructionSet.docx -------------------------------------------------------------------------------- /STLInstructionSet.md: -------------------------------------------------------------------------------- 1 | ## STL Instruction Set 2 | ### Nonmodifying 3 | 4 | ajf adjacent_find 5 | alo all_of 6 | ano any_of 7 | cni count_if 8 | cnt count 9 | eql equal 10 | ffo find_first_of 11 | fin find_if_not 12 | fnd find 13 | fne find_end 14 | fni find_if 15 | fre for_each 16 | ihp is_heap 17 | ihu is_heap_until 18 | ipr is_permutation 19 | ipt is_partitioned 20 | iss is_sorted 21 | isu is_sorted_until 22 | lxc lexigraphical_compare 23 | mme minmax_element 24 | mne min_element 25 | msm mismatch 26 | mxe max_element 27 | nno none_of 28 | ppt partition_point 29 | srh search 30 | srn search_n 31 | 32 | ### Sorting 33 | 34 | mkh make_heap 35 | nth nth_element 36 | phh push_heap 37 | pph pop_heap 38 | psc partial_sort_copy 39 | pst partial_sort 40 | ptc partition_copy 41 | ptn partition 42 | spt stable_partition 43 | srt sort 44 | sth sort_heap 45 | sts stable_sort 46 | 47 | ### Sorted Ranges 48 | 49 | bns binary_search 50 | eqr equal_range 51 | erl equal_range 52 | inc includes 53 | ipm inplace_merge 54 | lwb lower_bound 55 | mrg merge 56 | ssd set_symmetric_difference 57 | std set_difference 58 | stn set_intersection 59 | stu set_union 60 | ucp unique_copy 61 | upb upper_bound 62 | 63 | ### Modifying 64 | 65 | cpb copy_backward 66 | cpi copy_if 67 | cpn copy_n 68 | cpy copy 69 | fil fill 70 | fln fill_n 71 | gnn generate_n 72 | gnr generate 73 | ita iota 74 | mov move 75 | mvb move_backward 76 | rci replace_copy_if 77 | rpc replace_copy 78 | rpi replace_if 79 | rpl replace 80 | swp swap 81 | swr swap_ranges 82 | tfm transform 83 | 84 | ### Removing 85 | 86 | rmc remove_copy 87 | rmf remove_copy_if 88 | rmi remove_if 89 | rmv remove 90 | uqe unique 91 | 92 | ### Mutating 93 | 94 | nxp next_permutation 95 | prp prev_permutation 96 | rtc rotate_copy 97 | rte rotate 98 | rvc reverse_copy 99 | rvr reverse 100 | shf random_shuffle 101 | 102 | ### Numeric 103 | 104 | acl accumulate 105 | acm accumulate 106 | 107 | ### Idioms 108 | 109 | erm erase 110 | 111 | ### Strings 112 | 113 | ltr string_trim_left 114 | lwr string_lower 115 | trm string_trim_right 116 | upr string_upper 117 | 118 | ### Streams 119 | 120 | oit copy 121 | sti cin 122 | sto cout 123 | 124 | ### Containers 125 | 126 | stv vector 127 | 128 | -------------------------------------------------------------------------------- /SlickEdit/SlickEdit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tommybennett/algorithm-mnemonics/e0b8c61287e0b235cf07755aa9a25b26c6d24d4a/SlickEdit/SlickEdit.png -------------------------------------------------------------------------------- /SlickEdit/c.als.xml: -------------------------------------------------------------------------------- 1 | 2 |

3 | 4 | if (std::is_heap(begin(%\m sur_text%), end(%\m sur_text%))) { 5 | %\c 6 | } 7 | 8 |

9 |

10 | 11 | auto minmax = std::minmax_element(begin(%\m sur_text%), end(%\m sur_text%)); 12 | 13 |

14 |

15 | 16 | auto pos = std::is_heap_until(begin(%\m sur_text%), end(%\m sur_text%)); 17 | if (pos != end(%\m sur_text%)) { 18 | %\c 19 | } 20 | 21 |

22 |

23 | 24 | auto sum = std::accumulate( begin(%\m sur_text%), end(%\m sur_text%), 0, [](int total, %\c) { 25 | %\c 26 | } ); 27 | 28 |

29 |

30 | 31 | if (std::equal(begin(%\m sur_text%), end(%\m sur_text%), begin(%\c))) { 32 | %\c 33 | } 34 | 35 |

36 |

37 | 38 | auto sum = std::accumulate(begin(%\m sur_text%), end(%\m sur_text%), 0); 39 | 40 |

41 |

42 | 43 | std::unique_copy(begin(%\m sur_text%), end(%\m sur_text%), 44 | std::ostream_iterator<string>(std::cout, "\n")); 45 | 46 |

47 |

48 | 49 | std::iota(begin(%\m sur_text%), end(%\m sur_text%), %\c); 50 | 51 |

52 |

53 | 54 | if (std::is_sorted(begin(%\m sur_text%), end(%\m sur_text%))) { 55 | %\c 56 | } 57 | 58 |

59 |

60 | 61 | std::replace_copy(begin(%\m sur_text%), end(%\m sur_text%), begin(%\m sur_text%), %\c, %\c); 62 | 63 |

64 |

65 | 66 | auto pos = std::is_sorted_until(begin(%\m sur_text%), end(%\m sur_text%)); 67 | if (pos != end(%\m sur_text%)) { 68 | %\c 69 | } 70 | 71 |

72 |

73 | 74 | auto pos = std::remove(begin(%\m sur_text%), end(%\m sur_text%), %\c); 75 | if (pos != end(%\m sur_text%)) { 76 | %\c 77 | } 78 | 79 |

80 |

81 | 82 | std::nth_element(begin(%\m sur_text%), end(%\m sur_text%), end(%\m sur_text%)); 83 | 84 |

85 |

86 | 87 | std::replace_if(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 88 | %\c 89 | }, %\c); 90 | 91 |

92 |

93 | 94 | std::replace(begin(%\m sur_text%), end(%\m sur_text%), %\c, %\c); 95 | 96 |

97 |

98 | 99 | %\m sur_text%.erase( std::remove( begin(%\m sur_text%), end(%\m sur_text%), %\c ), end(%\m sur_text%) ); 100 | 101 |

102 |

103 | 104 | std::transform(begin(%\m sur_text%), end(%\m sur_text%), 105 | begin(%\m sur_text%), [](%\c) { 106 | %\c% 107 | } ); 108 | 109 |

110 |

111 | 112 | std::fill_n(begin(%\m sur_text%), %\c, %\c ); 113 | 114 |

115 |

116 | 117 | if (std::all_of(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 118 | %\c 119 | } ) ) { 120 | %\c 121 | } 122 | 123 |

124 |

125 | 126 | if (std::prev_permutation(begin(%\m sur_text%), end(%\m sur_text%))) { 127 | %\c 128 | } 129 | 130 |

131 |

132 | 133 | %\m sur_text%.erase(0, %\m sur_text%.find_first_not_of(" \t\n\r")); 134 | 135 |

136 |

137 | 138 | std::transform(begin(%\m sur_text%), end(%\m sur_text%), begin(%\m sur_text%), [](char c) { 139 | return std::toupper(c); 140 | } ); 141 | %\c 142 | 143 |

144 |

145 | 146 | std::partial_sort_copy(begin(%\m sur_text%), end(%\m sur_text%), 147 | begin(%\c), end(%\c)); 148 | 149 |

150 |

151 | 152 | auto pos = std::partition_point(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 153 | %\c 154 | } ); 155 | if (pos != end(%\m sur_text%)) { 156 | %\c 157 | } 158 | 159 |

160 |

161 | 162 | auto n = std::count(begin(%\m sur_text%), end(%\m sur_text%), %\c); 163 | 164 |

165 |

166 | 167 | auto pos = std::unique(begin(%\m sur_text%), end(%\m sur_text%)); 168 | 169 |

170 |

171 | 172 | std::copy(begin(%\m sur_text%), end(%\m sur_text%), begin(%\c)); 173 | 174 |

175 |

176 | 177 | std::copy_backward(begin(%\m sur_text%), end(%\m sur_text%), end(%\m sur_text%)); 178 | 179 |

180 |

181 | 182 | swap_ranges(begin(%\m sur_text%), end(%\m sur_text%), begin(%\c)); 183 | 184 |

185 |

186 | 187 | std::rotate_copy(begin(%\m sur_text%), begin(%\c), end(%\m sur_text%), 188 | begin(%\c)); 189 | 190 |

191 |

192 | 193 | auto pos = std::max_element(begin(%\m sur_text%), end(%\m sur_text%)); 194 | 195 |

196 |

197 | 198 | std::rotate(begin(%\m sur_text%), begin(%\c), end(%\m sur_text%)); 199 | 200 |

201 |

202 | 203 | std::copy_if(begin(%\m sur_text%), end(%\m sur_text%), begin(%\c), 204 | [](%\c) { 205 | %\c 206 | } ); 207 | 208 |

209 |

210 | 211 | auto n = std::count_if(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 212 | %\c 213 | }); 214 | 215 |

216 |

217 | 218 | std::copy_n(begin(%\m sur_text%), %\c, end(%\m sur_text%)); 219 | 220 |

221 |

222 | 223 | std::sort(begin(%\m sur_text%), end(%\m sur_text%)); 224 | 225 |

226 |

227 | 228 | auto pos = std::stable_partition(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 229 | %\c}); 230 | if (pos != end(%\m sur_text%)) { 231 | %\c 232 | } 233 | 234 |

235 |

236 | 237 | auto values = std::mismatch(begin(%\m sur_text%), end(%\m sur_text%), begin(%\m sur_text%)); 238 | if (values.first == end(%\m sur_text%)) { 239 | %\c 240 | } else { 241 | %\c 242 | } 243 | 244 |

245 |

246 | 247 | std::move_backward(begin(%\m sur_text%), end(%\m sur_text%), end(%\m sur_text%)); 248 | 249 |

250 |

251 | 252 | std::partition_copy(begin(%\m sur_text%), end(%\m sur_text%), 253 | begin(%\c), end(%\c)); 254 | 255 |

256 |

257 | 258 | std::partial_sort(begin(%\m sur_text%), end(%\m sur_text%), end(%\m sur_text%)); 259 | 260 |

261 |

262 | 263 | auto pos = std::find(begin(%\m sur_text%), end(%\m sur_text%), %\c); 264 | if (pos != end(%\m sur_text%)) { 265 | %\c 266 | } 267 | 268 |

269 |

270 | 271 | std::for_each( begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 272 | %\c 273 | } ); 274 | 275 |

276 |

277 | 278 | auto pos = std::min_element(begin(%\m sur_text%), end(%\m sur_text%)); 279 | 280 |

281 |

282 | 283 | auto pos = std::find_end(begin(%\m sur_text%), end(%\m sur_text%), 284 | begin(%\c), end(%\c)); 285 | if (pos != end(%\m sur_text%)) { 286 | %\c 287 | } 288 | 289 |

290 |

291 | 292 | std::merge(begin(%\m sur_text%), end(%\m sur_text%), 293 | begin(%\c), end(%\c), begin(%\c)); 294 | 295 |

296 |

297 | 298 | auto pos = std::search(begin(%\m sur_text%), end(%\m sur_text%), 299 | egin(%\c), end(%\c)); 300 | if (pos != end(%\m sur_text%)) { 301 | %\c 302 | } 303 | 304 |

305 |

306 | 307 | auto pos = std::find_if(begin(%\m sur_text%), end(%\m sur_text%), []( %\c ) { 308 | %\c 309 | }); 310 | if (pos != end(%\m sur_text%)) { 311 | %\c 312 | } 313 | 314 |

315 |

316 | 317 | auto pos = std::partition(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 318 | %\c 319 | }); 320 | if (pos != end(%\m sur_text%)) { 321 | %\c 322 | } 323 | 324 |

325 |

326 | 327 | auto pos = std::search_n(begin(%\m sur_text%), end(%\m sur_text%),%\c,%\c); 328 | if (pos != end(%\m sur_text%)) { 329 | %\c 330 | } 331 | 332 |

333 |

334 | 335 | if (std::any_of(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 336 | %\c 337 | } ) ) { 338 | %\c 339 | } 340 | 341 |

342 |

343 | 344 | if (std::next_permutation(begin(%\m sur_text%), end(%\m sur_text%))) { 345 | %\c 346 | } 347 | 348 |

349 |

350 | 351 | std::reverse(begin(%\m sur_text%), end(%\m sur_text%)); 352 | 353 |

354 |

355 | 356 | std::remove_copy(begin(%\m sur_text%), end(%\m sur_text%), 357 | begin(%\m sur_text%), %\c); 358 | 359 |

360 |

361 | 362 | std::stable_sort(begin(%\m sur_text%), end(%\m sur_text%)); 363 | 364 |

365 |

366 | 367 | std::remove_copy_if( begin(%\m sur_text%), end(%\m sur_text%), 368 | begin(%\m sur_text%), [](%\c) { 369 | %\c 370 | } ); 371 | 372 |

373 |

374 | 375 | std::replace_copy_if(begin(%\m sur_text%), end(%\m sur_text%), 376 | begin(%\m sur_text%), [](%\c) { 377 | %\c 378 | }, %\c ); 379 | 380 |

381 |

382 | 383 | auto pos = std::remove_if( begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 384 | %\c 385 | } ); 386 | if (pos != end(%\m sur_text%)) { 387 | %\c 388 | } 389 | 390 |

391 |

392 | 393 | std::reverse_copy(begin(%\m sur_text%), end(%\m sur_text%), begin(%\c)); 394 | 395 |

396 |

397 | 398 | std::copy( begin( %\m sur_text% ), end( %\m sur_text% ), std::ostream_iterator<%\c>{ 399 | %\istd::cout, "%\c" 400 | } ); 401 | 402 |

403 |

404 | 405 | std::sort_heap(begin(%\m sur_text%), end(%\m sur_text%)); 406 | 407 |

408 |

409 | 410 | std::push_heap(begin(%\m sur_text%), end(%\m sur_text%)); 411 | 412 |

413 |

414 | 415 | auto pos = std::find_first_of(begin(%\m sur_text%), end(%\m sur_text%), 416 | begin(%\c), end(%\c)); 417 | if (pos != end(%\m sur_text%)) { 418 | %\c 419 | } 420 | 421 |

422 |

423 | 424 | std::generate(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 425 | %\c 426 | } ); 427 | 428 |

429 |

430 | 431 | if (std::is_permutation(begin(%\m sur_text%), end(%\m sur_text%), begin(%\c))) { 432 | %\c 433 | } 434 | 435 |

436 |

437 | 438 | if (std::is_partitioned(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 439 | %\c 440 | } ) ) { 441 | %\c 442 | } 443 | 444 |

445 |

446 | 447 | std::make_heap(begin(%\m sur_text%), end(%\m sur_text%)); 448 | 449 |

450 |

451 | 452 | std::fill(begin(%\m sur_text%), end(%\m sur_text%), %\c); 453 | 454 |

455 |

456 | 457 | auto pos = std::find_if_not(begin(%\m sur_text%), end(%\m sur_text%),[](%\c) { 458 | %\c 459 | } ); 460 | if (pos != end(%\m sur_text%)) { 461 | %\c 462 | } 463 | 464 |

465 |

466 | 467 | std::transform(begin(%\m sur_text%), end(%\m sur_text%), begin(%\m sur_text%), [](char c) { 468 | return std::tolower(c); } ); 469 | 470 |

471 |

472 | 473 | if (std::lexigraphical_compare(begin(%\m sur_text%), end(%\m sur_text%), 474 | begin(%\c), end(%\c)) { 475 | %\c 476 | } 477 | 478 |

479 |

480 | 481 | std::random_shuffle(begin(%\m sur_text%), end(%\m sur_text%)); 482 | 483 |

484 |

485 | 486 | auto pos = std::adjacent_find(begin(%\m sur_text%), end(%\m sur_text%)); 487 | if (pos != end(%\m sur_text%)) { 488 | %\c 489 | } 490 | 491 |

492 |

493 | 494 | %\m sur_text%.erase(%\m sur_text%.find_last_not_of(" \t\n\r") + 1); 495 | 496 |

497 |

498 | 499 | std::generate_n(begin(%\m sur_text%), %\c, [](%\c) { 500 | %\c 501 | } ); 502 | 503 |

504 |

505 | 506 | if (std::none_of(begin(%\m sur_text%), end(%\m sur_text%), [](%\c) { 507 | %\c 508 | } ) ) { 509 | %\c 510 | } 511 | 512 |

513 |

514 | 515 | std::cin >> %\c 516 | 517 |

518 |

519 | 520 | std::cout << %\c 521 | 522 |

523 |

524 | 525 | std::vector<%\c> %\c 526 | 527 |

528 |
529 | -------------------------------------------------------------------------------- /algorithm_mnemonics.xml: -------------------------------------------------------------------------------- 1 | 32 | 33 | 44 | 45 | 46 |

47 | 48 | if (std::is_heap(std::begin(%\m C%), std::end(%\m C%))) { 49 | %\c 50 | } 51 | 52 |

53 |

54 | 55 | auto minmax = std::minmax_element(std::begin(%\m C%), std::end(%\m C%)); 56 | 57 |

58 |

59 | 60 | auto pos = std::is_heap_until(std::begin(%\m C%), std::end(%\m C%)); 61 | if (pos != std::end(%\m C%)) { 62 | %\c 63 | } 64 | 65 |

66 |

67 | 68 | auto sum = std::accumulate(std::begin(%\m C%), std::end(%\m C%), 0, [](int total, %\c) { 69 | %\c 70 | }); 71 | 72 |

73 |

74 | 75 | if (std::equal(std::begin(%\m C%), std::end(%\m C%), std::begin(%\c))) { 76 | %\c 77 | } 78 | 79 |

80 |

81 | 82 | auto sum = std::accumulate(std::begin(%\m C%), std::end(%\m C%), 0); 83 | 84 |

85 |

86 | 87 | std::unique_copy(std::begin(%\m C%), std::end(%\m C%), 88 | std::ostream_iterator<string>(std::cout, "\n")); 89 | 90 |

91 |

92 | 93 | std::iota(std::begin(%\m C%), std::end(%\m C%), %\c); 94 | 95 |

96 |

97 | 98 | if (std::is_sorted(std::begin(%\m C%), std::end(%\m C%))) { 99 | %\c 100 | } 101 | 102 |

103 |

104 | 105 | std::replace_copy(std::begin(%\m C%), std::end(%\m C%), std::begin(%\m C%), %\c, %\c); 106 | 107 |

108 |

109 | 110 | auto pos = std::is_sorted_until(std::begin(%\m C%), std::end(%\m C%)); 111 | if (pos != std::end(%\m C%)) { 112 | %\c 113 | } 114 | 115 |

116 |

117 | 118 | auto pos = std::remove(std::begin(%\m C%), std::end(%\m C%), %\c); 119 | if (pos != std::end(%\m C%)) { 120 | %\c 121 | } 122 | 123 |

124 |

125 | 126 | std::nth_element(std::begin(%\m C%), std::end(%\m C%), std::end(%\m C%)); 127 | 128 |

129 |

130 | 131 | std::replace_if(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 132 | %\c 133 | }, %\c); 134 | 135 |

136 |

137 | 138 | std::replace(std::begin(%\m C%), std::end(%\m C%), %\c, %\c); 139 | 140 |

141 |

142 | 143 | %\m C%.erase(std::remove(std::begin(%\m C%), std::end(%\m C%), %\c), std::end(%\m C%)); 144 | 145 |

146 |

147 | 148 | std::transform(std::begin(%\m C%), std::end(%\m C%), 149 | std::begin(%\m C%), [](%\c) { 150 | %\c% 151 | }); 152 | 153 |

154 |

155 | 156 | std::fill_n(std::begin(%\m C%), %\c, %\c); 157 | 158 |

159 |

160 | 161 | if (std::all_of(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 162 | %\c 163 | })) { 164 | %\c 165 | } 166 | 167 |

168 |

169 | 170 | if (std::prev_permutation(std::begin(%\m C%), std::end(%\m C%))) { 171 | %\c 172 | } 173 | 174 |

175 |

176 | 177 | %\m C%.erase(0, %\m C%.find_first_not_of(" \t\n\r")); 178 | 179 |

180 |

181 | 182 | std::transform(std::begin(%\m C%), std::end(%\m C%), std::begin(%\m C%), [](char c) { 183 | return std::toupper(c); 184 | }); 185 | %\c 186 | 187 |

188 |

189 | 190 | std::partial_sort_copy(std::begin(%\m C%), std::end(%\m C%), 191 | std::begin(%\c), std::end(%\c)); 192 | 193 |

194 |

195 | 196 | auto pos = std::partition_point(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 197 | %\c 198 | }); 199 | if (pos != std::end(%\m C%)) { 200 | %\c 201 | } 202 | 203 |

204 |

205 | 206 | auto n = std::count(std::begin(%\m C%), std::end(%\m C%), %\c); 207 | 208 |

209 |

210 | 211 | auto pos = std::unique(std::begin(%\m C%), std::end(%\m C%)); 212 | 213 |

214 |

215 | 216 | std::cin >> 217 | 218 |

219 |

220 | 221 | std::copy(std::begin(%\m C%), std::end(%\m C%), std::begin(%\c)); 222 | 223 |

224 |

225 | 226 | std::cout << 227 | 228 |

229 |

230 | 231 | std::copy_backward(std::begin(%\m C%), std::end(%\m C%), std::end(%\m C%)); 232 | 233 |

234 |

235 | 236 | std::swap_ranges(std::begin(%\m C%), std::end(%\m C%), std::begin(%\c)); 237 | 238 |

239 |

240 | 241 | std::rotate_copy(std::begin(%\m C%), std::begin(%\c), std::end(%\m C%), 242 | std::begin(%\c)); 243 | 244 |

245 |

246 | 247 | auto pos = std::max_element(std::begin(%\m C%), std::end(%\m C%)); 248 | 249 |

250 |

251 | 252 | std::rotate(std::begin(%\m C%), std::begin(%\c), std::end(%\m C%)); 253 | 254 |

255 |

256 | 257 | std::vector<%\c> %\c 258 | 259 |

260 |

261 | 262 | std::copy_if(std::begin(%\m C%), std::end(%\m C%), std::begin(%\c), 263 | [](%\c) { 264 | %\c 265 | }); 266 | 267 |

268 |

269 | 270 | auto n = std::count_if(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 271 | %\c 272 | }); 273 | 274 |

275 |

276 | 277 | std::copy_n(std::begin(%\m C%), %\c, std::end(%\m C%)); 278 | 279 |

280 |

281 | 282 | std::sort(std::begin(%\m C%), std::end(%\m C%)); 283 | 284 |

285 |

286 | 287 | auto pos = std::stable_partition(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 288 | %\c}); 289 | if (pos != std::end(%\m C%)) { 290 | %\c 291 | } 292 | 293 |

294 |

295 | 296 | auto values = std::mismatch(std::begin(%\m C%), std::end(%\m C%), std::begin(%\m C%)); 297 | if (values.first == std::end(%\m C%)) { 298 | %\c 299 | } else { 300 | %\c 301 | } 302 | 303 |

304 |

305 | 306 | std::partition_copy(std::begin(%\m C%), std::end(%\m C%), 307 | std::begin(%\c), std::end(%\c)); 308 | 309 |

310 |

311 | 312 | std::partial_sort(std::begin(%\m C%), std::end(%\m C%), std::end(%\m C%)); 313 | 314 |

315 |

316 | 317 | auto pos = std::find(std::begin(%\m C%), std::end(%\m C%), %\c); 318 | if (pos != std::end(%\m C%)) { 319 | %\c 320 | } 321 | 322 |

323 |

324 | 325 | std::for_each(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 326 | %\c 327 | }); 328 | 329 |

330 |

331 | 332 | auto pos = std::min_element(std::begin(%\m C%), std::end(%\m C%)); 333 | 334 |

335 |

336 | 337 | auto pos = std::find_std::end(std::begin(%\m C%), std::end(%\m C%), 338 | std::begin(%\c), std::end(%\c)); 339 | if (pos != std::end(%\m C%)) { 340 | %\c 341 | } 342 | 343 |

344 |

345 | 346 | std::merge(std::begin(%\m C%), std::end(%\m C%), 347 | std::begin(%\c), std::end(%\c), std::begin(%\c)); 348 | 349 |

350 |

351 | 352 | auto pos = std::search(std::begin(%\m C%), std::end(%\m C%), 353 | std::begin(%\c), std::end(%\c)); 354 | if (pos != std::end(%\m C%)) { 355 | %\c 356 | } 357 | 358 |

359 |

360 | 361 | auto pos = std::find_if(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 362 | %\c 363 | }); 364 | if (pos != std::end(%\m C%)) { 365 | %\c 366 | } 367 | 368 |

369 |

370 | 371 | auto pos = std::partition(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 372 | %\c 373 | }); 374 | if (pos != std::end(%\m C%)) { 375 | %\c 376 | } 377 | 378 |

379 |

380 | 381 | auto pos = std::search_n(std::begin(%\m C%), std::end(%\m C%),%\c,%\c); 382 | if (pos != std::end(%\m C%)) { 383 | %\c 384 | } 385 | 386 |

387 |

388 | 389 | if (std::any_of(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 390 | %\c 391 | })) { 392 | %\c 393 | } 394 | 395 |

396 |

397 | 398 | if (std::next_permutation(std::begin(%\m C%), std::end(%\m C%))) { 399 | %\c 400 | } 401 | 402 |

403 |

404 | 405 | std::reverse(std::begin(%\m C%), std::end(%\m C%)); 406 | 407 |

408 |

409 | 410 | std::remove_copy(std::begin(%\m C%), std::end(%\m C%), 411 | std::begin(%\m C%), %\c); 412 | 413 |

414 |

415 | 416 | std::stable_sort(std::begin(%\m C%), std::end(%\m C%)); 417 | 418 |

419 |

420 | 421 | std::remove_copy_if(std::begin(%\m C%), std::end(%\m C%), 422 | std::begin(%\m C%), [](%\c) { 423 | %\c 424 | }); 425 | 426 |

427 |

428 | 429 | std::replace_copy_if(std::begin(%\m C%), std::end(%\m C%), 430 | std::begin(%\m C%), [](%\c) { 431 | %\c 432 | }, %\c); 433 | 434 |

435 |

436 | 437 | auto pos = std::remove_if(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 438 | %\c 439 | }); 440 | if (pos != std::end(%\m C%)) { 441 | %\c 442 | } 443 | 444 |

445 |

446 | 447 | std::reverse_copy(std::begin(%\m C%), std::end(%\m C%), std::begin(%\c)); 448 | 449 |

450 |

451 | 452 | std::copy(std::begin(%\m C%), std::end(%\m C%), std::ostream_iterator<%\c>{ 453 | %\istd::cout, "%\c" 454 | }); 455 | 456 |

457 |

458 | 459 | std::sort_heap(std::begin(%\m C%), std::end(%\m C%)); 460 | 461 |

462 |

463 | 464 | std::push_heap(std::begin(%\m C%), std::end(%\m C%)); 465 | 466 |

467 |

468 | 469 | auto pos = std::find_first_of(std::begin(%\m C%), std::end(%\m C%), 470 | std::begin(%\c), std::end(%\c)); 471 | if (pos != std::end(%\m C%)) { 472 | %\c 473 | } 474 | 475 |

476 |

477 | 478 | std::generate(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 479 | %\c 480 | }); 481 | 482 |

483 |

484 | 485 | if (std::is_permutation(std::begin(%\m C%), std::end(%\m C%), std::begin(%\c))) { 486 | %\c 487 | } 488 | 489 |

490 |

491 | 492 | if (std::is_partitioned(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 493 | %\c 494 | })) { 495 | %\c 496 | } 497 | 498 |

499 |

500 | 501 | std::make_heap(std::begin(%\m C%), std::end(%\m C%)); 502 | 503 |

504 |

505 | 506 | std::fill(std::begin(%\m C%), std::end(%\m C%), %\c); 507 | 508 |

509 |

510 | 511 | auto pos = std::find_if_not(std::begin(%\m C%), std::end(%\m C%),[](%\c) { 512 | %\c 513 | }); 514 | if (pos != std::end(%\m C%)) { 515 | %\c 516 | } 517 | 518 |

519 |

520 | 521 | std::transform(std::begin(%\m C%), std::end(%\m C%), std::begin(%\m C%), [](char c) { 522 | return std::tolower(c); }); 523 | 524 |

525 |

526 | 527 | if (std::lexigraphical_compare(std::begin(%\m C%), std::end(%\m C%), 528 | std::begin(%\c), std::end(%\c)) { 529 | %\c 530 | } 531 | 532 |

533 |

534 | 535 | std::random_shuffle(std::begin(%\m C%), std::end(%\m C%)); 536 | 537 |

538 |

539 | 540 | auto pos = std::adjacent_find(std::begin(%\m C%), std::end(%\m C%)); 541 | if (pos != std::end(%\m C%)) { 542 | %\c 543 | } 544 | 545 |

546 |

547 | 548 | %\m C%.erase(%\m C%.find_last_not_of(" \t\n\r") + 1); 549 | 550 |

551 |

552 | 553 | std::generate_n(std::begin(%\m C%), %\c, [](%\c) { 554 | %\c 555 | }); 556 | 557 |

558 |

559 | 560 | if (std::none_of(std::begin(%\m C%), std::end(%\m C%), [](%\c) { 561 | %\c 562 | })) { 563 | %\c 564 | } 565 | 566 |

567 |

568 | 569 | std::pop_heap(std::begin(%\m C%), std::end(%\m C%)); 570 | 571 |

572 |

573 | 574 | auto pos = std::binary_search(std::begin(%\m C%), std::end(%\m C%), %\c); 575 | if (pos != std::end(%\m C%)) { 576 | %\c 577 | } 578 | 579 |

580 |

581 | 582 | if (std::includes(std::begin(%\m C%), std::end(%\m C%), 583 | std::begin(%\c), std::end(%\c))) { 584 | %\c 585 | } 586 | 587 |

588 |

589 | 590 | auto pos = std::lower_bound(std::begin(%\m C%), std::end(%\m C%), %\c); 591 | if (pos != std::end(%\m C%)) { 592 | %\c 593 | } 594 | 595 |

596 |

597 | 598 | auto pos = std::upper_bound(std::begin(%\m C%), std::end(%\m C%), %\c); 599 | if (pos != std::end(%\m C%)) { 600 | %\c 601 | } 602 | 603 |

604 |

605 | 606 | auto bounds = std::equal_range(std::begin(%\m C%), std::end(%\m C%), %\c); 607 | 608 |

609 |

610 | 611 | auto bounds = std::equal_range(std::begin(%\m C%), std::end(%\m C%), %\c, 612 | [](%\c,%\c) { %\c }); 613 | 614 |

615 |

616 | 617 | auto pos = std::set_union(std::begin(%\m C%), std::end(%\m C%), 618 | std::begin(%\c), std::end(%\c), std::begin(%\c)); 619 | 620 |

621 |

622 | 623 | auto pos = std::set_intersection(std::begin(%\m C%), std::end(%\m C%), 624 | std::begin(%\c), std::end(%\c), std::begin(%\c)); 625 | 626 |

627 |

628 | 629 | auto pos = std::set_difference(std::begin(%\m C%), std::end(%\m C%), 630 | std::begin(%\c), std::end(%\c), std::begin(%\c)); 631 | 632 |

633 |

634 | 635 | auto pos = std::set_symmetric_difference(std::begin(%\m C%), 636 | std::end(%\m C%), std::begin(%\c), std::end(%\c), std::begin(%\c)); 637 | 638 |

639 |

640 | 641 | std::inplace_merge(std::begin(%\m C%), std::end(%\m C%), std::end(%\m C%)); 642 | 643 |

644 |

645 | 646 | std::move(std::begin(%\m C%), std::end(%\m C%), std::begin(%\m C%)); 647 | 648 |

649 |

650 | 651 | std::move_backward(std::begin(%\m C%), std::end(%\m C%), std::end(%\m C%)); 652 | 653 |

654 |

655 | 656 | std::swap(%\m C%, %\c); 657 | 658 |

659 |
660 | -------------------------------------------------------------------------------- /list.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | ################################################################################ 3 | # Name: list.sh 4 | # 5 | # Create documentation from Algorithm Mnemonics XML document. 6 | # 7 | # Usage: list.sh [-cm] 8 | # 9 | # Where: -c Write categories 10 | # -m Write markdown format 11 | # 12 | # Author: Tommy Bennett, tommy_bennett@icloud.com 13 | # Date: 2016-10-15 14 | ################################################################################ 15 | 16 | # Constants 17 | declare -r ALGORITHM_MNEMONICS="algorithm_mnemonics.xml" 18 | declare -r SCRIPT_NAME="list.sh" 19 | declare -r SCRIPT_DESCRIPTION="Algorithm Mnemonics Documentation" 20 | declare -r VERSION="version 1.0" 21 | declare -a NAME 22 | declare -a EXPANDEDNAME 23 | declare -r NONMODIFYING=0 24 | declare -r SORTING=1 25 | declare -r SORTEDRANGES=2 26 | declare -r MODIFYING=3 27 | declare -r REMOVING=4 28 | declare -r MUTATING=5 29 | declare -r NUMERIC=6 30 | declare -r IDIOMS=7 31 | declare -r STRINGS=8 32 | declare -r STREAMS=9 33 | declare -r CONTAINERS=10 34 | 35 | 36 | # Prints the usage information to standard output. 37 | # 38 | function usage() { 39 | echo "$SCRIPT_NAME ($SCRIPT_DESCRIPTION) $VERSION" 40 | echo 41 | echo "usage: $SCRIPT_NAME [-cm]" 42 | echo 43 | echo "where: -c Write categories" 44 | echo " -m Write markdown format" 45 | echo 46 | exit 1 47 | } 48 | 49 | # Prints the version information to standard output. 50 | # 51 | function version() { 52 | echo "$SCRIPT_NAME ($SCRIPT_DESCRIPTION) $VERSION" 53 | echo "Copyright (C) 2016 Tommy Bennett." 54 | echo "License GPLv3+: GNU GPL version 3 or" \ 55 | "later " 56 | echo "This is free software: you are free to change and redistribute it." 57 | echo "There is NO WARRANTY, to the extent permitted by law." 58 | echo 59 | echo "Written by Tommy Bennett." 60 | exit 1 61 | } 62 | 63 | # Create algorithm name array 64 | # 65 | function create_name() { 66 | NAME[$NONMODIFYING]="fre:cnt:cni:mne:mxe:mme:fnd:fni:fin:fne:srh:srn:ffo:ajf:eql:ipr:msm:iss:isu:ipt:ppt:ihp:ihu:alo:ano:nno:lxc" 67 | NAME[$SORTING]="srt:sts:pst:psc:nth:ptn:spt:ptc:mkh:phh:pph:sth" 68 | NAME[$SORTEDRANGES]="bns::inc:lwb:upb:eqr:erl:mrg:stu:stn:std:ssd:ipm:ucp" 69 | NAME[$MODIFYING]="cpy:cpi:cpn:cpb:mov:mvb:tfm:mrg:swp:swr:fil:fln:gnr:gnn:rpl:rpi:rpc:rci:ita" 70 | NAME[$REMOVING]="rmv:rmi:rmc:rmf:uqe" 71 | NAME[$MUTATING]="rvr:rvc:rte:rtc:nxp:prp:shf" 72 | NAME[$NUMERIC]="acm:acl" 73 | NAME[$STRINGS]="ltr:trm:lwr:upr" 74 | NAME[$STREAMS]="sto:sti:oit" 75 | NAME[$IDIOMS]="erm" 76 | NAME[$CONTAINERS]="stv" 77 | } 78 | 79 | # Create the expanded name array 80 | # 81 | function create_expanded_name() { 82 | mnemonics=$(print_all) 83 | for n in $mnemonics 84 | do 85 | if [ -z "$name" ]; then 86 | name=$n 87 | find_category $name 88 | else 89 | if [ -z "${EXPANDEDNAME[$index]}" ]; then 90 | EXPANDEDNAME[$index]="$name $n" 91 | else 92 | EXPANDEDNAME[$index]="${EXPANDEDNAME[$index]}:$name $n" 93 | fi 94 | name="" 95 | fi 96 | done 97 | } 98 | 99 | # Print category name 100 | # 101 | function print_category() { 102 | case $1 in 103 | $NONMODIFYING ) echo "Nonmodifying" ;; 104 | $SORTING ) echo "Sorting" ;; 105 | $SORTEDRANGES ) echo "Sorted Ranges" ;; 106 | $MODIFYING ) echo "Modifying" ;; 107 | $REMOVING ) echo "Removing" ;; 108 | $MUTATING ) echo "Mutating" ;; 109 | $NUMERIC ) echo "Numeric" ;; 110 | $IDIOMS ) echo "Idioms" ;; 111 | $STRINGS ) echo "Strings" ;; 112 | $STREAMS ) echo "Streams" ;; 113 | $CONTAINERS ) echo "Containers" ;; 114 | esac 115 | } 116 | 117 | # Print all algorithm mnemonics 118 | # 119 | function print_all() { 120 | grep "n=" $ALGORITHM_MNEMONICS | awk -F'"' '{print $2" "$4}' | sort 121 | } 122 | 123 | # Print all algorithm mnemonics with category 124 | # 125 | function print_all_with_category() { 126 | local IFS=":" 127 | end=${#NAME[@]} 128 | for (( i=0; i', '"."\\<\1>"."', 'g' ) . '"' 24 | endif 25 | endfunction 26 | 27 | " Create abbreviation suitable for MapNoContext 28 | function Iab(ab, full) 29 | exe "iab ".a:ab." =MapNoContext('". 30 | \ a:ab."', '".escape (a:full.'=Eatchar()', '<>\"'). 31 | \"')" 32 | endfunction 33 | 34 | function Cpp_BeginEnd( func ) 35 | execute "normal! b\"udwi \" 36 | let @f = a:func 37 | execute "normal! iauto pos = \\"fpa(begin(\\"upa), end(\\"upa));\" 38 | execute "normal! oif (pos != end(\\"upa)) {\}\" 39 | execute "normal! k" 40 | endfunction 41 | 42 | function Cpp_BeginEndNoIf( func, return_variable ) 43 | execute "normal! b\"udwi \" 44 | let @f = a:func 45 | let @v = a:return_variable 46 | execute "normal! iauto \\"vpa = \\"fpa(begin(\\"upa), end(\\"upa));\" 47 | execute "normal! 0w" 48 | endfunction 49 | 50 | function Cpp_BeginEndNoReturn( func ) 51 | execute "normal! b\"udwi \" 52 | let @f = a:func 53 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa));\" 54 | execute "normal! 0w" 55 | endfunction 56 | 57 | function Cpp_BeginEndUnary( func ) 58 | execute "normal! b\"udwi \" 59 | let @f = a:func 60 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), " 61 | execute "normal! i []() {\});\04x" 62 | execute "normal! kf#x" 63 | endfunction 64 | 65 | function Cpp_BeginEndUnaryNoReturn( func ) 66 | execute "normal! b\\"udwi \" 67 | let @f = a:func 68 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), " 69 | execute "normal! i [](#) {\" 70 | execute "normal! i });\kf#x" 71 | endfunction 72 | 73 | function Cpp_BeginEndUnaryNoIf( func, value ) 74 | execute "normal! b\"udwi \" 75 | let @f = a:func 76 | let @v = a:value 77 | execute "normal! iauto \\"vpa = \\"fpa(begin(\\"upa), end(\\"upa), " 78 | execute "normal! i [](#) {\" 79 | execute "normal! i });\kf#x" 80 | endfunction 81 | 82 | function Cpp_IfBeginEnd( func ) 83 | execute "normal! b\"udwi \" 84 | let @f = a:func 85 | execute "normal! iif (\\"fpa(begin(\\"upa), end(\\"upa))) {\}" 86 | execute "normal! k" 87 | endfunction 88 | 89 | function Cpp_IfBeginEndUnary( func ) 90 | execute "normal! b\"udwi \" 91 | let @f = a:func 92 | execute "normal! iif (\\"fpa(begin(\\"upa), end(\\"upa), " 93 | execute "normal! i [](#) {\" 94 | execute "normal! i }) ) {\}\2kf#x" 95 | endfunction 96 | 97 | function Cpp_BeginEndValue( func ) 98 | execute "normal! b\"udwi \" 99 | let @f = a:func 100 | execute "normal! iauto pos = \\"fpa(begin(\\"upa), end(\\"upa), );\" 101 | execute "normal! oif (pos != end(\\"upa)) {\}\" 102 | execute "normal! 2k$F," 103 | endfunction 104 | 105 | function Cpp_BeginEndValueNoIf( func, return_value ) 106 | execute "normal! b\"udwi \" 107 | let @f = a:func 108 | let @v = a:return_value 109 | execute "normal! iauto \\"vpa = \\"fpa(begin(\\"upa), end(\\"upa), );\" 110 | execute "normal! $F," 111 | endfunction 112 | 113 | function Cpp_BeginEndValueUnaryNoIf( func, return_value ) 114 | execute "normal! b\"udwi \" 115 | let @f = a:func 116 | let @v = a:return_value 117 | execute "normal! iauto \\"vpa = \\"fpa(begin(\\"upa), end(\\"upa), " 118 | execute "normal! i, [](,) {\});\04x" 119 | execute "normal! k$3F," 120 | endfunction 121 | 122 | function Cpp_BeginEndValueReturnValue( func, value ) 123 | execute "normal! b\"udwi \" 124 | let @f = a:func 125 | let @v = a:value 126 | execute "normal! iauto \\"vpa = \\"fpa(begin(\\"upa), " 127 | execute "normal! i end(\\"upa), );\" 128 | execute "normal! F,l" 129 | endfunction 130 | 131 | function Cpp_AccumulateWithLambda( func, value ) 132 | execute "normal! b\"udwi \" 133 | let @f = a:func 134 | let @v = a:value 135 | execute "normal! iauto \\"vpa = \\"fpa(begin(\\"upa), " 136 | execute "normal! i end(\\"upa), 0, [](int total, #) {\});\" 137 | execute "normal! 04xkf#x" 138 | endfunction 139 | 140 | function Cpp_BeginEndValueNoReturn( func ) 141 | execute "normal! b\"udwi \" 142 | let @f = a:func 143 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), );\" 144 | execute "normal! F," 145 | endfunction 146 | 147 | function Cpp_BeginEndOldValueNewValue( func ) 148 | execute "normal! b\"udwi \" 149 | let @f = a:func 150 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), old_value, new_value );\" 151 | execute "normal! Fo" 152 | endfunction 153 | 154 | function Cpp_BeginEndUnaryValue( func ) 155 | execute "normal! b\"udwi \" 156 | let @f = a:func 157 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), [](#) {\}, );\" 158 | execute "normal! 04xk0f#x" 159 | endfunction 160 | 161 | function Cpp_BeginEndBeginOldValueNewValue( func ) 162 | execute "normal! b\"udwi \" 163 | let @f = a:func 164 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), begin(\\"upa), old_value, new_value);\" 165 | execute "normal! Fo" 166 | endfunction 167 | 168 | function Cpp_BeginEndBeginUnaryValue( func ) 169 | execute "normal! b\"udwi \" 170 | let @f = a:func 171 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), " 172 | execute "normal! i begin(\\"upa), [](#) {\}, );\" 173 | execute "normal! 04xk0f#x" 174 | endfunction 175 | 176 | function Cpp_IfBeginEndBeginEnd( func ) 177 | execute "normal! b\"udwi \" 178 | let @f = a:func 179 | execute "normal! iif (\\"fpa(begin(\\"upa), end(\\"upa), " 180 | execute "normal! i begin(#), end())) {\}" 181 | execute "normal! k0f#x" 182 | endfunction 183 | 184 | function Cpp_BeginEndEnd( func ) 185 | execute "normal! b\"udwi \" 186 | let @f = a:func 187 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), end(\\"upa));" 188 | execute "normal! 0w" 189 | endfunction 190 | 191 | function Cpp_BeginEndBegin( func ) 192 | execute "normal! b\"udwi \" 193 | let @f = a:func 194 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), begin(#));\" 195 | execute "normal! 0f#x" 196 | endfunction 197 | 198 | function Cpp_BeginBeginEnd( func ) 199 | execute "normal! b\"udwi \" 200 | let @f = a:func 201 | execute "normal! i\\"fpa(begin(\\"upa), begin(\\"upa), end(#));" 202 | execute "normal! 0f#x" 203 | endfunction 204 | 205 | function Cpp_BeginEndBeginValue( func ) 206 | execute "normal! b\"udwi \" 207 | let @f = a:func 208 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), begin(#), );" 209 | execute "normal! 0f#x" 210 | endfunction 211 | 212 | function Cpp_BeginEndBeginUnary( func ) 213 | execute "normal! b\"udwi \" 214 | let @f = a:func 215 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), begin(#), " 216 | execute "normal! i []() {\" 217 | execute "normal! i });\kf#x" 218 | endfunction 219 | 220 | function Cpp_BeginEndBeginEnd( func ) 221 | execute "normal! b\"udwi \" 222 | let @f = a:func 223 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), " 224 | execute "normal! i begin(#), end());" 225 | execute "normal! 0f#x" 226 | endfunction 227 | 228 | function Cpp_BeginEndBeginEndUnary( func ) 229 | execute "normal! b\"udwi \" 230 | let @f = a:func 231 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), " 232 | execute "normal! i begin(#), end(), []() {\});" 233 | execute "normal! 04xkf#x" 234 | endfunction 235 | 236 | function Cpp_BeginEndBeginEndBegin( func ) 237 | execute "normal! b\"udwi \" 238 | let @f = a:func 239 | execute "normal! i\\"fpa(begin(\\"upa), end(\\"upa), " 240 | execute "normal! i begin(#), end(), begin());" 241 | execute "normal! 0f#x" 242 | endfunction 243 | 244 | function Cpp_BeginBeginEndBegin( func ) 245 | execute "normal! b\"udwi \" 246 | let @f = a:func 247 | execute "normal! i\\"fpa(begin(\\"upa), begin(#), \ " 248 | execute "normal! iend(\\"upa), begin() ); " 249 | execute "normal! k0f#x" 250 | endfunction 251 | 252 | function Cpp_IteratorValueIterator( func, it1, value, it2 ) 253 | execute "normal! b\"udwi \" 254 | let @i = a:it1 255 | let @j = a:it2 256 | let @f = a:func 257 | let @v = a:value 258 | execute "normal! i\\"fpa( \\"ipa(\\"upa), \\"vpa, \\"jpa(\\"upa) );\" 259 | execute "normal! 0w" 260 | endfunction 261 | 262 | function Cpp_BeginSizeValue( func ) 263 | execute "normal! b\"udwi \" 264 | let @f = a:func 265 | execute "normal! i\\"fpa(begin(\\"upa), \\"upa.size(), );\" 266 | execute "normal! F," 267 | endfunction 268 | 269 | function Cpp_BeginSizeFunc( func ) 270 | execute "normal! b\"udwi \" 271 | let @f = a:func 272 | execute "normal! i\\"fpa(begin(\\"upa), \\"upa.size(), " 273 | execute "normal! i []() {\" 274 | execute "normal! i });\k0w" 275 | endfunction 276 | 277 | function Cpp_LambdaOneLine() 278 | execute "normal! F,a []( const auto& elem ) {\f)hi}\F{l" 279 | endfunction 280 | 281 | function Cpp_LambdaMultiLine() 282 | call Cpp_LambdaOneLine() 283 | execute "normal! F[i\\f{li\\>>>>f}hi\\04x2kf&h" 284 | endfunction 285 | 286 | function Cpp_FindEnd() 287 | execute "normal! b\"udwi \" 288 | execute "normal! iauto pos = find_end(begin(\\"upa), end(\\"upa), " 289 | execute "normal! i begin(#), end() );\0" 290 | execute "normal! oif (pos != end(\pa)) {\}\" 291 | execute "normal! 2k0f#x" 292 | endfunction 293 | 294 | function Cpp_Search() 295 | execute "normal! b\"udwi \" 296 | execute "normal! iauto pos = search(begin(\\"upa), end(\\"upa), " 297 | execute "normal! i begin(#), end() );\0" 298 | execute "normal! oif (pos != end(\pa)) {\}\" 299 | execute "normal! 2k0f#x" 300 | endfunction 301 | 302 | function Cpp_SearchN() 303 | execute "normal! b\"udwi \" 304 | execute "normal! iauto pos = search_n(begin(\\"upa), end(\\"upa), " 305 | execute "normal! i #, );\0" 306 | execute "normal! oif (pos != end(\pa)) {\}\" 307 | execute "normal! 2k0f#x" 308 | endfunction 309 | 310 | function Cpp_FindFirstOf() 311 | execute "normal! b\"udwi \" 312 | execute "normal! iauto pos = find_first_of(begin(\\"upa), end(\\"upa), " 313 | execute "normal! i begin(#), end() );\0" 314 | execute "normal! oif (pos != end(\pa)) {\}\" 315 | execute "normal! 2k0f#x" 316 | endfunction 317 | 318 | function Cpp_AdjacentFind() 319 | execute "normal! b\"udwi \" 320 | execute "normal! iauto pos = adjacent_find(begin(\\"upa), end(\\"upa));\" 321 | execute "normal! oif (pos != end(\\"upa)) {\}\" 322 | execute "normal! k0w" 323 | endfunction 324 | 325 | function Cpp_Equal() 326 | execute "normal! b\"udwi \" 327 | execute "normal! iif (equal(begin(\\"upa), end(\\"upa), \" 328 | execute "normal! i begin(\\"upa))) {\}\k" 329 | endfunction 330 | 331 | function Cpp_IsPermutation() 332 | execute "normal! b\"udwi \" 333 | execute "normal! iif (is_permutation(begin(\\"upa), end(\\"upa), \" 334 | execute "normal! i begin(\\"upa))) {\}\k" 335 | endfunction 336 | 337 | function Cpp_Mismatch() 338 | execute "normal! b\"udwi \" 339 | execute "normal! iauto values = mismatch(begin(\\"upa), end(\\"upa), " 340 | execute "normal! i begin(\\"upa));\0" 341 | execute "normal! oif (values.first == end(\pa)) {\} else {\}" 342 | execute "normal! 2k" 343 | endfunction 344 | 345 | function Cpp_UniqueCopy() 346 | execute "normal! \b\"udwi \" 347 | execute "normal! i unique_copy(begin(\pa), end(\pa),\" 348 | execute "normal! i ostream_iterator<#>(cout, \"\\n\"));" 349 | execute "normal! 0f#x" 350 | endfunction 351 | 352 | function Cpp_MakeTransform( source, destination, elemtype, statement ) 353 | call setline( ".", " transform(begin(" . a:source . "), end(" . a:source . "), begin(" . a:source . "), []( ". a:elemtype . ") { " . a:statement . " });" ) 354 | endfunction 355 | 356 | function Cpp_SetAlgorithm( func ) 357 | execute "normal! b\"udwi \" 358 | let @f = a:func 359 | execute "normal! iauto pos = \\"fpa(begin(\\"upa), end(\\"upa), " 360 | execute "normal! i begin(#), end(), begin());" 361 | execute "normal! 0f#x" 362 | endfunction 363 | 364 | function Cpp_StreamOutput() 365 | execute "normal! b\"udwi \" 366 | execute "normal! icopy(begin(\\"upa), end(\\"upa), " 367 | execute "normal! i ostream_iterator<#>{\ cout, \"\"\});" 368 | execute "normal! 05x2kf#x" 369 | endfunction 370 | 371 | function Cpp_Swap() 372 | execute "normal! \b\"udwi \" 373 | execute "normal! i swap(\pa, );" 374 | execute "normal! $F,l" 375 | endfunction 376 | 377 | function Cpp_Transform() 378 | execute "normal! Byw" 379 | call Cpp_MakeTransform( @", @", "elemtype elem", "return elem; // Return transformed value" ) 380 | endfunction 381 | 382 | function Cpp_ToUpper() 383 | execute "normal! yw" 384 | call Cpp_MakeTransform( @", @", "char c", "return toupper( c );" ) 385 | endfunction 386 | 387 | function Cpp_ToLower() 388 | execute "normal! yw" 389 | call Cpp_MakeTransform( @", @", "char c", "return tolower( c );" ) 390 | endfunction 391 | 392 | function Cpp_LeftTrim() 393 | execute "normal! \b\"udwi \" 394 | execute "normal! i \\"uPa.erase(0, \\"upa.find_first_not_of(\" \\t\\n\\r\"));" 395 | endfunction 396 | 397 | function Cpp_RightTrim() 398 | execute "normal! \b\"udwi \" 399 | execute "normal! i \\"uPa.erase(\\"upa.find_last_not_of(\" \\t\\n\\r\")+1);" 400 | endfunction 401 | 402 | -------------------------------------------------------------------------------- /vim/cpp_map.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin to map keys used for C++ 2 | " Maintainer: Tommy Bennett tommy_bennett@icloud.com 3 | " License: This file is placed in the public domain. 4 | 5 | if exists("g:loaded_cppmap") 6 | finish 7 | endif 8 | let g:loaded_cppmap = 1 9 | 10 | " Nonmodifying algorithms 11 | inoremap fre :call Cpp_BeginEndUnaryNoReturn( "for_each" )i 12 | inoremap cnt :call Cpp_BeginEndValueReturnValue( "count", "n" )a 13 | inoremap cni :call Cpp_BeginEndUnaryNoIf( "count_if", "n" )i 14 | inoremap mne :call Cpp_BeginEndNoIf( "min_element", "pos" ) 15 | inoremap mxe :call Cpp_BeginEndNoIf( "max_element", "pos" ) 16 | inoremap mme :call Cpp_BeginEndNoIf( "minmax_element", "minmax" ) 17 | inoremap fnd :call Cpp_BeginEndValue( "find" )a 18 | inoremap fni :call Cpp_BeginEndUnary( "find_if" )i 19 | inoremap fin :call Cpp_BeginEndUnary( "find_if_not" )i 20 | inoremap fne :call Cpp_FindEnd()i 21 | inoremap srh :call Cpp_Search()i 22 | inoremap srn :call Cpp_SearchN()i 23 | inoremap ffo :call Cpp_FindFirstOf()i 24 | inoremap ajf :call Cpp_AdjacentFind()o 25 | inoremap eql :call Cpp_Equal()o 26 | inoremap ipr :call Cpp_IsPermutation()o 27 | inoremap msm :call Cpp_Mismatch()o 28 | inoremap iss :call Cpp_IfBeginEnd( "is_sorted" )o 29 | inoremap isu :call Cpp_BeginEnd( "is_sorted_until" )o 30 | inoremap ipt :call Cpp_IfBeginEndUnary( "is_partitioned" )i 31 | inoremap ppt :call Cpp_BeginEndUnary( "partition_point" )i 32 | inoremap ihp :call Cpp_IfBeginEnd( "is_heap" )o 33 | inoremap ihu :call Cpp_BeginEnd( "is_heap_until" )o 34 | inoremap alo :call Cpp_IfBeginEndUnary( "all_of" )i 35 | inoremap ano :call Cpp_IfBeginEndUnary( "any_of" )i 36 | inoremap nno :call Cpp_IfBeginEndUnary( "none_of" )i 37 | inoremap lxc :call Cpp_IfBeginEndBeginEnd( "lexicographical_compare" )i 38 | 39 | " Sorting algorithms 40 | inoremap srt :call Cpp_BeginEndNoReturn( "sort" ) 41 | inoremap sts :call Cpp_BeginEndNoReturn( "stable_sort" ) 42 | inoremap pst :call Cpp_BeginEndEnd( "partial_sort" ) 43 | inoremap psc :call Cpp_BeginEndBeginEnd( "partial_sort_copy" )i 44 | inoremap nth :call Cpp_BeginEndEnd( "nth_element" ) 45 | inoremap ptn :call Cpp_BeginEndUnary( "partition" )i 46 | inoremap spt :call Cpp_BeginEndUnary( "stable_partition" )i 47 | inoremap ptc :call Cpp_BeginEndBeginEndUnary( "partition_copy" )i 48 | inoremap mkh :call Cpp_BeginEndNoReturn( "make_heap" ) 49 | inoremap phh :call Cpp_BeginEndNoReturn( "push_heap" ) 50 | inoremap pph :call Cpp_BeginEndNoReturn( "pop_heap" ) 51 | inoremap sth :call Cpp_BeginEndNoReturn( "sort_heap" ) 52 | 53 | " Algorithms for sorted ranges 54 | inoremap bns :call Cpp_BeginEndValue( "binary_search" )a 55 | inoremap inc :call Cpp_BeginEndBeginEnd( "includes" )i 56 | inoremap lwb :call Cpp_BeginEndValue( "lower_bound" )a 57 | inoremap upb :call Cpp_BeginEndValue( "upper_bound" )a 58 | inoremap eqr :call Cpp_BeginEndValueNoIf( "equal_range", "bounds" )a 59 | inoremap erl :call Cpp_BeginEndValueUnaryNoIf( "equal_range", "bounds" )a 60 | inoremap mrg :call Cpp_BeginEndBeginEndBegin( "merge" )i 61 | inoremap stu :call Cpp_SetAlgorithm( "set_union" )i 62 | inoremap sti :call Cpp_SetAlgorithm( "set_intersection" )i 63 | inoremap std :call Cpp_SetAlgorithm( "set_difference" )i 64 | inoremap ssd :call Cpp_SetAlgorithm( "set_symmetric_difference" )i 65 | inoremap ipm :call Cpp_BeginEndEnd( "inplace_merge" ) 66 | inoremap ucp :call Cpp_UniqueCopy()i 67 | 68 | " Modifying algorithms 69 | inoremap cpy :call Cpp_BeginEndBegin( "copy" )i 70 | inoremap cpi :call Cpp_BeginEndBeginUnary( "copy_if" )i 71 | inoremap cpn :call Cpp_IteratorValueIterator( "copy_n", "begin", "n", "end" ) 72 | inoremap cpb :call Cpp_BeginEndEnd( "copy_backward" ) 73 | inoremap mov :call Cpp_BeginEndBegin( "move" ) 74 | inoremap mvb :call Cpp_BeginEndEnd( "move_backward" ) 75 | inoremap tfm :call Cpp_BeginEndBeginUnary( "transform" )i 76 | inoremap swr :call Cpp_BeginEndBegin( "swap_ranges" )i 77 | inoremap fil :call Cpp_BeginEndValueNoReturn( "fill" )a 78 | inoremap fln :call Cpp_BeginSizeValue( "fill_n" )a 79 | inoremap gnr :call Cpp_BeginEndUnary( "generate" )o 80 | inoremap gnn :call Cpp_BeginSizeFunc( "generate_n" )o 81 | inoremap rpl :call Cpp_BeginEndOldValueNewValue( "replace" ) 82 | inoremap rpi :call Cpp_BeginEndUnaryValue( "replace_if" )i 83 | inoremap rpc :call Cpp_BeginEndBeginOldValueNewValue( "replace_copy" ) 84 | inoremap rci :call Cpp_BeginEndBeginUnaryValue( "replace_copy_if" )i 85 | inoremap ita :call Cpp_BeginEndValueNoReturn( "iota" )a 86 | inoremap swp :call Cpp_Swap()a 87 | 88 | " Removing algorithms 89 | inoremap rmv :call Cpp_BeginEndValue( "remove" )a 90 | inoremap rmi :call Cpp_BeginEndUnary( "remove_if" )i 91 | inoremap rmc :call Cpp_BeginEndBeginValue( "remove_copy" )i 92 | inoremap rmf :call Cpp_BeginEndBeginUnary( "remove_copy_if" )i 93 | inoremap uqe :call Cpp_BeginEndNoIf( "unique", "pos" ) 94 | inoremap uqc :call Cpp_BeginEndBegin( "unique_copy" )i 95 | 96 | " Mutating algorithms 97 | inoremap rvr :call Cpp_BeginEndNoReturn( "reverse" ) 98 | inoremap rvc :call Cpp_BeginEndBegin( "reverse_copy" )i 99 | inoremap rte :call Cpp_BeginBeginEnd( "rotate" )i 100 | inoremap rtc :call Cpp_BeginBeginEndBegin( "rotate_copy" )i 101 | inoremap nxp :call Cpp_IfBeginEnd( "next_permutation" ) 102 | inoremap prp :call Cpp_IfBeginEnd( "prev_permutation" ) 103 | inoremap shf :call Cpp_BeginEndNoReturn( "random_shuffle" ) 104 | 105 | " Numeric algorithms 106 | inoremap acm :call Cpp_BeginEndValueReturnValue( "accumulate", "sum" )a 107 | inoremap acl :call Cpp_AccumulateWithLambda( "accumulate", "sum" )i 108 | 109 | " Strings 110 | inoremap ltr :call Cpp_LeftTrim() 111 | inoremap trm :call Cpp_RightTrim() 112 | inoremap upr :call Cpp_ToUpper() 113 | inoremap lwr :call Cpp_ToLower() 114 | 115 | " Streams 116 | inoremap oit :call Cpp_StreamOutput()i 117 | 118 | " Abbreviations 119 | call Iab('sto', 'cout << ') 120 | call Iab('sti', 'cin >> ') 121 | call Iab('stv', 'vector<') 122 | 123 | --------------------------------------------------------------------------------