Skip to content

Instantly share code, notes, and snippets.

@Fiona-J-W
Fiona-J-W / main.cpp
Created June 30, 2014 19:17
rounding-error
#include <cmath>
#include <iostream>
int main() {
double num1 = 1.4126572077159485e+23;
double num2 = 1.4126572077159483546e+23;
double num3 = std::nexttoward(num2, num1);
std::cout << (num3 > num2) << '\n';
}
#ifndef ENFORCE_H_
#define ENFORCE_H_
#include <cassert>
#include <stdexcept>
#include <string>
namespace Aux {
/**
@Fiona-J-W
Fiona-J-W / main.cpp
Created June 21, 2014 21:10
handle-manager
#include <type_traits>
#include <utility>
template<typename Handle, class Releaser>
Handle get_null_handle() {
return Handle{};
}
template<typename Handle, typename Releaser>
@Fiona-J-W
Fiona-J-W / main.cpp
Last active August 29, 2015 14:02
inversion-calculator
#include <algorithm>
#include <string>
#include <iostream>
#include <iterator>
#include <cstdint>
int main() {
std::string line;
while(std::getline(std::cin, line)) {
std::size_t inversions = 0;
#include <cassert>
#include <iostream>
enum class side {
good,
evil
};
enum class strength {
strong,
@Fiona-J-W
Fiona-J-W / main.cpp
Created May 2, 2014 17:50
char-range to integer
#include <array>
#include <cassert>
#include <chrono>
#include <iostream>
#include <limits>
#include <random>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
set nu
set tabstop=8
set shiftwidth=8
" many thanks to steve losh. his blogpost at
" http://stevelosh.com/blog/2010/09/coming-home-to-vim
@Fiona-J-W
Fiona-J-W / main.cpp
Created April 4, 2014 01:17
tuple_reader
#include <iostream>
#include <tuple>
#include <istream>
template<unsigned Index, unsigned Max, typename Tuple>
struct read_tuple_helper {
static void read(std::istream& stream, Tuple& tuple) {
stream >> std::get<Index>(tuple);
@Fiona-J-W
Fiona-J-W / main.cpp
Created April 4, 2014 01:08
on_heap_creator
#include <iostream>
#include <utility>
struct foobar{
std::string value = "fooabarbazquux";
foobar() = default;
foobar(const foobar& other): value{other.value} {
std::cout << "foobar(const foobar&)\n";
}
@Fiona-J-W
Fiona-J-W / main.cpp
Created April 3, 2014 01:20
A short example for a simple find_if using tmp
#include <iostream>
#include <type_traits>
template<bool B, unsigned Index, template<typename> class Predicate, typename...Tail>
struct find_if_helper2;
template<template<typename> class Predicate, unsigned Index, typename Head, typename...Tail>
struct find_if_helper1{
using type = typename find_if_helper2<Predicate<Head>::value, Index, Predicate, Tail...>::type;
};