Skip to content

Instantly share code, notes, and snippets.

View DVMirchev's full-sized avatar
🦑
Being

Dimitar Mirchev DVMirchev

🦑
Being
View GitHub Profile
std :: vector < int > vec {2, 5, 3, 1, 4};
std :: sort (vec.begin () vec.end ());
std :: sort (vec);
std::vector<int> vi{ 1,2,3,4,5,6,7,8,9,10 };
using namespace ranges;
// we combine two views - remove_if and transform to produce a new composition
auto evensToStrings = view::remove_if([](int i) {return i % 2 == 1; })
| view::transform([](int i) {return std::to_string(i); });
// than we applay the new compositon to the range, currently a vector
auto rng = vi | evensToStrings;
template<class InputIt, class T>
T accumulate(InputIt first, InputIt last, T init)
{
for (; first != last; ++first) {
init = init + *first;
}
return init;
}
template<class InputIt, class T, class BinaryOperation>
@DVMirchev
DVMirchev / predicate_wrapper.cpp
Last active February 7, 2019 13:00
A predicate wrapper that creates a callable with desired signature that always returns true
#include <iostream>
#include <functional>
using signa = bool(void *);
using functo_signa = std::function<bool(void *, int)>;
template <typename Signature>
struct wrapper;
template <typename Ret, typename... Args>