This commit is contained in:
Branimir Karadžić
2018-11-14 20:01:03 -08:00
parent e35f29b647
commit d1c6ff2b1f
10 changed files with 45 additions and 53 deletions

View File

@@ -17,7 +17,7 @@
#include "macros.h"
///
#define BX_COUNTOF(_x) sizeof(bx::COUNTOF_REQUIRES_ARRAY_ARGUMENT(_x) )
#define BX_COUNTOF(_x) sizeof(bx::CountOfRequireArrayArgumentT(_x) )
///
#define BX_IGNORE_C4127(_x) bx::ignoreC4127(!!(_x) )
@@ -38,12 +38,12 @@ namespace bx
template<class Ty>
constexpr bool isTriviallyCopyable();
/// Exchange two values.
/// Swap two values.
template<typename Ty>
void xchg(Ty& _a, Ty& _b);
void swap(Ty& _a, Ty& _b);
/// Exchange memory.
void xchg(void* _a, void* _b, size_t _numBytes);
/// Swap memory.
void swap(void* _a, void* _b, size_t _numBytes);
/// Returns minimum of two values.
template<typename Ty>
@@ -73,10 +73,6 @@ namespace bx
template<typename Ty>
constexpr bool isPowerOf2(Ty _a);
// http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/
template<typename T, size_t N>
char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N];
///
void memCopy(void* _dst, const void* _src, size_t _numBytes);

View File

@@ -9,6 +9,11 @@
namespace bx
{
// Reference:
// https://web.archive.org/web/20181115035420/http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/
template<typename Ty, size_t Num>
char(&CountOfRequireArrayArgumentT(const Ty(&)[Num]))[Num];
template<bool>
inline constexpr bool isEnabled()
{
@@ -33,7 +38,7 @@ namespace bx
}
template<typename Ty>
inline void xchg(Ty& _a, Ty& _b)
inline void swap(Ty& _a, Ty& _b)
{
Ty tmp = _a; _a = _b; _b = tmp;
}

View File

@@ -141,7 +141,7 @@ namespace bx
for (uint32_t ii = 0, num = _num-1; ii < num; ++ii)
{
uint32_t jj = ii + 1 + _rng->gen() % (num - ii);
bx::xchg(_array[ii], _array[jj]);
bx::swap(_array[ii], _array[jj]);
}
}

View File

@@ -7,6 +7,7 @@
#define BX_OS_H_HEADER_GUARD
#include "debug.h"
#include "filepath.h"
#if BX_PLATFORM_OSX
# define BX_DL_EXT "dylib"
@@ -31,7 +32,7 @@ namespace bx
size_t getProcessMemoryUsed();
///
void* dlopen(const char* _filePath);
void* dlopen(const FilePath& _filePath);
///
void dlclose(void* _handle);
@@ -40,13 +41,10 @@ namespace bx
void* dlsym(void* _handle, const char* _symbol);
///
bool getenv(const char* _name, char* _out, uint32_t* _inOutSize);
bool getEnv(const char* _name, char* _out, uint32_t* _inOutSize);
///
void setenv(const char* _name, const char* _value);
///
void unsetenv(const char* _name);
void setEnv(const char* _name, const char* _value);
///
int chdir(const char* _path);