Skip to content

Instantly share code, notes, and snippets.

View hoffis's full-sized avatar

Marcin Hoffmann hoffis

  • Fibar Group S.A.
  • Poznań Poland
View GitHub Profile
// from blog post: http://reedbeta.com/blog/python-like-enumerate-in-cpp17/
#include <tuple>
template <typename T,
typename TIter = decltype(std::begin(std::declval<T>())),
typename = decltype(std::end(std::declval<T>()))>
constexpr auto enumerate(T && iterable)
{
struct iterator
{
@hoffis
hoffis / TrieRouter.cpp
Created June 25, 2019 13:38
Web endpoint router
#include <iostream>
#include <numeric>
#include <optional>
#include <vector>
#include <functional>
#include <boost/container/flat_map.hpp>
#include <boost/container/small_vector.hpp>
template<typename K, typename T>
struct TrieNode
#include <algorithm>
#include <utility>
#include <vector>
#include <iostream>
namespace range{
namespace detail{
using std::begin;
using std::end;
#include <stdexcept>
#include <string_view>
#include <string>
#include <type_traits>
#include <utility>
// TODO add default implementations for standard types(containers, smart pointers, optional, variant, etc)
// TODO introduce dedicated namespace for specialization of own serialize functions
//for c++14 use boost::string_ref;
#include <vector>
#include <type_traits>
#include <utility>
#include <stdexcept>
#include <string_view>
#include <tuple>
namespace Json {
template<typename T>
struct Reader
@hoffis
hoffis / SessionPool.cpp
Created March 22, 2019 23:36
Simple session pool
#include <algorithm>
#include <cassert>
#include <vector>
#include <mutex>
#include <condition_variable>
#include <memory>
#include <iostream>
template<typename Session, typename Pool>
@hoffis
hoffis / mutex_lock_cpp11.cpp
Created June 27, 2018 18:56
extended std::lock which retruns tuple of unique_locks
#include <mutex>
#include <tuple>
namespace meta {
template<int ... Ints>
struct Sequence{};
namespace details {
template<int ...Ints> struct SequenceGen;
#include <iostream>
#include <tuple>
template<int ... Ints>
struct sequence{
static constexpr std::size_t size = sizeof ...(Ints);
};
template<int ... Ns> struct seq_gen;
#include <algorithm>
template<typename Container, typename Comp, typename F>
void group_by (Container& vec, Comp comp, F&& f) {
std::sort(std::begin(vec), std::end(vec), comp);
auto it = std::begin(vec);
auto const end = std::end(vec);
while(it != end) {
auto last = std::upper_bound(it, end, *it, comp);
std::forward<F>(f)(it, last);
it = last;
#include <cstdio>
#include <string_view>
#include <string>
#include <streambuf>
#include <string>
template<typename Buffer>
class back_insert_streambuf final : public std::streambuf
{
public: