aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-01-22 05:50:27 -0800
committerChris Robinson <[email protected]>2021-01-22 05:50:27 -0800
commitcff3693387c6d389f83ca25c7a150ae3395a434b (patch)
tree8a7f8803a1b36dc5ed7c18be92f80f98b8688a83
parentda59ad51057ce7343e3db4632e8679e1e537779d (diff)
Use if constexpr when possible
-rw-r--r--alc/backends/opensl.cpp3
-rw-r--r--alc/backends/wave.cpp3
-rw-r--r--alc/hrtf.cpp4
-rw-r--r--common/albit.h5
-rw-r--r--common/opthelpers.h6
5 files changed, 15 insertions, 6 deletions
diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp
index 926911f0..917e097f 100644
--- a/alc/backends/opensl.cpp
+++ b/alc/backends/opensl.cpp
@@ -37,6 +37,7 @@
#include "alu.h"
#include "compat.h"
#include "core/logging.h"
+#include "opthelpers.h"
#include "ringbuffer.h"
#include "threads.h"
@@ -104,7 +105,7 @@ constexpr SLuint32 GetTypeRepresentation(DevFmtType type) noexcept
constexpr SLuint32 GetByteOrderEndianness() noexcept
{
- if /*constexpr*/(al::endian::native == al::endian::little)
+ if_constexpr(al::endian::native == al::endian::little)
return SL_BYTEORDER_LITTLEENDIAN;
return SL_BYTEORDER_BIGENDIAN;
}
diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp
index afff1d56..4f738230 100644
--- a/alc/backends/wave.cpp
+++ b/alc/backends/wave.cpp
@@ -42,6 +42,7 @@
#include "alu.h"
#include "compat.h"
#include "core/logging.h"
+#include "opthelpers.h"
#include "strutils.h"
#include "threads.h"
#include "vector.h"
@@ -149,7 +150,7 @@ int WaveBackend::mixerProc()
mDevice->renderSamples(mBuffer.data(), mDevice->UpdateSize, frameStep);
done += mDevice->UpdateSize;
- if /*constexpr*/(al::endian::native != al::endian::little)
+ if_constexpr(al::endian::native != al::endian::little)
{
const uint bytesize{mDevice->bytesFromFmt()};
diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp
index 3f4ddf61..60d0aead 100644
--- a/alc/hrtf.cpp
+++ b/alc/hrtf.cpp
@@ -472,7 +472,7 @@ inline T readle(std::istream &data)
static_assert(num_bits <= sizeof(T)*8, "num_bits is too large for the type");
T ret{};
- if /*constexpr*/(al::endian::native == al::endian::little)
+ if_constexpr(al::endian::native == al::endian::little)
{
if(!data.read(reinterpret_cast<char*>(&ret), num_bits/8))
return static_cast<T>(EOF);
@@ -485,7 +485,7 @@ inline T readle(std::istream &data)
std::reverse_copy(std::begin(b), std::end(b), reinterpret_cast<al::byte*>(&ret));
}
- if /*constexpr*/(std::is_signed<T>::value && num_bits < sizeof(T)*8)
+ if_constexpr(std::is_signed<T>::value && num_bits < sizeof(T)*8)
{
constexpr auto signbit = static_cast<T>(1u << (num_bits-1));
return static_cast<T>((ret^signbit) - signbit);
diff --git a/common/albit.h b/common/albit.h
index c54bb31a..2c83ca08 100644
--- a/common/albit.h
+++ b/common/albit.h
@@ -5,6 +5,7 @@
#include <type_traits>
#if !defined(__GNUC__) && (defined(_WIN32) || defined(_WIN64))
#include <intrin.h>
+#include "opthelpers.h"
#endif
namespace al {
@@ -104,7 +105,7 @@ inline std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value
int> countr_zero(T v)
{
unsigned long idx{std::numeric_limits<T>::digits};
- if /*constexpr*/(std::numeric_limits<T>::digits <= 32)
+ if_constexpr(std::numeric_limits<T>::digits <= 32)
_BitScanForward(&idx, static_cast<uint32_t>(v));
else // std::numeric_limits<T>::digits > 32
_BitScanForward64(&idx, v);
@@ -118,7 +119,7 @@ inline std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value
int> countr_zero(T v)
{
unsigned long idx{std::numeric_limits<T>::digits};
- if /*constexpr*/(std::numeric_limits<T>::digits <= 32)
+ if_constexpr(std::numeric_limits<T>::digits <= 32)
_BitScanForward(&idx, static_cast<uint32_t>(v));
else if(!_BitScanForward(&idx, static_cast<uint32_t>(v)))
{
diff --git a/common/opthelpers.h b/common/opthelpers.h
index 8f16fd3f..df0be2f5 100644
--- a/common/opthelpers.h
+++ b/common/opthelpers.h
@@ -36,4 +36,10 @@
#define ASSUME(x) ((void)0)
#endif
+#if __cplusplus >= 201709L || defined(__cpp_if_constexpr)
+#define if_constexpr if constexpr
+#else
+#define if_constexpr if
+#endif
+
#endif /* OPTHELPERS_H */