40 ostream&
operator<<(ostream &s,
const vector<unique_ptr<Fahrzeug>>& v);
49 bool fuel_consumption(
const unique_ptr<Fahrzeug>& a,
const unique_ptr<Fahrzeug>& b);
53 return a->verbrauch() < b->verbrauch();
63 float add_fuel(
float x,
const unique_ptr<Fahrzeug>& y);
65 float add_fuel(
float x,
const unique_ptr<Fahrzeug>& y)
67 return x + y->verbrauch();
72 cout <<
"Hello world!" << endl;
87 cout <<
" -------- New in v_10c_unique --------------\n";
92 vector<unique_ptr<Fahrzeug>> v;
93 v.push_back( make_unique<Raba>(3600, 4000) );
94 v.push_back( make_unique<Opel>(1450) );
95 v.push_back( make_unique<MAN>(1200, 12000) );
96 v.push_back( make_unique<Smart>(950) );
97 v.push_back( make_unique<Smart>(1100) );
107 cout <<
" -------- after sort (standard --> incorrect) -------------\n";
108 sort(v.begin(),v.end());
111 cout <<
" -------- only the pointers have been compared -------------\n";
113 cout <<
" -------- after sort (compare regarding fuel consumption) -------------\n";
117 cout <<
" -------- correct-------------\n";
122 for (
unsigned int i=0; i<v.size(); ++i)
124 sum += v[i]->verbrauch();
126 cout <<
"konv: durchschnittlicher Verbrauch: " << sum/v.size() << endl;
129 float sum2 =accumulate(v.begin(), v.end(), 0.0f,
add_fuel);
130 cout <<
"accu: durchschnittlicher Verbrauch: " << sum2/v.size() << endl;
133 cout <<
" -------- sort using lambda function for 'operator>' -------------\n";
136 sort(v.begin(),v.end(),
137 [](
const unique_ptr<Fahrzeug>& aa,
const unique_ptr<Fahrzeug>& cc) ->
bool
139 return aa->verbrauch() > cc->verbrauch();
163 ostream&
operator<<(ostream &s,
const vector<unique_ptr<Fahrzeug>>& v)
165 for (
const auto& it: v)
virtual float verbrauch() const =0
virtual std::string classname() const
Class name.
ostream & operator<<(ostream &s, const Fahrzeug &p)
Prints some info from a vehicle.
float add_fuel(float x, const unique_ptr< Fahrzeug > &y)
Adds the fuel consumption of a vehicle y to quantity x.
bool fuel_consumption(const unique_ptr< Fahrzeug > &a, const unique_ptr< Fahrzeug > &b)
Compares the fuel consumption between two vehicles.