Skip to content

Commit

Permalink
Removed BX_STATIC_ASSERT. Not needed in C++17.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed Dec 8, 2024
1 parent 57a4fb1 commit 3e9604c
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 51 deletions.
4 changes: 2 additions & 2 deletions include/bx/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
BX_ERROR_USE_TEMP_WHEN_NULL(_ptr); \
bx::ErrorScope bxErrorScope(const_cast<bx::Error*>(&tmpError), "" __VA_ARGS__)

#define BX_ERROR_RESULT(_err, _code) \
BX_STATIC_ASSERT(_code != 0, "ErrorCode 0 is reserved!"); \
#define BX_ERROR_RESULT(_err, _code) \
static_assert(_code != 0, "ErrorCode 0 is reserved!"); \
static constexpr bx::ErrorResult _err = { _code }

namespace bx
Expand Down
2 changes: 1 addition & 1 deletion include/bx/inline/hash.inl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace bx
template<typename HashT, typename Ty>
inline uint32_t hash(const Ty& _data)
{
BX_STATIC_ASSERT(isTriviallyCopyable<Ty>() );
static_assert(isTriviallyCopyable<Ty>() );
return hash<HashT>(&_data, sizeof(Ty) );
}

Expand Down
8 changes: 4 additions & 4 deletions include/bx/inline/math.inl
Original file line number Diff line number Diff line change
Expand Up @@ -668,28 +668,28 @@ namespace bx
template<typename Ty>
inline BX_CONSTEXPR_FUNC uint8_t findFirstSet(Ty _val)
{
BX_STATIC_ASSERT(isInteger<Ty>(), "Type Ty must be of integer type!");
static_assert(isInteger<Ty>(), "Type Ty must be of integer type!");
return Ty(0) == _val ? uint8_t(0) : countTrailingZeros<Ty>(_val) + 1;
}

template<typename Ty>
inline BX_CONSTEXPR_FUNC uint8_t findLastSet(Ty _val)
{
BX_STATIC_ASSERT(isInteger<Ty>(), "Type Ty must be of integer type!");
static_assert(isInteger<Ty>(), "Type Ty must be of integer type!");
return Ty(0) == _val ? uint8_t(0) : sizeof(Ty)*8 - countLeadingZeros<Ty>(_val);
}

template<typename Ty>
inline BX_CONSTEXPR_FUNC uint8_t ceilLog2(Ty _a)
{
BX_STATIC_ASSERT(isInteger<Ty>(), "Type Ty must be of integer type!");
static_assert(isInteger<Ty>(), "Type Ty must be of integer type!");
return Ty(_a) < Ty(1) ? Ty(0) : sizeof(Ty)*8 - countLeadingZeros<Ty>(_a - 1);
}

template<typename Ty>
inline BX_CONSTEXPR_FUNC uint8_t floorLog2(Ty _a)
{
BX_STATIC_ASSERT(isInteger<Ty>(), "Type Ty must be of integer type!");
static_assert(isInteger<Ty>(), "Type Ty must be of integer type!");
return Ty(_a) < Ty(1) ? Ty(0) : sizeof(Ty)*8 - 1 - countLeadingZeros<Ty>(_a);
}

Expand Down
12 changes: 6 additions & 6 deletions include/bx/inline/readerwriter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ namespace bx
inline int32_t read(ReaderI* _reader, Ty& _value, Error* _err)
{
BX_ERROR_SCOPE(_err);
BX_STATIC_ASSERT(isTriviallyCopyable<Ty>() );
static_assert(isTriviallyCopyable<Ty>() );
return _reader->read(&_value, sizeof(Ty), _err);
}

