openMSX
Functions
enumerate.hh File Reference
#include <cstddef>
#include <iterator>
#include <tuple>
#include <utility>
Include dependency graph for enumerate.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename Iterable , typename Iter = decltype(std::begin(std::declval<Iterable>())), typename = decltype(std::end (std::declval<Iterable>()))>
constexpr auto enumerate (Iterable &&iterable)
 Heavily inspired by Nathan Reed's blog post: Python-Like enumerate() In C++17 http://reedbeta.com/blog/python-like-enumerate-in-cpp17/. More...
 

Function Documentation

◆ enumerate()

template<typename Iterable , typename Iter = decltype(std::begin(std::declval<Iterable>())), typename = decltype(std::end (std::declval<Iterable>()))>
constexpr auto enumerate ( Iterable &&  iterable)
constexpr

Heavily inspired by Nathan Reed's blog post: Python-Like enumerate() In C++17 http://reedbeta.com/blog/python-like-enumerate-in-cpp17/.

Can be used to simplify loops like: for (size_t i = 0; i < std::size(my_array); ++i) { auto& elem = my_array[i]; ... do stuff with 'i' and 'elem' }

With enumerate() that becomes: for (auto [i, elem] : enumerate(my_array)) { ... do stuff with 'i' and 'elem' }

Definition at line 28 of file enumerate.hh.

References begin(), end(), openmsx::operator!=(), operator*(), and openmsx::operator==().

Referenced by openmsx::ColecoJoystickIO::ColecoJoystickIO(), openmsx::JoyTap::createPorts(), openmsx::NowindCommand::execute(), openmsx::V9990SDLRasterizer< Pixel >::preCalcPalettes(), openmsx::RawTrack::readBlock(), openmsx::MegaFlashRomSCCPlusSD::reset(), openmsx::MusicalMemoryMapper::reset(), openmsx::RGBTriplet3xScaler< Pixel >::scaleBlank1to3(), openmsx::RGBTriplet3xScaler< Pixel >::scaleBlank2to3(), openmsx::SDLSnow< Pixel >::SDLSnow(), openmsx::MSXFDC::serialize(), openmsx::MB89352::serialize(), openmsx::WD33C93::serialize(), openmsx::JoyTap::serialize(), openmsx::MSXMapperIO::serialize(), openmsx::RomHolyQuran2::serialize(), openmsx::MSXS1985::serialize(), openmsx::I8254::serialize(), openmsx::MSXSCCPlusCart::serialize(), openmsx::SCC::serialize(), openmsx::YM2413Okazaki::YM2413::serialize(), openmsx::YMF278::serialize(), openmsx::Multiply< uint16_t >::setFactor(), openmsx::Multiply32< uint16_t >::setFactor32(), TEST_CASE(), openmsx::YM2413Okazaki::Slot::updatePG(), openmsx::NinjaTap::write(), openmsx::RawTrack::writeBlock(), and ProfileCounters< ENABLED, ENUM >::~ProfileCounters().