Proper fix for static asserts (#64)

Replace std::uniform_int_distribution with boost::random::uniform_int_distribution
This commit is contained in:
ArtemisX64 2022-08-26 21:28:50 +09:00 committed by GitHub
parent 19a0a3a359
commit 1cb2d4e5ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 13 deletions

View File

@ -3,12 +3,13 @@
#include "gui/CemuApp.h" #include "gui/CemuApp.h"
#include "util/helpers/SystemException.h" #include "util/helpers/SystemException.h"
#include <random>
#include "config/ActiveSettings.h" #include "config/ActiveSettings.h"
#include "Cafe/IOSU/legacy/iosu_crypto.h" #include "Cafe/IOSU/legacy/iosu_crypto.h"
#include "Common/filestream.h" #include "Common/filestream.h"
#include <random>
#include <boost/random/uniform_int.hpp>
std::vector<Account> Account::s_account_list; std::vector<Account> Account::s_account_list;
Account::Account(uint32 persistent_id) Account::Account(uint32 persistent_id)
@ -65,8 +66,11 @@ Account::Account(uint32 persistent_id, std::wstring_view mii_name)
static std::random_device s_random_device; static std::random_device s_random_device;
static std::mt19937 s_mte(s_random_device()); static std::mt19937 s_mte(s_random_device());
std::uniform_int_distribution<uint16> dist(std::numeric_limits<uint8>::min(), std::numeric_limits<uint8>::max());
std::generate(m_uuid.begin(), m_uuid.end(), [&]() { return (uint8)dist(s_mte); }); // use boost library to escape static asserts in linux builds
boost::random::uniform_int_distribution<uint16> dist(std::numeric_limits<uint8>::min(), std::numeric_limits<uint8>::max());
std::generate(m_uuid.begin(), m_uuid.end(), [&]() { return (uint8)dist(s_mte); });
// 1000004 or 2000004 | lower uint32 from uuid from uuid // 1000004 or 2000004 | lower uint32 from uuid from uuid
m_transferable_id_base = (0x2000004ULL << 32); m_transferable_id_base = (0x2000004ULL << 32);

View File

@ -4,6 +4,8 @@
#include<bitset> #include<bitset>
#include<random> #include<random>
#include <boost/random/uniform_int.hpp>
void swap(unsigned char *a, unsigned char *b) void swap(unsigned char *a, unsigned char *b)
{ {
int tmp = *a; int tmp = *a;
@ -111,7 +113,8 @@ void releasePRUDPPort(uint16 port)
} }
std::mt19937_64 prudpRG(GetTickCount()); std::mt19937_64 prudpRG(GetTickCount());
std::uniform_int_distribution<int> prudpDis8(0, 0xFF); // workaround for static asserts when using uniform_int_distribution
boost::random::uniform_int_distribution<int> prudpDis8(0, 0xFF);
uint8 prudp_generateRandomU8() uint8 prudp_generateRandomU8()
{ {

View File

@ -1,9 +1,3 @@
//Temporary Workaround for static_assert related errors in libstdc++12
//TODO: Make a proper fix
#ifdef __clang__
#define static_assert(...) static_assert(true, "")
#endif
#pragma once #pragma once
#include <stdlib.h> // for size_t #include <stdlib.h> // for size_t

View File

@ -9,6 +9,9 @@
#include "config/ActiveSettings.h" #include "config/ActiveSettings.h"
#include <boost/random/uniform_int.hpp>
#if BOOST_OS_WINDOWS #if BOOST_OS_WINDOWS
#include <TlHelp32.h> #include <TlHelp32.h>
#endif #endif
@ -427,7 +430,9 @@ std::string GenerateRandomString(const size_t length, const std::string_view cha
std::random_device rd; std::random_device rd;
std::mt19937 gen(rd()); std::mt19937 gen(rd());
std::uniform_int_distribution<decltype(characters.size())> index_dist(0, characters.size() - 1);
// workaround for static asserts using boost
boost::random::uniform_int_distribution<decltype(characters.size())> index_dist(0, characters.size() - 1);
std::generate_n( std::generate_n(
result.begin(), result.begin(),
length, length,

View File

@ -29,6 +29,7 @@
"boost-ptr-container", "boost-ptr-container",
"boost-property-tree", "boost-property-tree",
"boost-static-string", "boost-static-string",
"boost-random",
"fmt", "fmt",
"glm", "glm",
"glslang", "glslang",