template<typename Ty>
inline int32_t readHE(ReaderI* _reader, Ty& _value, bool _fromLittleEndian, Error* _err)
{
BX_ERROR_SCOPE(_err);
BX_STATIC_ASSERT(isTriviallyCopyable<Ty>() );
static_assert(isTriviallyCopyable<Ty>() );
Ty value;
int32_t result = _reader->read(&value, sizeof(Ty), _err);
_value = toHostEndian(value, _fromLittleEndian);
Expand Down Expand Up @@ -322,7 +322,7 @@ namespace bx
inline int32_t write(WriterI* _writer, const Ty& _value, Error* _err)
{
BX_ERROR_SCOPE(_err);
BX_STATIC_ASSERT(isTriviallyCopyable<Ty>() );
static_assert(isTriviallyCopyable<Ty>() );
return _writer->write(&_value, sizeof(Ty), _err);
}

Expand All @@ -347,7 +347,7 @@ namespace bx
inline int32_t writeLE(WriterI* _writer, const Ty& _value, Error* _err)
{
BX_ERROR_SCOPE(_err);
BX_STATIC_ASSERT(isTriviallyCopyable<Ty>() );
static_assert(isTriviallyCopyable<Ty>() );
Ty value = toLittleEndian(_value);
int32_t result = _writer->write(&value, sizeof(Ty), _err);
return result;
Expand All @@ -363,7 +363,7 @@ namespace bx
inline int32_t writeBE(WriterI* _writer, const Ty& _value, Error* _err)
{
BX_ERROR_SCOPE(_err);
BX_STATIC_ASSERT(isTriviallyCopyable<Ty>() );
static_assert(isTriviallyCopyable<Ty>() );
Ty value = toBigEndian(_value);
int32_t result = _writer->write(&value, sizeof(Ty), _err);
return result;
Expand Down Expand Up @@ -414,7 +414,7 @@ namespace bx
inline int32_t peek(ReaderSeekerI* _reader, Ty& _value, Error* _err)
{
BX_ERROR_SCOPE(_err);
BX_STATIC_ASSERT(isTriviallyCopyable<Ty>() );
static_assert(isTriviallyCopyable<Ty>() );
return peek(_reader, &_value, sizeof(Ty), _err);
}

Expand Down
12 changes: 6 additions & 6 deletions include/bx/inline/sort.inl
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ namespace bx
template<typename Ty>
inline void quickSort(void* _data, uint32_t _num, uint32_t _stride, const ComparisonFn _fn)
{
BX_STATIC_ASSERT(isTriviallyMoveAssignable<Ty>(), "Element type must be trivially move assignable");
static_assert(isTriviallyMoveAssignable<Ty>(), "Element type must be trivially move assignable");
quickSort(_data, _num, _stride, _fn);
}

template<typename Ty>
inline void quickSort(Ty* _data, uint32_t _num, const ComparisonFn _fn)
{
BX_STATIC_ASSERT(isTriviallyMoveAssignable<Ty>(), "Element type must be trivially move assignable");
static_assert(isTriviallyMoveAssignable<Ty>(), "Element type must be trivially move assignable");
quickSort( (void*)_data, _num, sizeof(Ty), _fn);
}

template<typename Ty>
inline uint32_t unique(void* _data, uint32_t _num, uint32_t _stride, const ComparisonFn _fn)
{
BX_STATIC_ASSERT(isTriviallyMoveAssignable<Ty>(), "Element type must be trivially move assignable");
static_assert(isTriviallyMoveAssignable<Ty>(), "Element type must be trivially move assignable");
return unique(_data, _num, _stride, _fn);
}

template<typename Ty>
inline uint32_t unique(Ty* _data, uint32_t _num, const ComparisonFn _fn)
{
BX_STATIC_ASSERT(isTriviallyMoveAssignable<Ty>(), "Element type must be trivially move assignable");
static_assert(isTriviallyMoveAssignable<Ty>(), "Element type must be trivially move assignable");
return unique( (void*)_data, _num, sizeof(Ty), _fn);
}

Expand Down Expand Up @@ -189,7 +189,7 @@ done:
template <typename Ty>
inline void radixSort(uint32_t* _keys, uint32_t* _tempKeys, Ty* _values, Ty* _tempValues, uint32_t _size)
{
BX_STATIC_ASSERT(isTriviallyMoveAssignable<Ty>(), "Sort element type must be trivially move assignable");
static_assert(isTriviallyMoveAssignable<Ty>(), "Sort element type must be trivially move assignable");

uint32_t* keys = _keys;
uint32_t* tempKeys = _tempKeys;
Expand Down Expand Up @@ -325,7 +325,7 @@ done:
template <typename Ty>
inline void radixSort(uint64_t* _keys, uint64_t* _tempKeys, Ty* _values, Ty* _tempValues, uint32_t _size)
{
BX_STATIC_ASSERT(isTriviallyMoveAssignable<Ty>(), "Sort element type must be trivially move assignable");
static_assert(isTriviallyMoveAssignable<Ty>(), "Sort element type must be trivially move assignable");

uint64_t* keys = _keys;
uint64_t* tempKeys = _tempKeys;
Expand Down
2 changes: 1 addition & 1 deletion include/bx/inline/typetraits.inl
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ namespace bx
template<typename Ty>
inline constexpr Ty&& forward(RemoveReferenceType<Ty>&& _a)
{
BX_STATIC_ASSERT(!isLvalueReference<Ty>(), "Can not forward an Rvalue as an Lvalue.");
static_assert(!isLvalueReference<Ty>(), "Can not forward an Rvalue as an Lvalue.");
return static_cast<Ty&&>(_a);
}

Expand Down
3 changes: 0 additions & 3 deletions include/bx/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@
///
#define BX_CONSTEXPR_FUNC constexpr BX_CONST_FUNC

///
#define BX_STATIC_ASSERT(_condition, ...) static_assert(_condition, "" __VA_ARGS__)

///
#define BX_ALIGN_DECL_16(_decl) BX_ALIGN_DECL(16, _decl)
#define BX_ALIGN_DECL_256(_decl) BX_ALIGN_DECL(256, _decl)
Expand Down
2 changes: 1 addition & 1 deletion src/bounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ namespace bx

bool intersect(const Ray& _ray, const Capsule& _capsule, Hit* _hit)
{
BX_STATIC_ASSERT(sizeof(Capsule) == sizeof(Cylinder) );
static_assert(sizeof(Capsule) == sizeof(Cylinder) );
return intersect(_ray, *( (const Cylinder*)&_capsule), true, _hit);
}

Expand Down
2 changes: 1 addition & 1 deletion src/easing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace bx
easeInOutBounce,
easeOutInBounce,
};
BX_STATIC_ASSERT(BX_COUNTOF(s_easeFunc) == Easing::Count);
static_assert(BX_COUNTOF(s_easeFunc) == Easing::Count);

EaseFn getEaseFunc(Easing::Enum _enum)
{
Expand Down
6 changes: 3 additions & 3 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ namespace bx

FileReader::FileReader()
{
BX_STATIC_ASSERT(sizeof(FileReaderImpl) <= sizeof(m_internal) );
static_assert(sizeof(FileReaderImpl) <= sizeof(m_internal) );
BX_PLACEMENT_NEW(m_internal, FileReaderImpl)(NULL);
}

Expand Down Expand Up @@ -530,7 +530,7 @@ namespace bx

FileWriter::FileWriter()
{
BX_STATIC_ASSERT(sizeof(FileWriterImpl) <= sizeof(m_internal) );
static_assert(sizeof(FileWriterImpl) <= sizeof(m_internal) );
BX_PLACEMENT_NEW(m_internal, FileWriterImpl)(NULL);
}

Expand Down Expand Up @@ -711,7 +711,7 @@ namespace bx

DirectoryReader::DirectoryReader()
{
BX_STATIC_ASSERT(sizeof(DirectoryReaderImpl) <= sizeof(m_internal) );
static_assert(sizeof(DirectoryReaderImpl) <= sizeof(m_internal) );
BX_PLACEMENT_NEW(m_internal, DirectoryReaderImpl);
}

Expand Down
12 changes: 6 additions & 6 deletions src/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const uint32_t s_crcTableIeee[] =
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
BX_STATIC_ASSERT(BX_COUNTOF(s_crcTableIeee) == 256);
static_assert(BX_COUNTOF(s_crcTableIeee) == 256);

static const uint32_t s_crcTableCastagnoli[] =
{
Expand Down Expand Up @@ -80,7 +80,7 @@ static const uint32_t s_crcTableCastagnoli[] =
0xf36e6f75, 0x0105ec76, 0x12551f82, 0xe03e9c81, 0x34f4f86a, 0xc69f7b69, 0xd5cf889d, 0x27a40b9e,
0x79b737ba, 0x8bdcb4b9, 0x988c474d, 0x6ae7c44e, 0xbe2da0a5, 0x4c4623a6, 0x5f16d052, 0xad7d5351,
};
BX_STATIC_ASSERT(BX_COUNTOF(s_crcTableCastagnoli) == 256);
static_assert(BX_COUNTOF(s_crcTableCastagnoli) == 256);

static const uint32_t s_crcTableKoopman[] =
{
Expand Down Expand Up @@ -117,15 +117,15 @@ static const uint32_t s_crcTableKoopman[] =
0xcc9b9520, 0x5a0e51ea, 0x37d3ace9, 0xa1466823, 0xec6856ef, 0x7afd9225, 0x17206f26, 0x81b5abec,
0x8d7c12be, 0x1be9d674, 0x76342b77, 0xe0a1efbd, 0xad8fd171, 0x3b1a15bb, 0x56c7e8b8, 0xc0522c72,
};
BX_STATIC_ASSERT(BX_COUNTOF(s_crcTableKoopman) == 256);
static_assert(BX_COUNTOF(s_crcTableKoopman) == 256);

static const uint32_t* s_crcTable[] =
{
s_crcTableIeee,
s_crcTableCastagnoli,
s_crcTableKoopman,
};
BX_STATIC_ASSERT(BX_COUNTOF(s_crcTable) == HashCrc32::Count);
static_assert(BX_COUNTOF(s_crcTable) == HashCrc32::Count);

void HashCrc32::begin(Enum _type)
{
Expand Down Expand Up @@ -270,7 +270,7 @@ struct HashMurmur2APod
m_hash ^= m_hash >> 15;
}
};
BX_STATIC_ASSERT(sizeof(HashMurmur2A) == sizeof(HashMurmur2APod) );
static_assert(sizeof(HashMurmur2A) == sizeof(HashMurmur2APod) );

void HashMurmur2A::add(const void* _data, int32_t _len)
{
Expand Down Expand Up @@ -334,7 +334,7 @@ struct HashMurmur3Pod
m_hash ^= m_hash >> 16;
}
};
BX_STATIC_ASSERT(sizeof(HashMurmur3) == sizeof(HashMurmur3Pod) );
static_assert(sizeof(HashMurmur3) == sizeof(HashMurmur3Pod) );

void HashMurmur3::add(const void* _data, int32_t _len)
{
Expand Down
4 changes: 2 additions & 2 deletions src/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace bx

Mutex::Mutex()
{
BX_STATIC_ASSERT(sizeof(int32_t) <= sizeof(m_internal) );
static_assert(sizeof(int32_t) <= sizeof(m_internal) );

uint32_t* futex = (uint32_t*)m_internal;
*futex = State::Unlocked;
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace bx

Mutex::Mutex()
{
BX_STATIC_ASSERT(sizeof(pthread_mutex_t) <= sizeof(m_internal) );
static_assert(sizeof(pthread_mutex_t) <= sizeof(m_internal) );

pthread_mutexattr_t attr;

Expand Down
6 changes: 3 additions & 3 deletions src/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace bx
#if BX_CRT_NONE
Semaphore::Semaphore()
{
BX_STATIC_ASSERT(sizeof(SemaphoreInternal) <= sizeof(m_internal) );
static_assert(sizeof(SemaphoreInternal) <= sizeof(m_internal) );
}

Semaphore::~Semaphore()
Expand All @@ -77,7 +77,7 @@ namespace bx

Semaphore::Semaphore()
{
BX_STATIC_ASSERT(sizeof(SemaphoreInternal) <= sizeof(m_internal) );
static_assert(sizeof(SemaphoreInternal) <= sizeof(m_internal) );

SemaphoreInternal* si = (SemaphoreInternal*)m_internal;
si->m_handle = dispatch_semaphore_create(0);
Expand Down Expand Up @@ -137,7 +137,7 @@ namespace bx

Semaphore::Semaphore()
{
BX_STATIC_ASSERT(sizeof(SemaphoreInternal) <= sizeof(m_internal) );
static_assert(sizeof(SemaphoreInternal) <= sizeof(m_internal) );

SemaphoreInternal* si = (SemaphoreInternal*)m_internal;
si->m_count = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace bx
, m_exitCode(kExitSuccess)
, m_running(false)
{
BX_STATIC_ASSERT(sizeof(ThreadInternal) <= sizeof(m_internal) );
static_assert(sizeof(ThreadInternal) <= sizeof(m_internal) );

ThreadInternal* ti = (ThreadInternal*)m_internal;
#if BX_CRT_NONE
Expand Down Expand Up @@ -330,7 +330,7 @@ namespace bx
#if BX_CRT_NONE
TlsData::TlsData()
{
BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) );
static_assert(sizeof(TlsDataInternal) <= sizeof(m_internal) );

TlsDataInternal* ti = (TlsDataInternal*)m_internal;
BX_UNUSED(ti);
Expand All @@ -357,7 +357,7 @@ namespace bx
#elif BX_PLATFORM_WINDOWS
TlsData::TlsData()
{
BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) );
static_assert(sizeof(TlsDataInternal) <= sizeof(m_internal) );

TlsDataInternal* ti = (TlsDataInternal*)m_internal;
ti->m_id = TlsAlloc();
Expand Down Expand Up @@ -387,7 +387,7 @@ namespace bx

TlsData::TlsData()
{
BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) );
static_assert(sizeof(TlsDataInternal) <= sizeof(m_internal) );

TlsDataInternal* ti = (TlsDataInternal*)m_internal;
int result = pthread_key_create(&ti->m_id, NULL);
Expand Down
14 changes: 7 additions & 7 deletions tests/macros_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <bx/bx.h>
#include <bx/string.h>

BX_STATIC_ASSERT(false
static_assert(false
|| BX_CRT_BIONIC
|| BX_CRT_GLIBC
|| BX_CRT_LIBCXX
Expand All @@ -17,12 +17,12 @@ BX_STATIC_ASSERT(false
|| BX_CRT_NONE
);

BX_STATIC_ASSERT(1 == BX_VA_ARGS_COUNT(1) );
BX_STATIC_ASSERT(2 == BX_VA_ARGS_COUNT(1, 2) );
BX_STATIC_ASSERT(3 == BX_VA_ARGS_COUNT(1, 2, 3) );
BX_STATIC_ASSERT(4 == BX_VA_ARGS_COUNT(1, 2, 3, 4) );
BX_STATIC_ASSERT(5 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
BX_STATIC_ASSERT(6 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );
static_assert(1 == BX_VA_ARGS_COUNT(1) );
static_assert(2 == BX_VA_ARGS_COUNT(1, 2) );
static_assert(3 == BX_VA_ARGS_COUNT(1, 2, 3) );
static_assert(4 == BX_VA_ARGS_COUNT(1, 2, 3, 4) );
static_assert(5 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) );
static_assert(6 == BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) );

BX_NO_INLINE void unusedFunction()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/string_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ TEST_CASE("strCmpV sort", "[string][sort]")
"test_100.txt",
};

BX_STATIC_ASSERT(BX_COUNTOF(test) == BX_COUNTOF(expected) );
static_assert(BX_COUNTOF(test) == BX_COUNTOF(expected) );

bx::quickSort(test, BX_COUNTOF(test), sizeof(const char*), strCmpV);

Expand Down

0 comments on commit 3e9604c

Please sign in to comment.