Skip to content

Instantly share code, notes, and snippets.

#include <type_traits>
#include <iostream>
using namespace std;
template <typename Iterator>
using value_type = typename Iterator::value_type;
template <typename Iterator, typename Data>
auto copy_or_move(Iterator begin, Iterator end, Data& new_memory)
@rbock
rbock / auto_recover.cpp
Created July 9, 2017 07:34
auto_recover: A class to that will restore the value of a variable on scope exit
#include <iostream>
// ---------------------------------------------
template<typename T>
class auto_recover_t
{
T& _ref;
T _value;
public:
#include <type_traits>
#include <utility>
template<typename T>
struct wrong
{
static constexpr auto value = false;
};
struct not_integral
@rbock
rbock / gist:57e49e477ce7cee6182b
Created September 10, 2015 19:13
replace include guards
#!/usr/bin/env python
import sys
import re
def convert(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
s2 = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).upper()
return re.sub('[./_]+', '_', s2)
@rbock
rbock / unique.cpp
Created November 16, 2014 21:58
Test if parameter pack arguments are unique
// This algorithm to determine if the parameter pack arguments are unique looks linear.
// It turns out to be quadratic anyway (something inside the compiler, I guess)
#include <utility>
template<typename T>
struct empty{};
template<typename... Ts>
struct unique;
#include <type_traits>
namespace sqlpp
{
namespace detail
{
// A template that always returns false
// To be used with static assert, for instance, to ensure it
// fires only when the template is instantiated.
template<typename T>