From a87733917aba948044b067e75c7149f3e95191aa Mon Sep 17 00:00:00 2001 From: Ben Cumming <bcumming@cscs.ch> Date: Tue, 16 Aug 2016 08:37:30 +0200 Subject: [PATCH] improve STL iterator support in threading code * use iterator and const_iterator type members instead of iterator_type and const_iterator_type * add begin() end() to the thread_enumerable spike storage to iterator over thread local storage --- src/thread_private_spike_store.hpp | 12 ++++++++++++ src/threading/serial.hpp | 18 +++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/thread_private_spike_store.hpp b/src/thread_private_spike_store.hpp index 1e14ab10..3f320fdd 100644 --- a/src/thread_private_spike_store.hpp +++ b/src/thread_private_spike_store.hpp @@ -69,6 +69,18 @@ private : threading::enumerable_thread_specific<std::vector<spike_type>>; local_spike_store_type buffers_; + +public : + using iterator = typename local_spike_store_type::iterator; + using const_iterator = typename local_spike_store_type::const_iterator; + + // make the container iterable + // we iterate of threads, not individual containers + + iterator begin() { return buffers_.begin(); } + iterator end() { return buffers_.begin(); } + const_iterator begin() const { return buffers_.begin(); } + const_iterator end() const { return buffers_.begin(); } }; } // namespace mc diff --git a/src/threading/serial.hpp b/src/threading/serial.hpp index c18d4800..da2740a6 100644 --- a/src/threading/serial.hpp +++ b/src/threading/serial.hpp @@ -19,10 +19,10 @@ namespace threading { template <typename T> class enumerable_thread_specific { std::array<T, 1> data; - using iterator_type = typename std::array<T, 1>::iterator; - using const_iterator_type = typename std::array<T, 1>::const_iterator; - public : +public : + using iterator = typename std::array<T, 1>::iterator; + using const_iterator = typename std::array<T, 1>::const_iterator; enumerable_thread_specific() = default; @@ -39,14 +39,14 @@ class enumerable_thread_specific { auto size() -> decltype(data.size()) const { return data.size(); } - iterator_type begin() { return data.begin(); } - iterator_type end() { return data.end(); } + iterator begin() { return data.begin(); } + iterator end() { return data.end(); } - const_iterator_type begin() const { return data.begin(); } - const_iterator_type end() const { return data.end(); } + const_iterator begin() const { return data.begin(); } + const_iterator end() const { return data.end(); } - const_iterator_type cbegin() const { return data.cbegin(); } - const_iterator_type cend() const { return data.cend(); } + const_iterator cbegin() const { return data.cbegin(); } + const_iterator cend() const { return data.cend(); } }; -- GitLab