Upgrade to C++17
This commit is contained in:
parent
df661be1a3
commit
13a74602bd
@ -46,7 +46,7 @@ flags = [
|
||||
# a "-std=<something>".
|
||||
# For a C project, you would set this to something like 'c99' instead of
|
||||
# 'c++11'.
|
||||
'-std=c++14',
|
||||
'-std=c++17',
|
||||
'-stdlib=libc++',
|
||||
# ...and the same thing goes for the magic -x option which specifies the
|
||||
# language that the files to be compiled are written in. This is mostly
|
||||
|
@ -1,4 +1,4 @@
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 3.4)
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 3.16)
|
||||
|
||||
# Find CCache
|
||||
FIND_PROGRAM(CCACHE_PATH ccache)
|
||||
@ -227,7 +227,7 @@ ENDIF ()
|
||||
|
||||
IF (STAR_COMPILER_GNU)
|
||||
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wuninitialized -Wunreachable-code -Wformat -no-pie")
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wuninitialized -Wunreachable-code -Wformat -no-pie")
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wextra -Wuninitialized -Wunreachable-code -Wformat -no-pie")
|
||||
|
||||
IF (STAR_SYSTEM_FAMILY_WINDOWS)
|
||||
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthreads")
|
||||
@ -261,11 +261,11 @@ IF (STAR_COMPILER_GNU)
|
||||
|
||||
ELSEIF (STAR_COMPILER_CLANG)
|
||||
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wuninitialized -Wno-parentheses-equality -Wno-deprecated-declarations")
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wuninitialized -Wno-parentheses-equality -Wno-deprecated-declarations")
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wextra -Wuninitialized -Wno-parentheses-equality -Wno-deprecated-declarations")
|
||||
|
||||
IF (STAR_SYSTEM_MACOS)
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
SET (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++14")
|
||||
SET (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++17")
|
||||
SET (CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
|
||||
ELSEIF ()
|
||||
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -D_REENTRANT")
|
||||
@ -313,7 +313,7 @@ ELSEIF (STAR_COMPILER_MSVC)
|
||||
# using unions in interesting ways.
|
||||
|
||||
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP /EHsc /bigobj /wd4996 /wd4351 /wd4800 /wd4244 /wd4305 /wd4267 /wd4456 /wd4503 /wd4250 /wd4624")
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /EHsc /bigobj /wd4996 /wd4351 /wd4800 /wd4244 /wd4305 /wd4267 /wd4456 /wd4503 /wd4250 /wd4624")
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17 /MP /EHsc /bigobj /wd4996 /wd4351 /wd4800 /wd4244 /wd4305 /wd4267 /wd4456 /wd4503 /wd4250 /wd4624")
|
||||
|
||||
IF (STAR_ENABLE_STATIC_MSVC_RUNTIME)
|
||||
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MT")
|
||||
@ -351,7 +351,7 @@ ELSEIF (STAR_COMPILER_MSVC)
|
||||
|
||||
ELSE ()
|
||||
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pthread -D_REENTRANT")
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -pthread -D_REENTRANT")
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -pthread -D_REENTRANT")
|
||||
|
||||
SET (CMAKE_C_FLAGS_DEBUG "-g")
|
||||
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
|
@ -63,3 +63,4 @@ IF (STAR_ENABLE_DISCORD_INTEGRATION)
|
||||
ENDIF ()
|
||||
|
||||
ADD_LIBRARY (star_application OBJECT ${star_application_SOURCES} ${star_application_HEADERS})
|
||||
TARGET_PRECOMPILE_HEADERS (star_application REUSE_FROM star_core)
|
@ -35,3 +35,4 @@ SET (star_base_SOURCES
|
||||
|
||||
CONFIGURE_FILE (StarVersion.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/StarVersion.cpp)
|
||||
ADD_LIBRARY (star_base OBJECT ${star_base_SOURCES} ${star_base_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/StarVersion.cpp)
|
||||
TARGET_PRECOMPILE_HEADERS (star_base REUSE_FROM star_core)
|
||||
|
@ -28,4 +28,5 @@ ADD_EXECUTABLE (starbound WIN32
|
||||
$<TARGET_OBJECTS:star_extern> $<TARGET_OBJECTS:star_core> $<TARGET_OBJECTS:star_base> $<TARGET_OBJECTS:star_game>
|
||||
$<TARGET_OBJECTS:star_application> $<TARGET_OBJECTS:star_rendering> $<TARGET_OBJECTS:star_windowing> $<TARGET_OBJECTS:star_frontend>
|
||||
${star_client_HEADERS} ${star_client_SOURCES} ${star_client_RESOURCES})
|
||||
TARGET_PRECOMPILE_HEADERS (starbound REUSE_FROM star_core)
|
||||
TARGET_LINK_LIBRARIES (starbound ${STAR_EXT_LIBS} ${STAR_EXT_GUI_LIBS})
|
@ -84,6 +84,7 @@ SET (star_core_HEADERS
|
||||
StarOrderedMap.hpp
|
||||
StarOrderedSet.hpp
|
||||
StarParametricFunction.hpp
|
||||
StarPch.hpp
|
||||
StarPeriodic.hpp
|
||||
StarPeriodicFunction.hpp
|
||||
StarPerlin.hpp
|
||||
@ -203,3 +204,4 @@ ELSEIF (STAR_SYSTEM_FAMILY_WINDOWS)
|
||||
ENDIF ()
|
||||
|
||||
ADD_LIBRARY (star_core OBJECT ${star_core_SOURCES} ${star_core_HEADERS})
|
||||
TARGET_PRECOMPILE_HEADERS (star_core PUBLIC StarPch.hpp)
|
@ -1,10 +1,6 @@
|
||||
#ifndef STAR_ALGORITHM_HPP
|
||||
#define STAR_ALGORITHM_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
|
||||
#include "StarException.hpp"
|
||||
|
||||
namespace Star {
|
||||
@ -267,11 +263,6 @@ void stableSortByComputedValue(Container& container, Getter&& valueGetter) {
|
||||
return sortByComputedValue(container, forward<Getter>(valueGetter), true);
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
void shuffle(Container& c) {
|
||||
std::random_shuffle(c.begin(), c.end());
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
void reverse(Container& c) {
|
||||
std::reverse(c.begin(), c.end());
|
||||
|
@ -1,23 +1,8 @@
|
||||
#include "StarPch.hpp"
|
||||
|
||||
#ifndef STAR_CONFIG_HPP
|
||||
#define STAR_CONFIG_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <initializer_list>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
|
||||
namespace Star {
|
||||
|
||||
// Some really common std namespace includes
|
||||
|
25
source/core/StarPch.hpp
Normal file
25
source/core/StarPch.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef STAR_PCH_HPP
|
||||
#define STAR_PCH_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <initializer_list>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#endif
|
@ -187,7 +187,8 @@ typename Container::value_type RandomSource::randValueFrom(
|
||||
|
||||
template <typename Container>
|
||||
void RandomSource::shuffle(Container& container) {
|
||||
std::random_shuffle(container.begin(), container.end(), [this](size_t max) { return randUInt(max - 1); });
|
||||
size_t max = container.size();
|
||||
std::shuffle(container.begin(), container.end(), URBG<size_t>([this, max]() { return randUInt(max - 1); }));
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
@ -208,7 +209,8 @@ typename Container::value_type Random::randValueFrom(
|
||||
|
||||
template <typename Container>
|
||||
void Random::shuffle(Container& container) {
|
||||
std::random_shuffle(container.begin(), container.end(), [](size_t max) { return Random::randUInt(max - 1); });
|
||||
size_t max = container.size();
|
||||
std::shuffle(container.begin(), container.end(), URBG<size_t>([max]() { return Random::randUInt(max - 1); }));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -118,12 +118,28 @@ typename Container::value_type staticRandomValueFrom(Container const& container,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class URBG {
|
||||
public:
|
||||
typedef function <T()> Function;
|
||||
|
||||
URBG(Function func) : m_func(func) {};
|
||||
|
||||
typedef T result_type;
|
||||
static constexpr T min() { return std::numeric_limits<T>::min(); };
|
||||
static constexpr T max() { return std::numeric_limits<T>::max(); };
|
||||
T operator()() { return m_func(); };
|
||||
private:
|
||||
Function m_func;
|
||||
};
|
||||
|
||||
template <typename Container, typename T, typename... TL>
|
||||
void staticRandomShuffle(Container& container, T const& d, TL const&... rest) {
|
||||
int mix = 0;
|
||||
std::random_shuffle(container.begin(),
|
||||
container.end(),
|
||||
[&](size_t max) { return staticRandomU32Range(0, max - 1, ++mix, d, rest...); });
|
||||
size_t max = container.size();
|
||||
std::shuffle(container.begin(), container.end(), URBG<size_t>([&]() {
|
||||
return staticRandomU32Range(0, max - 1, ++mix, d, rest...);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -103,3 +103,4 @@ SET (star_frontend_SOURCES
|
||||
)
|
||||
|
||||
ADD_LIBRARY (star_frontend OBJECT ${star_frontend_SOURCES} ${star_frontend_HEADERS})
|
||||
TARGET_PRECOMPILE_HEADERS (star_frontend REUSE_FROM star_core)
|
@ -584,8 +584,8 @@ void Projectile::processAction(Json const& action) {
|
||||
|
||||
bool allowEntityOverlap = parameters.getBool("allowEntityOverlap", true);
|
||||
|
||||
random_shuffle(tileDrops.begin(), tileDrops.end(), [](int i) { return Random::randu64() % i; });
|
||||
for (auto tile : zip(openSpaces, tileDrops)) {
|
||||
Random::shuffle(tileDrops);
|
||||
for (auto& tile : zip(openSpaces, tileDrops)) {
|
||||
if (!world()->modifyTile(std::get<0>(tile), PlaceMaterial{TileLayer::Foreground, std::get<1>(tile), MaterialHue()}, allowEntityOverlap)) {
|
||||
auto itemDrop = ItemDrop::createRandomizedDrop(materialDatabase->materialItemDrop(std::get<1>(tile)), (Vec2F)std::get<0>(tile));
|
||||
world()->addEntity(itemDrop);
|
||||
|
@ -33,3 +33,4 @@ SET (star_rendering_SOURCES
|
||||
)
|
||||
|
||||
ADD_LIBRARY (star_rendering OBJECT ${star_rendering_SOURCES} ${star_rendering_HEADERS})
|
||||
TARGET_PRECOMPILE_HEADERS (star_rendering REUSE_FROM star_core)
|
@ -22,4 +22,5 @@ SET (star_server_SOURCES
|
||||
ADD_EXECUTABLE (starbound_server
|
||||
$<TARGET_OBJECTS:star_extern> $<TARGET_OBJECTS:star_core> $<TARGET_OBJECTS:star_base> $<TARGET_OBJECTS:star_game>
|
||||
${star_server_HEADERS} ${star_server_SOURCES})
|
||||
TARGET_PRECOMPILE_HEADERS (starbound_server REUSE_FROM star_core)
|
||||
TARGET_LINK_LIBRARIES (starbound_server ${STAR_EXT_LIBS})
|
@ -101,25 +101,25 @@ namespace {
|
||||
db.open();
|
||||
|
||||
// record writes/reads repeated writeRepeat times randomly each cycle
|
||||
std::random_shuffle(keys.begin(), keys.end());
|
||||
Random::shuffle(keys);
|
||||
putAll(db, keys);
|
||||
|
||||
EXPECT_EQ(db.recordCount(), testCount);
|
||||
|
||||
std::random_shuffle(keys.begin(), keys.end());
|
||||
Random::shuffle(keys);
|
||||
checkAll(db, keys);
|
||||
|
||||
// Random reads/writes with randCount cycles...
|
||||
for (uint32_t i = 0; i < randCount; ++i) {
|
||||
List<uint32_t> keysTemp(keys.begin(), keys.begin() + keys.size() / 2);
|
||||
|
||||
std::random_shuffle(keysTemp.begin(), keysTemp.end());
|
||||
Random::shuffle(keysTemp);
|
||||
removeAll(db, keysTemp);
|
||||
|
||||
std::random_shuffle(keysTemp.begin(), keysTemp.end());
|
||||
Random::shuffle(keysTemp);
|
||||
putAll(db, keysTemp);
|
||||
|
||||
std::random_shuffle(keys.begin(), keys.end());
|
||||
Random::shuffle(keys);
|
||||
checkAll(db, keys);
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ namespace {
|
||||
// Random reads/writes/rollbacks with rollbackCount cycles...
|
||||
for (uint32_t i = 0; i < rollbackCount ; ++i) {
|
||||
List<uint32_t> keysTemp(keys.begin(), keys.begin() + keys.size() / 2);
|
||||
std::random_shuffle(keysTemp.begin(), keysTemp.end());
|
||||
Random::shuffle(keysTemp);
|
||||
|
||||
removeAll(db, keysTemp);
|
||||
db.rollback();
|
||||
@ -193,7 +193,7 @@ TEST(BTreeDatabaseTest, Threading) {
|
||||
if (Random::randf() > 0.3)
|
||||
deleteKeySet.append(key);
|
||||
}
|
||||
std::random_shuffle(writeKeySet.begin(), writeKeySet.end());
|
||||
Random::shuffle(writeKeySet);
|
||||
|
||||
{
|
||||
auto writer = Thread::invoke("databaseTestWriter",
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "StarMap.hpp"
|
||||
#include "StarSet.hpp"
|
||||
#include "StarLexicalCast.hpp"
|
||||
#include "StarRandom.hpp"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -614,25 +615,25 @@ void testBTree(size_t maxIndexSize, size_t maxLeafSize) {
|
||||
}
|
||||
|
||||
// record writes/reads repeated WriteRepeat times randomly each cycle
|
||||
std::random_shuffle(keys.begin(), keys.end());
|
||||
Random::shuffle(keys);
|
||||
putAll(db, keys);
|
||||
|
||||
EXPECT_EQ(db.recordCount(), TestCount);
|
||||
|
||||
std::random_shuffle(keys.begin(), keys.end());
|
||||
Random::shuffle(keys);
|
||||
checkAll(db, keys);
|
||||
|
||||
// Random reads/writes with ShrinkCount cycles...
|
||||
for (size_t i = 0; i < ShrinkCount; ++i) {
|
||||
std::random_shuffle(keys.begin(), keys.end());
|
||||
Random::shuffle(keys);
|
||||
List<int> keysTemp = keys.slice(0, keys.size() / 2);
|
||||
|
||||
removeAll(db, keysTemp);
|
||||
|
||||
std::random_shuffle(keysTemp.begin(), keysTemp.end());
|
||||
Random::shuffle(keysTemp);
|
||||
putAll(db, keysTemp);
|
||||
|
||||
std::random_shuffle(keysTemp.begin(), keysTemp.end());
|
||||
Random::shuffle(keysTemp);
|
||||
checkAll(db, keys);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user