From ea45b8acd25785bd2789c2c1928e223c9a8e2fbd Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 19 Aug 2013 14:17:17 -0700 Subject: BUILDFIX: refactored decltype out into traits class --- indra/llcommon/llpreprocessor.h | 6 +-- indra/llcommon/llunit.h | 110 +++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 56 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llpreprocessor.h b/indra/llcommon/llpreprocessor.h index a764a42fca..e5c8482ed1 100755 --- a/indra/llcommon/llpreprocessor.h +++ b/indra/llcommon/llpreprocessor.h @@ -182,10 +182,10 @@ #endif // LL_COMMON_LINK_SHARED #if LL_WINDOWS -#define LLTYPEOF(exp) decltype(exp) +#define LL_TYPEOF(exp) decltype(exp) #elif LL_LINUX -#define LLTYPEOF(exp) typeof(exp) +#define LL_TYPEOF(exp) typeof(exp) #elif LL_DARWIN -#define LLTYPEOF(exp) typeof(exp) +#define LL_TYPEOF(exp) typeof(exp) #endif #endif // not LL_LINDEN_PREPROCESSOR_H diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 7afb1089ba..67810ffabc 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -44,10 +44,14 @@ struct LLIsSameType static const bool value = true; }; +// workaround for decltype() not existing and typeof() not working inline in gcc 4.2 template -struct LLPromotedType +struct LLResultType { - typedef LLTYPEOF(S() + T()) type_t; + typedef LL_TYPEOF(S() + T()) add_t; + typedef LL_TYPEOF(S() - T()) subtract_t; + typedef LL_TYPEOF(S() * T()) multiply_t; + typedef LL_TYPEOF(S() / T(1)) divide_t; }; template @@ -262,9 +266,9 @@ LL_FORCE_INLINE void ll_convert_units(LLUnit in, LLUnit& out, .. // operator + // template -LLUnit operator + (LLUnit first, LLUnit second) +LLUnit::add_t, UNIT_TYPE1> operator + (LLUnit first, LLUnit second) { - LLUnit result(first); + LLUnit::add_t, UNIT_TYPE1> result(first); result += second; return result; } @@ -284,41 +288,41 @@ LLUnit operator + (UNITLESS first, LLUnit -LLUnitImplicit operator + (LLUnitImplicit first, LLUnitImplicit second) +LLUnitImplicit::add_t, UNIT_TYPE1> operator + (LLUnitImplicit first, LLUnitImplicit second) { - LLUnitImplicit result(first); + LLUnitImplicit::add_t, UNIT_TYPE1> result(first); result += second; return result; } template -LLUnitImplicit operator + (LLUnit first, LLUnitImplicit second) +LLUnitImplicit::add_t, UNIT_TYPE1> operator + (LLUnit first, LLUnitImplicit second) { - LLUnitImplicit result(first); + LLUnitImplicit::add_t, UNIT_TYPE1> result(first); result += second; return result; } template -LLUnitImplicit operator + (LLUnitImplicit first, LLUnit second) +LLUnitImplicit::add_t, UNIT_TYPE1> operator + (LLUnitImplicit first, LLUnit second) { - LLUnitImplicit result(first); + LLUnitImplicit::add_t, UNIT_TYPE1> result(first); result += LLUnitImplicit(second); return result; } template -LLUnitImplicit operator + (LLUnitImplicit first, UNITLESS_TYPE second) +LLUnitImplicit::add_t, UNIT_TYPE> operator + (LLUnitImplicit first, UNITLESS_TYPE second) { - LLUnitImplicit result(first); + LLUnitImplicit::add_t, UNIT_TYPE> result(first); result += second; return result; } template -LLUnitImplicit operator + (UNITLESS_TYPE first, LLUnitImplicit second) +LLUnitImplicit::add_t, UNIT_TYPE> operator + (UNITLESS_TYPE first, LLUnitImplicit second) { - LLUnitImplicit result(first); + LLUnitImplicit::add_t, UNIT_TYPE> result(first); result += second; return result; } @@ -327,9 +331,9 @@ LLUnitImplicit operator + // operator - // template -LLUnit operator - (LLUnit first, LLUnit second) +LLUnit::subtract_t, UNIT_TYPE1> operator - (LLUnit first, LLUnit second) { - LLUnit result(first); + LLUnit::subtract_t, UNIT_TYPE1> result(first); result -= second; return result; } @@ -349,41 +353,41 @@ LLUnit operator - (UNITLESS first, LLUnit -LLUnitImplicit operator - (LLUnitImplicit first, LLUnitImplicit second) +LLUnitImplicit::subtract_t, UNIT_TYPE1> operator - (LLUnitImplicit first, LLUnitImplicit second) { - LLUnitImplicit result(first); + LLUnitImplicit::subtract_t, UNIT_TYPE1> result(first); result -= second; return result; } template -LLUnitImplicit operator - (LLUnit first, LLUnitImplicit second) +LLUnitImplicit::subtract_t, UNIT_TYPE1> operator - (LLUnit first, LLUnitImplicit second) { - LLUnitImplicit result(first); + LLUnitImplicit::subtract_t, UNIT_TYPE1> result(first); result -= second; return result; } template -LLUnitImplicit operator - (LLUnitImplicit first, LLUnit second) +LLUnitImplicit::subtract_t, UNIT_TYPE1> operator - (LLUnitImplicit first, LLUnit second) { - LLUnitImplicit result(first); + LLUnitImplicit::subtract_t, UNIT_TYPE1> result(first); result -= LLUnitImplicit(second); return result; } template -LLUnitImplicit operator - (LLUnitImplicit first, UNITLESS_TYPE second) +LLUnitImplicit::subtract_t, UNIT_TYPE> operator - (LLUnitImplicit first, UNITLESS_TYPE second) { - LLUnitImplicit result(first); + LLUnitImplicit::subtract_t, UNIT_TYPE> result(first); result -= second; return result; } template -LLUnitImplicit operator - (UNITLESS_TYPE first, LLUnitImplicit second) +LLUnitImplicit::subtract_t, UNIT_TYPE> operator - (UNITLESS_TYPE first, LLUnitImplicit second) { - LLUnitImplicit result(first); + LLUnitImplicit::subtract_t, UNIT_TYPE> result(first); result -= second; return result; } @@ -400,15 +404,15 @@ LLUnit operator * (LLUnit, } template -LLUnit operator * (LLUnit first, UNITLESS_TYPE second) +LLUnit::multiply_t, UNIT_TYPE> operator * (LLUnit first, UNITLESS_TYPE second) { - return LLUnit(first.value() * second); + return LLUnit::multiply_t, UNIT_TYPE>(first.value() * second); } template -LLUnit operator * (UNITLESS_TYPE first, LLUnit second) +LLUnit::multiply_t, UNIT_TYPE> operator * (UNITLESS_TYPE first, LLUnit second) { - return LLUnit(first * second.value()); + return LLUnit::multiply_t, UNIT_TYPE>(first * second.value()); } template @@ -420,15 +424,15 @@ LLUnitImplicit operator * (LLUnitImplicit -LLUnitImplicit operator * (LLUnitImplicit first, UNITLESS_TYPE second) +LLUnitImplicit::multiply_t, UNIT_TYPE> operator * (LLUnitImplicit first, UNITLESS_TYPE second) { - return LLUnitImplicit(first.value() * second); + return LLUnitImplicit::multiply_t, UNIT_TYPE>(first.value() * second); } template -LLUnitImplicit operator * (UNITLESS_TYPE first, LLUnitImplicit second) +LLUnitImplicit::multiply_t, UNIT_TYPE> operator * (UNITLESS_TYPE first, LLUnitImplicit second) { - return LLUnitImplicit(first * second.value()); + return LLUnitImplicit::multiply_t, UNIT_TYPE>(first * second.value()); } @@ -437,39 +441,39 @@ LLUnitImplicit operator * // template -LLUnit operator / (LLUnit first, UNITLESS_TYPE second) +LLUnit::divide_t, UNIT_TYPE> operator / (LLUnit first, UNITLESS_TYPE second) { - return LLUnit(first.value() / second); + return LLUnit::divide_t, UNIT_TYPE>(first.value() / second); } template -LLTYPEOF(STORAGE_TYPE1() / STORAGE_TYPE2(1)) operator / (LLUnit first, LLUnit second) +typename LLResultType::divide_t operator / (LLUnit first, LLUnit second) { return first.value() / first.convert(second).value(); } template -LLUnitImplicit operator / (LLUnitImplicit first, UNITLESS_TYPE second) +LLUnitImplicit::divide_t, UNIT_TYPE> operator / (LLUnitImplicit first, UNITLESS_TYPE second) { - return LLUnitImplicit(first.value() / second); + return LLUnitImplicit::divide_t, UNIT_TYPE>(first.value() / second); } template -LLTYPEOF(STORAGE_TYPE1() / STORAGE_TYPE2(1)) operator / (LLUnitImplicit first, LLUnitImplicit second) +typename LLResultType::divide_t operator / (LLUnitImplicit first, LLUnitImplicit second) { - return (LLTYPEOF(STORAGE_TYPE1() / STORAGE_TYPE2(1)))(first.value() / first.convert(second).value()); + return (typename LLResultType::divide_t)(first.value() / first.convert(second).value()); } template -LLTYPEOF(STORAGE_TYPE1() / STORAGE_TYPE2(1)) operator / (LLUnit first, LLUnitImplicit second) +typename LLResultType::divide_t operator / (LLUnit first, LLUnitImplicit second) { - return (LLTYPEOF(STORAGE_TYPE1() / STORAGE_TYPE2()))(first.value() / first.convert(second).value()); + return (typename LLResultType::divide_t)(first.value() / first.convert(second).value()); } template -LLTYPEOF(STORAGE_TYPE1() / STORAGE_TYPE2(1)) operator / (LLUnitImplicit first, LLUnit second) +typename LLResultType::divide_t operator / (LLUnitImplicit first, LLUnit second) { - return (LLTYPEOF(STORAGE_TYPE1() / STORAGE_TYPE2()))(first.value() / first.convert(second).value()); + return (typename LLResultType::divide_t)(first.value() / first.convert(second).value()); } // @@ -562,25 +566,25 @@ struct LLUnitLinearOps template output_t operator * (T other) { - return typename LLPromotedType::type_t(mInput) * other; + return typename LLResultType::multiply_t(mInput) * other; } template output_t operator / (T other) { - return typename LLPromotedType::type_t(mInput) / other; + return typename LLResultType::divide_t(mInput) / other; } template output_t operator + (T other) { - return typename LLPromotedType::type_t(mInput) + other; + return typename LLResultType::add_t(mInput) + other; } template output_t operator - (T other) { - return typename LLPromotedType::type_t(mInput) - other; + return typename LLResultType::subtract_t(mInput) - other; } }; @@ -599,25 +603,25 @@ struct LLUnitInverseLinearOps template output_t operator * (T other) { - return typename LLPromotedType::type_t(mInput) / other; + return typename LLResultType::divide_t(mInput) / other; } template output_t operator / (T other) { - return typename LLPromotedType::type_t(mInput) * other; + return typename LLResultType::multiply_t(mInput) * other; } template output_t operator + (T other) { - return typename LLPromotedType::type_t(mInput) - other; + return typename LLResultType::subtract_t(mInput) - other; } template output_t operator - (T other) { - return typename LLPromotedType::type_t(mInput) + other; + return typename LLResultType::add_t(mInput) + other; } }; -- cgit v1.2.3