From b359c6c6de23aee057114e276b172c0ce4079e87 Mon Sep 17 00:00:00 2001 From: cxl Date: Sat, 12 Nov 2016 15:59:18 +0000 Subject: [PATCH] Core: min/max now up to 40 arguments git-svn-id: svn://ultimatepp.org/upp/trunk@10412 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Defs.h | 37 ++++++++++++++++++++-------- uppsrc/Core/init | 4 +++ uppsrc/Core/src.tpp/AppEnv$en-us.tpp | 30 ++++++---------------- 3 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 uppsrc/Core/init diff --git a/uppsrc/Core/Defs.h b/uppsrc/Core/Defs.h index 0f4531dee..8ed8082c5 100644 --- a/uppsrc/Core/Defs.h +++ b/uppsrc/Core/Defs.h @@ -216,18 +216,35 @@ static void COMBINE(MK__s, _fn)() { x } static UPP::Callexit MK__s(COMBINE(MK__s #undef max #endif +//$-template inline const T& min(const T& a, const T& b, ...); +//$-template inline const T& max(const T& a, const T& b, ...); + template inline const T& min(const T& a, const T& b) { return a < b ? a : b; } - -template inline const T& min(const T& a, const T& b, const T& c) -{ return min(a, min(b, c)); } -template inline const T& min(const T& a, const T& b, const T& c, const T& d) -{ return min(min(a, b), min(c, d)); } - template inline const T& max(const T& a, const T& b) { return a > b ? a : b; } -template inline const T& max(const T& a, const T& b, const T& c) -{ return max(a, max(b, c)); } -template inline const T& max(const T& a, const T& b, const T& c, const T& d) -{ return max(max(a, b), max(c, d)); } + +#define E__MinMaxParam(I) const T& COMBINE(p, I) +#define E__MinMaxValue(I) COMBINE(p, I) + +#define E__MinBody(I) \ +template \ +const T& min(const T& a, const T& b, __List##I(E__MinMaxParam)) \ +{\ + return min(a, min(b, __List##I(E__MinMaxValue))); \ +} \ + +__Expand40(E__MinBody) + +#define E__MaxBody(I) \ +template \ +const T& max(const T& a, const T& b, __List##I(E__MinMaxParam)) \ +{\ + return max(a, max(b, __List##I(E__MinMaxValue))); \ +} \ + +__Expand40(E__MaxBody) + +//$+ + template // deprecated name, use clamp inline T minmax(T x, T _min, T _max) { return min(max(x, _min), _max); } diff --git a/uppsrc/Core/init b/uppsrc/Core/init new file mode 100644 index 000000000..7eb91cbdd --- /dev/null +++ b/uppsrc/Core/init @@ -0,0 +1,4 @@ +#ifndef _Core_icpp_init_stub +#define _Core_icpp_init_stub +#include "plugin\z/init" +#endif diff --git a/uppsrc/Core/src.tpp/AppEnv$en-us.tpp b/uppsrc/Core/src.tpp/AppEnv$en-us.tpp index 5e1c4864e..9de73e7e8 100644 --- a/uppsrc/Core/src.tpp/AppEnv$en-us.tpp +++ b/uppsrc/Core/src.tpp/AppEnv$en-us.tpp @@ -167,33 +167,17 @@ URL that will be opened in the browser&] [s4; &] [s5;:CpuMMX`(`): [@(0.0.255) bool]_[* CpuMMX]()&] [s2;%% Returns true if CPU has MMX support.&] -[s3; &] +[s3;%% &] [s4; &] -[s5;:min`(const T`&`,const T`&`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T]>_[@(0.0.255) c -onst]_[*@4 T][@(0.0.255) `&]_[* min]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 a], -[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 b])&] -[s5;:min`(const T`&`,const T`&`,const T`&`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T -]>_[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[* min]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_ -[*@3 a], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 b], [@(0.0.255) const]_[*@4 T][@(0.0.255) `& -]_[*@3 c])&] -[s5;:min`(const T`&`,const T`&`,const T`&`,const T`&`): [@(0.0.255) template]_<[@(0.0.255) c -lass]_[*@4 T]>_[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[* min]([@(0.0.255) const]_[*@4 T][@(0.0.255) `& -]_[*@3 a], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 b], [@(0.0.255) const]_[*@4 T][@(0.0.255) `& -]_[*@3 c], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 d])&] +[s5;:Upp`:`:min`(const T`&`,const T`&`,`.`.`.`): [@(0.0.255) template]_<[@(0.0.255) class +]_[*@4 T]>_[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[* min]([@(0.0.255) const]_[*@4 T][@(0.0.255) `& +]_[*@3 a], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 b], ...)&] [s2;%% Returns the least of all arguments.&] [s3;%% &] [s4; &] -[s5;:max`(const T`&`,const T`&`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T]>_[@(0.0.255) c -onst]_[*@4 T][@(0.0.255) `&]_[* max]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 a], -[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 b])&] -[s5;:max`(const T`&`,const T`&`,const T`&`): [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T -]>_[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[* max]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_ -[*@3 a], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 b], [@(0.0.255) const]_[*@4 T][@(0.0.255) `& -]_[*@3 c])&] -[s5;:max`(const T`&`,const T`&`,const T`&`,const T`&`): [@(0.0.255) template]_<[@(0.0.255) c -lass]_[*@4 T]>_[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[* max]([@(0.0.255) const]_[*@4 T][@(0.0.255) `& -]_[*@3 a], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 b], [@(0.0.255) const]_[*@4 T][@(0.0.255) `& -]_[*@3 c], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 d])&] +[s5;:Upp`:`:max`(const T`&`,const T`&`,`.`.`.`): [@(0.0.255) template]_<[@(0.0.255) class +]_[*@4 T]>_[@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[* max]([@(0.0.255) const]_[*@4 T][@(0.0.255) `& +]_[*@3 a], [@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 b], ...)&] [s2;%% Returns the greatest of all arguments.&] [s3;%% &] [s4; &]