- Timestamp:
- Mar 4, 2025, 11:26:33 AM (4 weeks ago)
- Branches:
- master
- Children:
- 45553f5
- Parents:
- 98a5ee7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Common/Iterate.hpp ¶
r98a5ee7 ree22919 208 208 return group_iterate_t<Args...>( std::forward<Args>( args )... ); 209 209 } 210 211 // -----------------------------------------------------------------------------212 // Helper struct and function to support213 // for ( val : lazy_map( container1, f ) ) {}214 // syntax to have a for each that iterates a container,215 // mapping each element by applying f.216 217 template< typename T, typename Func >218 struct lambda_iterate_t {219 const T & ref;220 std::function<Func> f;221 222 struct iterator {223 typedef decltype(begin(ref)) Iter;224 Iter it;225 std::function<Func> f;226 iterator( Iter it, std::function<Func> f ) : it(it), f(f) {}227 iterator & operator++() {228 ++it; return *this;229 }230 bool operator!=( const iterator &other ) const { return it != other.it; }231 auto operator*() const -> decltype(f(*it)) { return f(*it); }232 };233 234 lambda_iterate_t( const T & ref, std::function<Func> f ) : ref(ref), f(f) {}235 236 auto begin() const -> decltype(iterator(std::begin(ref), f)) { return iterator(std::begin(ref), f); }237 auto end() const -> decltype(iterator(std::end(ref), f)) { return iterator(std::end(ref), f); }238 };239 240 template< typename... Args >241 lambda_iterate_t<Args...> lazy_map( const Args &... args ) {242 return lambda_iterate_t<Args...>( args...);243 }244 245 // Local Variables: //246 // tab-width: 4 //247 // mode: c++ //248 // compile-command: "make install" //249 // End: //
Note: See TracChangeset
for help on using the changeset viewer.