space_age: iteration 1, X-macros version
This commit is contained in:
parent
af9aad2d97
commit
8d461d793e
1 changed files with 20 additions and 36 deletions
|
|
@ -2,6 +2,25 @@
|
||||||
|
|
||||||
namespace space_age {
|
namespace space_age {
|
||||||
|
|
||||||
|
#define PLANET_TABLE \
|
||||||
|
X(on_mercury, 0.2408467) \
|
||||||
|
X(on_venus, 0.61519726) \
|
||||||
|
X(on_mars, 1.8808158) \
|
||||||
|
X(on_jupiter, 11.862615) \
|
||||||
|
X(on_saturn, 29.447498) \
|
||||||
|
X(on_uranus, 84.016846) \
|
||||||
|
X(on_neptune, 164.79132)
|
||||||
|
|
||||||
|
#define X(a, b) \
|
||||||
|
double space_age:: a () const \
|
||||||
|
{ \
|
||||||
|
return on_earth() / b; \
|
||||||
|
}
|
||||||
|
|
||||||
|
PLANET_TABLE
|
||||||
|
#undef X
|
||||||
|
|
||||||
|
|
||||||
space_age::space_age(double seconds)
|
space_age::space_age(double seconds)
|
||||||
: seconds_(seconds)
|
: seconds_(seconds)
|
||||||
{
|
{
|
||||||
|
|
@ -17,39 +36,4 @@ double space_age::on_earth() const
|
||||||
return seconds() / 31557600;
|
return seconds() / 31557600;
|
||||||
}
|
}
|
||||||
|
|
||||||
double space_age::on_mercury() const
|
|
||||||
{
|
|
||||||
return on_earth() / 0.2408467;
|
|
||||||
}
|
|
||||||
|
|
||||||
double space_age::on_venus() const
|
|
||||||
{
|
|
||||||
return on_earth() / 0.61519726;
|
|
||||||
}
|
|
||||||
|
|
||||||
double space_age::on_mars() const
|
|
||||||
{
|
|
||||||
return on_earth() / 1.8808158;
|
|
||||||
}
|
|
||||||
|
|
||||||
double space_age::on_jupiter() const
|
|
||||||
{
|
|
||||||
return on_earth() / 11.862615;
|
|
||||||
}
|
|
||||||
|
|
||||||
double space_age::on_saturn() const
|
|
||||||
{
|
|
||||||
return on_earth() / 29.447498;
|
|
||||||
}
|
|
||||||
|
|
||||||
double space_age::on_uranus() const
|
|
||||||
{
|
|
||||||
return on_earth() / 84.016846;
|
|
||||||
}
|
|
||||||
|
|
||||||
double space_age::on_neptune() const
|
|
||||||
{
|
|
||||||
return on_earth() / 164.79132;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue