Created
July 11, 2018 08:04
-
-
Save bolry/d107642fcdb1ea84c7319d86301c7de5 to your computer and use it in GitHub Desktop.
Source currently unknown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <iterator> | |
#include <string> | |
#include <vector> | |
template<typename C> | |
void pr(C const&c) | |
{ | |
for (auto const& e : c) | |
std::cout << e << '\n'; | |
std::cout << '\n'; | |
} | |
template<typename C1, typename C2, typename C3> | |
void pp(C1 const&c1, C2 const& c2, C3 const& c3) | |
{ | |
auto b1 = begin(c1); | |
auto b2 = begin(c2); | |
auto b3 = begin(c3); | |
auto e1 = end(c1); | |
auto e2 = end(c2); | |
auto e3 = end(c3); | |
for (; b1 != e1 && b2 != e2 && b3!= e3; ++b1, ++b2,++b3) | |
std::cout << *b1 << '\t' << *b2 << '\t' << *b3 << '\n'; | |
std::cout << '\n'; | |
} | |
template<typename RandIt> | |
auto slide(RandIt f, RandIt l, RandIt p) -> std::pair<RandIt,RandIt> | |
{ | |
if (p < f) | |
return {p, std::rotate(p,f,l)}; | |
if (l < p) | |
return {std::rotate(f,l,p), p}; | |
return {f,l}; | |
} | |
template<typename BiIt, typename U> | |
auto gather(BiIt f, BiIt l, BiIt p, U u) -> std::pair<BiIt, BiIt> | |
{ | |
return {std::stable_partition(f, p, std::not1(u)), | |
std::stable_partition(p, l, u)}; | |
} | |
int main() | |
{ | |
using S = std::string; | |
using VS = std::vector<S>; | |
VS const vs = { "0 adam", "1 berti", "2 cesar", "3 david", "4 erik", | |
"5 fredr", "6 gusta", "7 haral", "8 ivar", "9 johan", | |
"10karl", "11ludvi", "12morte", "13nikla", "14Oscar", | |
"15Proud", "16qvint" }; | |
auto vsc1 = vs; | |
auto f = begin(vsc1) + 3; | |
auto l = f + 4; | |
auto p = l + 5; | |
std::rotate(f, l, p); | |
auto vsc2 = vs; | |
p = begin(vsc2) + 3; | |
f = p + 5; | |
l = f + 4; | |
std::rotate(p,f,l); | |
pp(vs, vsc1, vsc2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment