template

Run Settings
LanguageC++
Language Version
Run Command
#include <cstdio> #include <cstdint> #include <iostream> #include <vector> #include <algorithm> #include <numeric> #include "lib.hpp" int main( ) { std::vector<int> col{1,2,3,4,5,6,7}; std::vector<int> secondCol{1,2,3,4,5,6,7}; puts("running filter operation"); for(auto i : HigherOrderFunctions::filter(col, [](int x ) -> int { return x > 3; })) { printf(" %i", i); printf("\n"); } puts("running map operation"); for(auto i : HigherOrderFunctions::map(col, [](int x ) -> int { return x + 10; })) { printf(" %i", i); printf("\n"); } puts("running zip operation"); auto zipAdd = [] (int a, int b){ return a+b;}; for(auto i : HigherOrderFunctions::zip(col,secondCol,zipAdd) ) { printf(" %i", i); printf("\n"); } }
#include <cstdint> #include <vector> #include <algorithm> #include <numeric> namespace HigherOrderFunctions { uint64_t doubleMe ( uint64_t tmp ) { return tmp * 2; } //filter template < typename Collection, typename filterOperate > Collection filter( Collection collection, filterOperate operate ) { collection.erase( std::remove_if(collection.begin(), collection.end(), [operate]( typename Collection::value_type i ) { return !operate(i); } ), collection.end() ); return collection; } //map template < typename Collection, typename mapOperate > Collection map( Collection collection, mapOperate operate ) { std::transform( collection.begin(), collection.end(), collection.begin(), operate ); return collection; } //zip template < typename Collection, typename biOperate > Collection zip( Collection firstCollection, Collection secoundCollection, biOperate operate ) { std::transform( firstCollection.begin(), firstCollection.end(), secoundCollection.begin(), firstCollection.begin(), operate ); return firstCollection; } }
Editor Settings
Theme
Key bindings
Full width
Lines