Skip to content

Instantly share code, notes, and snippets.

@ChrisTrompf
ChrisTrompf / adding_calculator.cpp
Created October 11, 2017 01:06
e0331 - Adding calculator - Using template meta programming to perform lots of the work
#include "gmock/gmock.h"
#include <iostream>
#include <sstream>
#include <type_traits>
#include <limits>
/// Given a value, return the value directly before it (without using minus)
template <typename T, T goal_value, T current_value = 0>
struct value_before { static constexpr const T value = (current_value + 1 == goal_value) ? current_value : value_before<T, goal_value, current_value + 1>::value; };