Small header-only C++ function to mimic Python-style enumerate() ranges in for loops.
Used to automatically get index and value when enumerating lists with for loop.
Function works simillar to Python's enumerate() or Rust's .iter().enumerate()
#include "enumerator.hpp"
std::vector<std::string> v = {"a", "b", "c"};
for (const auto& [i, value] : enumerator::enumerate(v)) {
std::cout << "String " << value << " has index " << i << std::endl;
}String a has index 0 String b has index 1 String c has index 2
FetchContent_Declare( enumerator GIT_REPOSITORY https://github.com/hrykr/cpp-enumerator.git GIT_TAG v1.2.0 ) FetchContent_MakeAvailable(enumerator) # Your add_executable or add_library target_link_libraries(your_project PRIVATE enumerator::enumerator)Then use it by:
#include <enumerator/enumerator.hpp>
Copy
include/enumerator/into your projectThen use it by:
#include "enumerator/enumerator.hpp"