Browse Source

MSVC 2013 compatibility: workaround for "can't deduce T" bug.

Somehow it's not possible to deduce template parameter if used as
default function arguments. You just can't make this up.
Vladimír Vondruš 13 years ago
parent
commit
1004d33c7c
  1. 91
      src/Color.h

91
src/Color.h

@ -164,7 +164,12 @@ template<class T> class BasicColor3: public Math::Vector3<T> {
* floating-point underlying type equivalent to @ref Vector3::xAxis().
* @see @ref green(), @ref blue(), @ref cyan()
*/
constexpr static BasicColor3<T> red(T red = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor3<T> red(T red = Implementation::fullChannel<T>())
#else
constexpr static BasicColor3<T> red(T red = fullChannel())
#endif
{
return Math::Vector3<T>::xAxis(red);
}
@ -175,7 +180,12 @@ template<class T> class BasicColor3: public Math::Vector3<T> {
* floating-point underlying type equivalent to @ref Vector3::yAxis().
* @see @ref red(), @ref blue(), @ref magenta()
*/
constexpr static BasicColor3<T> green(T green = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor3<T> green(T green = Implementation::fullChannel<T>())
#else
constexpr static BasicColor3<T> green(T green = fullChannel())
#endif
{
return Math::Vector3<T>::yAxis(green);
}
@ -186,7 +196,12 @@ template<class T> class BasicColor3: public Math::Vector3<T> {
* floating-point underlying type equivalent to @ref Vector3::zAxis().
* @see @ref red(), @ref green(), @ref yellow()
*/
constexpr static BasicColor3<T> blue(T blue = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor3<T> blue(T blue = Implementation::fullChannel<T>())
#else
constexpr static BasicColor3<T> blue(T blue = fullChannel())
#endif
{
return Math::Vector3<T>::zAxis(blue);
}
@ -327,6 +342,12 @@ template<class T> class BasicColor3: public Math::Vector3<T> {
}
MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(3, BasicColor3)
#ifdef CORRADE_MSVC2013_COMPATIBILITY
private:
template<class U = T, class = typename std::enable_if<std::is_floating_point<T>::value, T>::type> constexpr static T fullChannel() { return T(1); }
template<class U = T, class V = T, class = typename std::enable_if<std::is_integral<T>::value, T>::type> constexpr static T fullChannel() { return std::numeric_limits<T>::max(); }
#endif
};
/** @brief Three-component (RGB) float color */
@ -361,7 +382,12 @@ class BasicColor4: public Math::Vector4<T> {
* Convenience alternative to e.g. `%Color4(red, 0.0f, 0.0f, alpha)`.
* @see @ref green(), @ref blue(), @ref cyan()
*/
constexpr static BasicColor4<T> red(T red = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor4<T> red(T red = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>())
#else
constexpr static BasicColor4<T> red(T red = fullChannel(), T alpha = fullChannel())
#endif
{
return {red, T(0), T(0), alpha};
}
@ -371,7 +397,12 @@ class BasicColor4: public Math::Vector4<T> {
* Convenience alternative to e.g. `%Color4(0.0f, green, 0.0f, alpha)`.
* @see @ref red(), @ref blue(), @ref magenta()
*/
constexpr static BasicColor4<T> green(T green = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor4<T> green(T green = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>())
#else
constexpr static BasicColor4<T> green(T green = fullChannel(), T alpha = fullChannel())
#endif
{
return {T(0), green, T(0), alpha};
}
@ -381,7 +412,12 @@ class BasicColor4: public Math::Vector4<T> {
* Convenience alternative to e.g. `%Color4(0.0f, 0.0f, blue, alpha)`.
* @see @ref red(), @ref green(), @ref yellow()
*/
constexpr static BasicColor4<T> blue(T blue = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor4<T> blue(T blue = Implementation::fullChannel<T>(), T alpha = Implementation::fullChannel<T>())
#else
constexpr static BasicColor4<T> blue(T blue = fullChannel(), T alpha = fullChannel())
#endif
{
return {T(0), T(0), blue, alpha};
}
@ -391,7 +427,12 @@ class BasicColor4: public Math::Vector4<T> {
* Convenience alternative to e.g. `%Color4(red, 1.0f, 1.0f, alpha)`.
* @see @ref magenta(), @ref yellow(), @ref red()
*/
constexpr static BasicColor4<T> cyan(T red = T(0), T alpha = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor4<T> cyan(T red = T(0), T alpha = Implementation::fullChannel<T>())
#else
constexpr static BasicColor4<T> cyan(T red = T(0), T alpha = fullChannel())
#endif
{
return {red, Implementation::fullChannel<T>(), Implementation::fullChannel<T>(), alpha};
}
@ -401,7 +442,12 @@ class BasicColor4: public Math::Vector4<T> {
* Convenience alternative to e.g. `%Color4(1.0f, green, 1.0f, alpha)`.
* @see @ref cyan(), @ref yellow(), @ref green()
*/
constexpr static BasicColor4<T> magenta(T green = T(0), T alpha = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor4<T> magenta(T green = T(0), T alpha = Implementation::fullChannel<T>())
#else
constexpr static BasicColor4<T> magenta(T green = T(0), T alpha = fullChannel())
#endif
{
return {Implementation::fullChannel<T>(), green, Implementation::fullChannel<T>(), alpha};
}
@ -411,7 +457,12 @@ class BasicColor4: public Math::Vector4<T> {
* Convenience alternative to e.g. `%Color4(1.0f, 1.0f, blue, alpha)`.
* @see @ref cyan(), @ref magenta(), @ref red()
*/
constexpr static BasicColor4<T> yellow(T blue = T(0), T alpha = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor4<T> yellow(T blue = T(0), T alpha = Implementation::fullChannel<T>())
#else
constexpr static BasicColor4<T> yellow(T blue = T(0), T alpha = fullChannel())
#endif
{
return {Implementation::fullChannel<T>(), Implementation::fullChannel<T>(), blue, alpha};
}
@ -420,7 +471,12 @@ class BasicColor4: public Math::Vector4<T> {
* @param a Alpha value, defaults to 1.0 for floating-point types
* and maximum positive value for integral types.
*/
constexpr static BasicColor4<T> fromHSV(HSV hsv, T a = Implementation::fullChannel<T>()) {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr static BasicColor4<T> fromHSV(HSV hsv, T a = Implementation::fullChannel<T>())
#else
constexpr static BasicColor4<T> fromHSV(HSV hsv, T a = fullChannel())
#endif
{
return BasicColor4<T>(Implementation::fromHSV<T>(hsv), a);
}
/** @overload */
@ -444,8 +500,7 @@ class BasicColor4: public Math::Vector4<T> {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr explicit BasicColor4(T rgb, T alpha = Implementation::fullChannel<T>()): Math::Vector4<T>(rgb, rgb, rgb, alpha) {}
#else
template<class U = T, class = typename std::enable_if<std::is_floating_point<T>::value, T>::type> constexpr explicit BasicColor4(T rgb, T alpha = T(1)): Math::Vector4<T>(rgb, rgb, rgb, alpha) {}
template<class U = T, class V = T, class = typename std::enable_if<std::is_integral<T>::value, T>::type> constexpr explicit BasicColor4(T rgb, T alpha = std::numeric_limits<T>::max()): Math::Vector4<T>(rgb, rgb, rgb, alpha) {}
constexpr explicit BasicColor4(T rgb, T alpha = fullChannel()): Math::Vector4<T>(rgb, rgb, rgb, alpha) {}
#endif
/**
@ -459,8 +514,7 @@ class BasicColor4: public Math::Vector4<T> {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = Implementation::fullChannel<T>()): Math::Vector4<T>(r, g, b, a) {}
#else
template<class U = T, class = typename std::enable_if<std::is_floating_point<T>::value, T>::type> constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = T(1)): Math::Vector4<T>(r, g, b, a) {}
template<class U = T, class V = T, class = typename std::enable_if<std::is_integral<T>::value, T>::type> constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = std::numeric_limits<T>::max()): Math::Vector4<T>(r, g, b, a) {}
constexpr /*implicit*/ BasicColor4(T r, T g, T b, T a = fullChannel()): Math::Vector4<T>(r, g, b, a) {}
#endif
/**
@ -473,8 +527,7 @@ class BasicColor4: public Math::Vector4<T> {
#ifndef CORRADE_MSVC2013_COMPATIBILITY
constexpr /*implicit*/ BasicColor4(const Math::Vector3<T>& rgb, T a = Implementation::fullChannel<T>()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {}
#else
template<class U = T, class = typename std::enable_if<std::is_floating_point<T>::value, T>::type> constexpr /*implicit*/ BasicColor4(const Math::Vector3<T>& rgb, T a = T(1)): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {}
template<class U = T, class V = T, class = typename std::enable_if<std::is_integral<T>::value, T>::type> constexpr /*implicit*/ BasicColor4(const Math::Vector3<T>& rgb, T a = std::numeric_limits<T>::max()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {}
constexpr /*implicit*/ BasicColor4(const Math::Vector3<T>& rgb, T a = fullChannel()): Math::Vector4<T>(rgb[0], rgb[1], rgb[2], a) {}
#endif
/**
@ -510,6 +563,12 @@ class BasicColor4: public Math::Vector4<T> {
}
MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(4, BasicColor4)
#ifdef CORRADE_MSVC2013_COMPATIBILITY
private:
template<class U = T, class = typename std::enable_if<std::is_floating_point<T>::value, T>::type> constexpr static T fullChannel() { return T(1); }
template<class U = T, class V = T, class = typename std::enable_if<std::is_integral<T>::value, T>::type> constexpr static T fullChannel() { return std::numeric_limits<T>::max(); }
#endif
};
/** @brief Four-component (RGBA) float color */

Loading…
Cancel
Save