TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_container_utilities.hpp
1 
9 #ifndef TurtleBrains_ContainerUtilities_hpp
10 #define TurtleBrains_ContainerUtilities_hpp
11 
12 #include <vector>
13 
14 namespace TurtleBrains::Core::ContainerUtilities
15 {
16 
17  // 2024-11-21: Didn't actually get this working as ContainerType "vector, map, etc" wasn't able to do ContainerType<Type>
18  // quite like I desired. Perhaps could just use a ContainerType and access the ::type inside it?
19  //template<typename Type, typename ContainerType> bool Contains(const std::vector<Type>& container, const Type& item)
20  //{
21  // for (const Type& itemInContainer : container)
22  // {
23  // if (itemInContainer == item)
24  // {
25  // return true;
26  // }
27  // }
28 
29  // return false;
30  //}
31 
32  template<typename Type> void PushBackAndCycle(std::vector<Type>& container, const Type& value, std::size_t maximumSize)
33  {
34  if (container.size() < maximumSize)
35  {
36  container.push_back(value);
37  }
38  else
39  {
40  for (std::size_t index = 1; index < container.size() - 1; ++index)
41  {
42  container[index] = container[index + 1];
43  }
44  container.back() = value;
45  }
46  }
47 
48 }; /* namespace TurtleBrains::Core::ContainerUtilties */
49 
50 namespace tbCore = TurtleBrains::Core;
51 
52 #endif /* TurtleBrains_ContainerUtilities_hpp */
Contains core functionality for each component of the API.
Definition: tb_debug_logger.hpp:125