Use if-constexpr in Range
This commit is contained in:
parent
0196fb57ad
commit
dd5035db35
1 changed files with 14 additions and 8 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "MathHelpers.h"
|
#include "MathHelpers.h"
|
||||||
|
#include "Macros.h"
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
@ -30,7 +31,6 @@ public:
|
||||||
: _start(start)
|
: _start(start)
|
||||||
, _end(Checked ? max(start, end) : end)
|
, _end(Checked ? max(start, end) : end)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Range(const Range<Type, !Checked>& other)
|
constexpr Range(const Range<Type, !Checked>& other)
|
||||||
|
|
@ -50,15 +50,19 @@ public:
|
||||||
void setStart(Type start) noexcept
|
void setStart(Type start) noexcept
|
||||||
{
|
{
|
||||||
_start = start;
|
_start = start;
|
||||||
if (Checked && start > _end)
|
IF_CONSTEXPR (Checked) {
|
||||||
_end = start;
|
if (start > _end)
|
||||||
|
_end = start;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEnd(Type end) noexcept
|
void setEnd(Type end) noexcept
|
||||||
{
|
{
|
||||||
_end = end;
|
_end = end;
|
||||||
if (Checked && end < _start)
|
IF_CONSTEXPR (Checked) {
|
||||||
_start = end;
|
if (end < _start)
|
||||||
|
_start = end;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,7 +70,7 @@ public:
|
||||||
*/
|
*/
|
||||||
bool isValid() const noexcept
|
bool isValid() const noexcept
|
||||||
{
|
{
|
||||||
if (Checked)
|
IF_CONSTEXPR (Checked)
|
||||||
return true; // always valid
|
return true; // always valid
|
||||||
else
|
else
|
||||||
return _start <= _end;
|
return _start <= _end;
|
||||||
|
|
@ -103,8 +107,10 @@ public:
|
||||||
*/
|
*/
|
||||||
void shrinkIfSmaller(Type start, Type end)
|
void shrinkIfSmaller(Type start, Type end)
|
||||||
{
|
{
|
||||||
if (Checked && start > end)
|
IF_CONSTEXPR (Checked) {
|
||||||
std::swap(start, end);
|
if (start > end)
|
||||||
|
std::swap(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
if (start > _start)
|
if (start > _start)
|
||||||
_start = start;
|
_start = start;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue