Код: Выделить всё
namespace math
{
/** Min of two elements */
template
T min(const T a, const T b)
{
return (a < b) ? a : b;
}
/** Min of multiple elements */
template
T min(const T first, const Ts... others)
{
T result = first;
auto temp = { (result = math::min(result, others), 0)... };
(void)temp;
return result;
}
}
Код: Выделить всё
/** Vec2 */
struct Vec2
{
float x, y;
Vec2(const float _x, const float _y) : x(_x), y(_y) {}
};
namespace math
{
/** Min override for Vec2 */
Vec2 min(const Vec2 a, const Vec2 b)
{
return Vec2(math::min(a.x, b.x), math::min(a.y, b.y));
}
}
Код: Выделить всё
extern Vec2 getNewVec2();
int main()
{
Vec2 v1 = getNewVec2();
Vec2 v2 = getNewVec2();
Vec2 v3 = getNewVec2();
Vec2 v_min = math::min(v1, v2, v3);
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... antiations
Мобильная версия