Scilab: update STL vector example with vector<string>
This commit is contained in:
parent
8ee91b4352
commit
9bdeb67312
3 changed files with 38 additions and 17 deletions
|
|
@ -2,17 +2,13 @@
|
|||
|
||||
#include "example.hxx"
|
||||
|
||||
// double vectors
|
||||
|
||||
std::vector<double> create_dvector(const int size, const double value)
|
||||
{
|
||||
return std::vector<double>(size, value);
|
||||
}
|
||||
|
||||
std::vector<int> create_ivector(const int size, const int value)
|
||||
{
|
||||
return std::vector<int>(size, value);
|
||||
}
|
||||
|
||||
double sum_dvector(const std::vector<double> dvector)
|
||||
{
|
||||
double sum = 0;
|
||||
|
|
@ -23,6 +19,18 @@ double sum_dvector(const std::vector<double> dvector)
|
|||
return sum;
|
||||
}
|
||||
|
||||
void concat_dvector(std::vector<double>& dvector, const std::vector<double> other_dvector)
|
||||
{
|
||||
dvector.insert(dvector.end(), other_dvector.begin(), other_dvector.end());
|
||||
}
|
||||
|
||||
// int vectors
|
||||
|
||||
std::vector<int> create_ivector(const int size, const int value)
|
||||
{
|
||||
return std::vector<int>(size, value);
|
||||
}
|
||||
|
||||
int sum_ivector(const std::vector<int> ivector)
|
||||
{
|
||||
int sum = 0;
|
||||
|
|
@ -33,15 +41,19 @@ int sum_ivector(const std::vector<int> ivector)
|
|||
return sum;
|
||||
}
|
||||
|
||||
void concat_dvector(std::vector<double>& dvector, const std::vector<double> other_dvector)
|
||||
{
|
||||
dvector.insert(dvector.end(), other_dvector.begin(), other_dvector.end());
|
||||
}
|
||||
|
||||
void concat_ivector(std::vector<int>& ivector, const std::vector<int> other_ivector)
|
||||
{
|
||||
ivector.insert(ivector.end(), other_ivector.begin(), other_ivector.end());
|
||||
}
|
||||
|
||||
// string vectors
|
||||
|
||||
std::vector<std::string> create_svector(const int size, const char* value)
|
||||
{
|
||||
return std::vector<std::string>(size, value);
|
||||
}
|
||||
|
||||
void concat_svector(std::vector<std::string>& svector, const std::vector<std::string> other_svector)
|
||||
{
|
||||
svector.insert(svector.end(), other_svector.begin(), other_svector.end());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/* File : example.hxx */
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
std::vector<double> create_dvector(const int size, const double value);
|
||||
std::vector<int> create_ivector(const int size, const int value);
|
||||
|
||||
double sum_dvector(const std::vector<double> dvector);
|
||||
int sum_ivector(const std::vector<int> ivector);
|
||||
|
||||
void concat_dvector(std::vector<double>& dvector, const std::vector<double> other_dvector);
|
||||
|
||||
std::vector<int> create_ivector(const int size, const int value);
|
||||
int sum_ivector(const std::vector<int> ivector);
|
||||
void concat_ivector(std::vector<int>& ivector, const std::vector<int> other_ivector);
|
||||
|
||||
|
||||
|
||||
std::vector<std::string> create_svector(const int size, const char* value);
|
||||
void concat_svector(std::vector<std::string>& svector, const std::vector<std::string> other_svector);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,18 @@ is = sum_ivector(iv);
|
|||
disp("sum of this vector elements is:");
|
||||
disp(is);
|
||||
iv2 = create_ivector(2, 1);
|
||||
disp("concat this vector with the vector of int {1, 1}:");
|
||||
disp("concat this vector with the vector of ints {1, 1}:");
|
||||
iv3 = concat_ivector(iv, iv2);
|
||||
disp(iv3);
|
||||
|
||||
disp("now an example with vectors of string.");
|
||||
disp("create the vector of string {''aa'', ''aa''}:");
|
||||
sv = create_svector(2, "aa");
|
||||
disp(sv);
|
||||
sv2 = create_svector(2, "bb");
|
||||
disp("concat this vector with the vector of string {''bb'', ''bb''}:");
|
||||
sv3 = concat_svector(sv, sv2);
|
||||
disp(sv3);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue