-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ad782c
commit 2d1e858
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
cmake_minimum_required(VERSION 3.27) | ||
|
||
set(PROJECT_NAME poc) | ||
|
||
project( | ||
${PROJECT_NAME} | ||
VERSION 1.0.0 | ||
LANGUAGES CXX | ||
) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
add_executable( | ||
${PROJECT_NAME} | ||
) | ||
|
||
if(MSVC) | ||
target_compile_options( | ||
${PROJECT_NAME} | ||
PRIVATE | ||
/W4 | ||
) | ||
else() | ||
target_compile_options( | ||
${PROJECT_NAME} | ||
PRIVATE | ||
-Wall -Wextra | ||
) | ||
endif() | ||
|
||
add_subdirectory(src) | ||
|
||
if (WIN32) | ||
add_custom_command( | ||
TARGET ${PROJECT_NAME} POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
$<TARGET_FILE:${PROJECT_NAME}> | ||
${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.exe | ||
) | ||
else() | ||
add_custom_command( | ||
TARGET ${PROJECT_NAME} POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
$<TARGET_FILE:${PROJECT_NAME}> | ||
${CMAKE_SOURCE_DIR}/${PROJECT_NAME} | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.27) | ||
|
||
target_include_directories( | ||
${PROJECT_NAME} | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
target_sources( | ||
${PROJECT_NAME} | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/mainSparseArray.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <iterator> | ||
#include <list> | ||
|
||
template <typename Component> | ||
class SparseArray { | ||
public: | ||
void add(Component component) | ||
{ | ||
_components.push_back(component); | ||
}; | ||
void erase(int id) | ||
{ | ||
auto it = _components.begin(); | ||
std::advance(it, id); | ||
_components.erase(it); | ||
}; | ||
Component &operator[](size_t idx) | ||
{ | ||
return _components[idx]; | ||
} | ||
|
||
std::list<Component>::iterator begin() | ||
{ | ||
return _components.begin(); | ||
} | ||
|
||
std::list<Component>::iterator end() | ||
{ | ||
return _components.end(); | ||
} | ||
private: | ||
std::list<Component> _components; | ||
}; |