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 <<
" -------- New in v_10c_unique --------------\n";
75 vector<unique_ptr<Fahrzeug>> v;
78 v.push_back( unique_ptr<Fahrzeug> (
new Raba(3600, 4000)) );
79 v.push_back( unique_ptr<Fahrzeug> (
new Opel(1450)) );
80 v.push_back( unique_ptr<Fahrzeug> (
new MAN(1200, 12000)) );
81 v.push_back( unique_ptr<Fahrzeug> (
new Smart(950)) );
82 v.push_back( unique_ptr<Fahrzeug> (
new Smart(1100)) );
87 vector<unique_ptr<Fahrzeug>> w
89 make_unique<Fahrzeug> (
Raba(3600, 4000))
92 auto ip = make_unique<Raba>(
Raba(3600, 4000));
97 cout <<
" -------- after sort (standard --> incorrect) -------------\n";
98 sort(v.begin(),v.end());
101 cout <<
" -------- only the pointers have been compared -------------\n";
103 cout <<
" -------- after sort (compare regarding fuel consumption) -------------\n";
107 cout <<
" -------- correct-------------\n";
112 for (
unsigned int i=0; i<v.size(); ++i)
114 sum += v[i]->verbrauch();
116 cout <<
"konv: durchschnittlicher Verbrauch: " << sum/v.size() << endl;
119 float sum2 =accumulate(v.begin(), v.end(), 0.0f,
add_fuel);
120 cout <<
"accu: durchschnittlicher Verbrauch: " << sum2/v.size() << endl;
123 cout <<
" -------- sort using lambda function for 'operator>' -------------\n";
126 sort(v.begin(),v.end(),
127 [](
const unique_ptr<Fahrzeug>& aa,
const unique_ptr<Fahrzeug>& cc) ->
bool
129 return aa->verbrauch() > cc->verbrauch();
153 ostream&
operator<<(ostream &s,
const vector<unique_ptr<Fahrzeug>>& v)
155 for (
const auto& it: v)
virtual float verbrauch() const =0
virtual std::string classname() const
Class name.
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.
ostream & operator<<(ostream &s, const Fahrzeug &p)
Prints some info from a vehicle.