Scilab: update STL set example
Fixes: - use generic support of STL set - add example for set of string
This commit is contained in:
parent
c66952a3f0
commit
1cf1e72e72
9 changed files with 131 additions and 75 deletions
61
Examples/scilab/std_set/example.cpp
Normal file
61
Examples/scilab/std_set/example.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* File : example.cpp */
|
||||
|
||||
#include "example.hxx"
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
template <typename T>
|
||||
std::set<T> concat_set(const std::set<T> set, const std::set<T> other_set)
|
||||
{
|
||||
std::set<T> out_set(set);
|
||||
out_set.insert(other_set.begin(), other_set.end());
|
||||
return out_set;
|
||||
}
|
||||
|
||||
// int sets
|
||||
|
||||
std::set<int> create_integer_set(const int rangemin, const int rangemax)
|
||||
{
|
||||
std::set<int> out_set;
|
||||
for (int i = rangemin; i <= rangemax; i++)
|
||||
{
|
||||
out_set.insert(i);
|
||||
}
|
||||
return out_set;
|
||||
}
|
||||
|
||||
int sum_integer_set(const std::set<int>& set)
|
||||
{
|
||||
return std::accumulate(set.begin(), set.end(), 0);
|
||||
}
|
||||
|
||||
std::set<int> concat_integer_set(const std::set<int> set, const std::set<int> other_set)
|
||||
{
|
||||
return concat_set<int>(set, other_set);
|
||||
}
|
||||
|
||||
// string sets
|
||||
|
||||
std::set<std::string> create_string_set(const char* svalue)
|
||||
{
|
||||
std::set<std::string> out_set;
|
||||
std::string str(svalue);
|
||||
|
||||
std::istringstream iss(str);
|
||||
std::copy(std::istream_iterator<std::string>(iss),
|
||||
std::istream_iterator<std::string>(),
|
||||
std::inserter<std::set<std::string> >(out_set, out_set.begin()));
|
||||
|
||||
return out_set;
|
||||
}
|
||||
|
||||
std::set<std::string> concat_string_set(const std::set<std::string> set, const std::set<std::string> other_set)
|
||||
{
|
||||
return concat_set<std::string>(set, other_set);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue