Add static_assert, components must be def-const
EC::Manager will fail to compile if any given Component is not default constructible, so a static_assert and ctest was added.
This commit is contained in:
parent
6bf239a43b
commit
8c462b83a1
4 changed files with 43 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,4 +2,5 @@ build*/
|
||||||
*.o
|
*.o
|
||||||
*.swp
|
*.swp
|
||||||
doxygen_html/
|
doxygen_html/
|
||||||
|
compile_commands.json
|
||||||
|
tags
|
||||||
|
|
|
@ -16,6 +16,9 @@ set(EntityComponentSystem_HEADERS
|
||||||
EC/Manager.hpp
|
EC/Manager.hpp
|
||||||
EC/EC.hpp)
|
EC/EC.hpp)
|
||||||
|
|
||||||
|
set(WillFailCompile_SOURCES
|
||||||
|
test/WillFailCompileTest.cpp)
|
||||||
|
|
||||||
add_library(EntityComponentSystem INTERFACE)
|
add_library(EntityComponentSystem INTERFACE)
|
||||||
target_link_libraries(EntityComponentSystem INTERFACE pthread)
|
target_link_libraries(EntityComponentSystem INTERFACE pthread)
|
||||||
target_include_directories(EntityComponentSystem INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(EntityComponentSystem INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
@ -56,3 +59,11 @@ if(GTEST_FOUND)
|
||||||
add_test(NAME UnitTests COMMAND UnitTests)
|
add_test(NAME UnitTests COMMAND UnitTests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_executable(WillFailCompile ${WillFailCompile_SOURCES})
|
||||||
|
set_target_properties(WillFailCompile PROPERTIES
|
||||||
|
EXCLUDE_FROM_ALL True
|
||||||
|
EXCLUDE_FROM_DEFAULT_BUILD True)
|
||||||
|
add_test(NAME WillFailCompile_0
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build . --target WillFailCompile --config $<CONFIGURATION>
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
|
set_tests_properties(WillFailCompile_0 PROPERTIES WILL_FAIL True)
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -59,6 +60,10 @@ namespace EC
|
||||||
using BitsetType = EC::Bitset<ComponentsList, TagsList>;
|
using BitsetType = EC::Bitset<ComponentsList, TagsList>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
using ComponentsTuple = EC::Meta::Morph<ComponentsList, std::tuple<> >;
|
||||||
|
static_assert(std::is_default_constructible<ComponentsTuple>::value,
|
||||||
|
"All components must be default constructible");
|
||||||
|
|
||||||
template <typename... Types>
|
template <typename... Types>
|
||||||
struct Storage
|
struct Storage
|
||||||
{
|
{
|
||||||
|
@ -66,6 +71,7 @@ namespace EC
|
||||||
};
|
};
|
||||||
using ComponentsStorage =
|
using ComponentsStorage =
|
||||||
typename EC::Meta::Morph<ComponentsList, Storage<> >::type;
|
typename EC::Meta::Morph<ComponentsList, Storage<> >::type;
|
||||||
|
|
||||||
// Entity: isAlive, ComponentsTags Info
|
// Entity: isAlive, ComponentsTags Info
|
||||||
using EntitiesTupleType = std::tuple<bool, BitsetType>;
|
using EntitiesTupleType = std::tuple<bool, BitsetType>;
|
||||||
using EntitiesType = std::vector<EntitiesTupleType>;
|
using EntitiesType = std::vector<EntitiesTupleType>;
|
||||||
|
|
24
src/test/WillFailCompileTest.cpp
Normal file
24
src/test/WillFailCompileTest.cpp
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <EC/Manager.hpp>
|
||||||
|
|
||||||
|
struct NoDef
|
||||||
|
{
|
||||||
|
NoDef(int a) : a(a) {}
|
||||||
|
|
||||||
|
int a;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WithDef
|
||||||
|
{
|
||||||
|
WithDef() : a(0) {}
|
||||||
|
|
||||||
|
int a;
|
||||||
|
};
|
||||||
|
|
||||||
|
using EC::Meta::TypeList;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// should fail to compile because "NoDef" is not default constructible
|
||||||
|
EC::Manager<TypeList<WithDef, NoDef>, TypeList<>> manager;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue