Add example for STL sets

This commit is contained in:
Simon Marchetto 2013-06-03 15:24:53 +02:00
commit 2e7a435440
5 changed files with 88 additions and 0 deletions

View file

@ -0,0 +1,29 @@
/* File : example.cpp */
#include "example.hxx"
std::set<int> create_iset(const int size, const int* values)
{
std::set<int> iset;
std::copy(values, values + size, std::inserter(iset, iset.begin()));
return iset;
}
int sum_iset(const std::set<int> iset)
{
int sum = 0;
std::set<int>::iterator it;
for (it = iset.begin(); it != iset.end(); it++)
{
sum += *it;
}
return sum;
}
void concat_iset(std::set<int>& iset, const std::set<int> other_iset)
{
std::copy(other_iset.begin(), other_iset.end(), std::inserter(iset, iset.begin()));
}