mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added macros JUCE_CONSTEXPR and JUCE_HAS_CONSTEXPR to support constexpr
This commit is contained in:
parent
7bae8a426b
commit
4a2a5294a7
2 changed files with 48 additions and 30 deletions
|
|
@ -47,6 +47,10 @@
|
|||
#define JUCE_COMPILER_SUPPORTS_THREAD_LOCAL 1
|
||||
#endif
|
||||
|
||||
#if __cpp_constexpr >= 201304
|
||||
#define JUCE_HAS_CONSTEXPR 1
|
||||
#endif
|
||||
|
||||
#ifndef JUCE_EXCEPTIONS_DISABLED
|
||||
#if ! __EXCEPTIONS
|
||||
#define JUCE_EXCEPTIONS_DISABLED 1
|
||||
|
|
@ -86,6 +90,10 @@
|
|||
#define JUCE_COMPILER_SUPPORTS_OVERRIDE_AND_FINAL 1
|
||||
#endif
|
||||
|
||||
#if __has_feature(cxx_relaxed_constexpr)
|
||||
#define JUCE_HAS_CONSTEXPR 1
|
||||
#endif
|
||||
|
||||
#ifndef JUCE_COMPILER_SUPPORTS_ARC
|
||||
#define JUCE_COMPILER_SUPPORTS_ARC 1
|
||||
#endif
|
||||
|
|
@ -118,6 +126,10 @@
|
|||
#define JUCE_COMPILER_SUPPORTS_NOEXCEPT 1
|
||||
#endif
|
||||
|
||||
#if _MSC_VER >= 1910
|
||||
#define JUCE_HAS_CONSTEXPR 1
|
||||
#endif
|
||||
|
||||
#ifndef JUCE_EXCEPTIONS_DISABLED
|
||||
#if ! _CPPUNWIND
|
||||
#define JUCE_EXCEPTIONS_DISABLED 1
|
||||
|
|
@ -137,6 +149,12 @@
|
|||
#define JUCE_DELETED_FUNCTION
|
||||
#endif
|
||||
|
||||
#if JUCE_HAS_CONSTEXPR
|
||||
#define JUCE_CONSTEXPR constexpr
|
||||
#else
|
||||
#define JUCE_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if ! DOXYGEN
|
||||
#if ! JUCE_COMPILER_SUPPORTS_NOEXCEPT
|
||||
#ifdef noexcept
|
||||
|
|
|
|||
|
|
@ -41,101 +41,101 @@ class Point
|
|||
{
|
||||
public:
|
||||
/** Creates a point at the origin */
|
||||
Point() noexcept : x(), y() {}
|
||||
JUCE_CONSTEXPR Point() noexcept : x(), y() {}
|
||||
|
||||
/** Creates a copy of another point. */
|
||||
Point (const Point& other) noexcept : x (other.x), y (other.y) {}
|
||||
JUCE_CONSTEXPR Point (const Point& other) noexcept : x (other.x), y (other.y) {}
|
||||
|
||||
/** Creates a point from an (x, y) position. */
|
||||
Point (ValueType initialX, ValueType initialY) noexcept : x (initialX), y (initialY) {}
|
||||
JUCE_CONSTEXPR Point (ValueType initialX, ValueType initialY) noexcept : x (initialX), y (initialY) {}
|
||||
|
||||
//==============================================================================
|
||||
/** Copies this point from another one. */
|
||||
Point& operator= (const Point& other) noexcept { x = other.x; y = other.y; return *this; }
|
||||
Point& operator= (const Point& other) noexcept { x = other.x; y = other.y; return *this; }
|
||||
|
||||
inline bool operator== (Point other) const noexcept { return x == other.x && y == other.y; }
|
||||
inline bool operator!= (Point other) const noexcept { return x != other.x || y != other.y; }
|
||||
JUCE_CONSTEXPR inline bool operator== (Point other) const noexcept { return x == other.x && y == other.y; }
|
||||
JUCE_CONSTEXPR inline bool operator!= (Point other) const noexcept { return x != other.x || y != other.y; }
|
||||
|
||||
/** Returns true if the point is (0, 0). */
|
||||
bool isOrigin() const noexcept { return x == ValueType() && y == ValueType(); }
|
||||
JUCE_CONSTEXPR bool isOrigin() const noexcept { return x == ValueType() && y == ValueType(); }
|
||||
|
||||
/** Returns true if the coordinates are finite values. */
|
||||
inline bool isFinite() const noexcept { return juce_isfinite(x) && juce_isfinite(y); }
|
||||
JUCE_CONSTEXPR inline bool isFinite() const noexcept { return juce_isfinite(x) && juce_isfinite(y); }
|
||||
|
||||
/** Returns the point's x coordinate. */
|
||||
inline ValueType getX() const noexcept { return x; }
|
||||
JUCE_CONSTEXPR inline ValueType getX() const noexcept { return x; }
|
||||
|
||||
/** Returns the point's y coordinate. */
|
||||
inline ValueType getY() const noexcept { return y; }
|
||||
JUCE_CONSTEXPR inline ValueType getY() const noexcept { return y; }
|
||||
|
||||
/** Sets the point's x coordinate. */
|
||||
inline void setX (ValueType newX) noexcept { x = newX; }
|
||||
inline void setX (ValueType newX) noexcept { x = newX; }
|
||||
|
||||
/** Sets the point's y coordinate. */
|
||||
inline void setY (ValueType newY) noexcept { y = newY; }
|
||||
inline void setY (ValueType newY) noexcept { y = newY; }
|
||||
|
||||
/** Returns a point which has the same Y position as this one, but a new X. */
|
||||
Point withX (ValueType newX) const noexcept { return Point (newX, y); }
|
||||
JUCE_CONSTEXPR Point withX (ValueType newX) const noexcept { return Point (newX, y); }
|
||||
|
||||
/** Returns a point which has the same X position as this one, but a new Y. */
|
||||
Point withY (ValueType newY) const noexcept { return Point (x, newY); }
|
||||
JUCE_CONSTEXPR Point withY (ValueType newY) const noexcept { return Point (x, newY); }
|
||||
|
||||
/** Changes the point's x and y coordinates. */
|
||||
void setXY (ValueType newX, ValueType newY) noexcept { x = newX; y = newY; }
|
||||
void setXY (ValueType newX, ValueType newY) noexcept { x = newX; y = newY; }
|
||||
|
||||
/** Adds a pair of coordinates to this value. */
|
||||
void addXY (ValueType xToAdd, ValueType yToAdd) noexcept { x += xToAdd; y += yToAdd; }
|
||||
void addXY (ValueType xToAdd, ValueType yToAdd) noexcept { x += xToAdd; y += yToAdd; }
|
||||
|
||||
//==============================================================================
|
||||
/** Returns a point with a given offset from this one. */
|
||||
Point translated (ValueType deltaX, ValueType deltaY) const noexcept { return Point (x + deltaX, y + deltaY); }
|
||||
JUCE_CONSTEXPR Point translated (ValueType deltaX, ValueType deltaY) const noexcept { return Point (x + deltaX, y + deltaY); }
|
||||
|
||||
/** Adds two points together */
|
||||
Point operator+ (Point other) const noexcept { return Point (x + other.x, y + other.y); }
|
||||
JUCE_CONSTEXPR Point operator+ (Point other) const noexcept { return Point (x + other.x, y + other.y); }
|
||||
|
||||
/** Adds another point's coordinates to this one */
|
||||
Point& operator+= (Point other) noexcept { x += other.x; y += other.y; return *this; }
|
||||
Point& operator+= (Point other) noexcept { x += other.x; y += other.y; return *this; }
|
||||
|
||||
/** Subtracts one points from another */
|
||||
Point operator- (Point other) const noexcept { return Point (x - other.x, y - other.y); }
|
||||
JUCE_CONSTEXPR Point operator- (Point other) const noexcept { return Point (x - other.x, y - other.y); }
|
||||
|
||||
/** Subtracts another point's coordinates to this one */
|
||||
Point& operator-= (Point other) noexcept { x -= other.x; y -= other.y; return *this; }
|
||||
Point& operator-= (Point other) noexcept { x -= other.x; y -= other.y; return *this; }
|
||||
|
||||
/** Multiplies two points together */
|
||||
template <typename OtherType>
|
||||
Point operator* (Point<OtherType> other) const noexcept { return Point ((ValueType) (x * other.x), (ValueType) (y * other.y)); }
|
||||
JUCE_CONSTEXPR Point operator* (Point<OtherType> other) const noexcept { return Point ((ValueType) (x * other.x), (ValueType) (y * other.y)); }
|
||||
|
||||
/** Multiplies another point's coordinates to this one */
|
||||
template <typename OtherType>
|
||||
Point& operator*= (Point<OtherType> other) noexcept { *this = *this * other; return *this; }
|
||||
Point& operator*= (Point<OtherType> other) noexcept { *this = *this * other; return *this; }
|
||||
|
||||
/** Divides one point by another */
|
||||
template <typename OtherType>
|
||||
Point operator/ (Point<OtherType> other) const noexcept { return Point ((ValueType) (x / other.x), (ValueType) (y / other.y)); }
|
||||
JUCE_CONSTEXPR Point operator/ (Point<OtherType> other) const noexcept { return Point ((ValueType) (x / other.x), (ValueType) (y / other.y)); }
|
||||
|
||||
/** Divides this point's coordinates by another */
|
||||
template <typename OtherType>
|
||||
Point& operator/= (Point<OtherType> other) noexcept { *this = *this / other; return *this; }
|
||||
Point& operator/= (Point<OtherType> other) noexcept { *this = *this / other; return *this; }
|
||||
|
||||
/** Returns a point whose coordinates are multiplied by a given scalar value. */
|
||||
template <typename FloatType>
|
||||
Point operator* (FloatType multiplier) const noexcept { return Point ((ValueType) (x * multiplier), (ValueType) (y * multiplier)); }
|
||||
JUCE_CONSTEXPR Point operator* (FloatType multiplier) const noexcept { return Point ((ValueType) (x * multiplier), (ValueType) (y * multiplier)); }
|
||||
|
||||
/** Returns a point whose coordinates are divided by a given scalar value. */
|
||||
template <typename FloatType>
|
||||
Point operator/ (FloatType divisor) const noexcept { return Point ((ValueType) (x / divisor), (ValueType) (y / divisor)); }
|
||||
JUCE_CONSTEXPR Point operator/ (FloatType divisor) const noexcept { return Point ((ValueType) (x / divisor), (ValueType) (y / divisor)); }
|
||||
|
||||
/** Multiplies the point's coordinates by a scalar value. */
|
||||
template <typename FloatType>
|
||||
Point& operator*= (FloatType multiplier) noexcept { x = (ValueType) (x * multiplier); y = (ValueType) (y * multiplier); return *this; }
|
||||
Point& operator*= (FloatType multiplier) noexcept { x = (ValueType) (x * multiplier); y = (ValueType) (y * multiplier); return *this; }
|
||||
|
||||
/** Divides the point's coordinates by a scalar value. */
|
||||
template <typename FloatType>
|
||||
Point& operator/= (FloatType divisor) noexcept { x = (ValueType) (x / divisor); y = (ValueType) (y / divisor); return *this; }
|
||||
Point& operator/= (FloatType divisor) noexcept { x = (ValueType) (x / divisor); y = (ValueType) (y / divisor); return *this; }
|
||||
|
||||
/** Returns the inverse of this point. */
|
||||
Point operator-() const noexcept { return Point (-x, -y); }
|
||||
JUCE_CONSTEXPR Point operator-() const noexcept { return Point (-x, -y); }
|
||||
|
||||
//==============================================================================
|
||||
/** This type will be double if the Point's type is double, otherwise it will be float. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue