Fix example for STL vectors
This commit is contained in:
parent
c61f9b233d
commit
a61d829676
6 changed files with 84 additions and 90 deletions
|
|
@ -1,19 +1,47 @@
|
|||
/* File : example.cpp */
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "example.hxx"
|
||||
|
||||
class opt {
|
||||
public:
|
||||
void set_lower_bound(const std::vector<double> &v) {
|
||||
double sum = 0;
|
||||
std::cout << "coucou" << std::endl;
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
sum += v[i];
|
||||
std::cout << v[i] << std::endl;
|
||||
}
|
||||
//return sum;
|
||||
|
||||
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;
|
||||
for (int i = 0; i < dvector.size(); i++)
|
||||
{
|
||||
sum += dvector[i];
|
||||
}
|
||||
};
|
||||
return sum;
|
||||
}
|
||||
|
||||
int sum_ivector(const std::vector<int> ivector)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i < ivector.size(); i++)
|
||||
{
|
||||
sum += ivector[i];
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue