Skip to content

Instantly share code, notes, and snippets.

View dirvine's full-sized avatar

David Irvine dirvine

View GitHub Profile
@dirvine
dirvine / c++11_regular.h
Last active August 29, 2015 14:07
c++11_regular
// from Eric Niebler's talk from C++Now 2014 https://www.youtube.com/watch?v=zgOF4NrQllo
class RegularCxx11 {
RegularCxx11();
RegularCxx11(RegularCxx11 const &);
RegularCxx11(RegularCxx11 &&) noexcept;
~RegularCxx11();
RegularCxx11 & operator=(RegularCxx11 const &);
RegularCxx11 & operator=(RegularCxx11 &&) noexcept;
friend bool operator==(RegularCxx11 const &, RegularCxx11 const &);
friend bool operator!=(RegularCxx11 const &, RegularCxx11 const &);
#==================================================================================================#
# #
# Copyright 2012 MaidSafe.net limited #
# #
# This MaidSafe Software is licensed to you under (1) the MaidSafe.net Commercial License, #
# version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which #
# licence you accepted on initial access to the Software (the "Licences"). #
# #
# By contributing code to the MaidSafe Software, or to this project generally, you agree to be #
# bound by the terms of the MaidSafe Contributor Agreement, version 1.0, found in the root #
@dirvine
dirvine / Atomic
Last active August 29, 2015 14:05
monitor<T>
template<class T>
class Atomic {
private:
mutable T t;
mutable std::mutex m;
public:
Atomic( T t_ ) : t( t_ ) { }
template<typename F>
auto operator()( F f ) const -> decltype(f(t))
@dirvine
dirvine / myclass.h
Last active December 19, 2015 07:49
FullyOrdered c++11 class (assume that will work in msvc as well as gcc clang)
#ifndef MY_CLASS_H
#define MY_CLASS_H
#include <tuple>
#include <utility>
template <typename T, typename U>
struct MyClass {
T first;
U second;
@dirvine
dirvine / turing.cc
Created February 9, 2013 22:38
turing machine, not sure where this is from I am not the origin author.
/*
* =====================================================================================
*
* Filename: turing.cc
*
* Description:
*
* Version: 1.0
* Created: 30/07/12 19:16:46
* Revision: none
@dirvine
dirvine / max_template.cc
Created February 9, 2013 22:15
template form of max as test
/*
* =====================================================================================
*
* Filename: max_template.cc
*
* Description: simple template example
*
* Version: 1.0
* Created: 25/07/12 19:56:01
* Revision: none
@dirvine
dirvine / check_concept.cc
Created January 24, 2013 08:49
Concept checker
// sfinae test for has ThisFunc() method
template <typename T>
class has_this_func {
typedef char one[1];
typedef char two[2];
template <typename U> static one test(decltype(&U::ThisFunc()); // could also be *U::Routing() for pointer to ThisFunc
// the above gets masked out as sfinae will choose two
template <typename U) static two test(...);
public:
static bool const value = sizeof(test<T>(0)) == sizeof(one);
@dirvine
dirvine / endian.cc
Created January 10, 2013 01:01
Endian calculation (unrestricted union)
union Endian {
char c;
int i;
Endian(void) : i(1) { };
bool big(void) { return !!c; };
} endian;
cerr << (endian.big() ? "big" : "little");
@dirvine
dirvine / dummy.cc
Created June 18, 2012 14:22
boost process test
#include <boost/program_options.hpp>
#include <thread>
#include <chrono>
#include <iostream>
namespace po = boost::program_options;
int main(int ac, char* av[]) {
po::options_description desc("Allowed options");
desc.add_options()