- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
class figure
{
//...
};
class triugolnik: public figure
{
//...
};
class kvadrat: public figure
{
//...
};
#define PAIR(f0, f1) std::make_tuple(std::type_index(typeid(f0)), std::type_index(typeid(f1)))
int PloshadTrehFigur(const figure& f0, const figure& f1, const figure& f2);//forward declaration
int PloshadDvuhFigur(const figure& f0, const figure& f1)
{
static const std::unordered_map<
std::tuple<std::type_index, std::type_index>, std::function<int(const figure&, const figure&)>
> caller
{
{PAIR(triugolnik, kvadrat), ploshadTriugolnikIKvadrat},
{PAIR(kvadrat, triugolnik), lispGovno::flip(ploshadTriugolnikIKvadrat)},
{PAIR(kvadrat, kvadrat), ploshadKvadratIKvadrat},
{PAIR(triugolnik, triugolnik), ploshadTriugolnikITriugolnik}
};
const auto& f = caller.find(PAIR(f0, f1));
assert(f!=caller.end());
f(f0, f1);
}
#undef PAIR