Skip to content

Instantly share code, notes, and snippets.

@dgski
Last active March 12, 2021 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dgski/91cc7a4f785f68201c077896dc490c26 to your computer and use it in GitHub Desktop.
Save dgski/91cc7a4f785f68201c077896dc490c26 to your computer and use it in GitHub Desktop.
#include <vector>
#include <string>
#include <list>
#include <deque>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <array>
#include <iostream>
using namespace std;
int main()
{
// back_inserter
{
vector<int> src(10);
iota(begin(src), end(src),0);
vector<int> dst;
copy_if(cbegin(src), cend(src), back_inserter(dst), [](int n)
{
return (n % 2) == 0;
});
}
// front_inserter
{
array<int,6> src{ 2,9,1,10,23,3 };
deque<int> dst;
copy_if(crbegin(src), crend(src), front_inserter(dst), [](int n)
{
return (n % 3) == 0;
});
}
// const containers
{
array<const int,5> src{1,2,3,4,5};
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment