Skip to content

Instantly share code, notes, and snippets.

View ricejasonf's full-sized avatar

Jason Rice ricejasonf

  • Henderson, NV
View GitHub Profile
#include<iostream>
template<typename T>
struct LambdaTraits
{
using ReturnType = typename LambdaTraits<decltype(&T::operator())>::ReturnType;
};
template<typename ClassType, typename Return, typename... Args>
struct LambdaTraits<Return(ClassType::*)(Args...) const>
{
@ricejasonf
ricejasonf / variant_callback.cpp
Last active August 29, 2015 14:26
Nifty type matching for a lightweight variant type I am working on.
#include<nbdl>
#include "catch.hpp"
struct Type1 {};
struct Type2 {};
struct Type3 {};
struct Type4 {};
template<typename T>
int getInt(T tag)
{
@ricejasonf
ricejasonf / test_variant.cpp
Created August 8, 2015 23:47
A variant type I made. :D
#include<string>
#include<nbdl>
#include "catch.hpp"
TEST_CASE("Unitialized variant should match Unresolved.", "[variant]")
{
using Number = nbdl::Variant<int, std::string, float>;
Number number;
REQUIRE(number.match(
[](nbdl::Unresolved) {
@ricejasonf
ricejasonf / reverse_hana.cpp
Last active November 3, 2015 20:16
Hand Written C++11 Sequence Reverse Migrated to Hana
#include<boost/hana.hpp>
namespace hana = boost::hana;
constexpr auto my_sequence = hana::tuple_t<int, float, char>;
constexpr auto my_sequence_reversed = hana::tuple_t<char, float, int>;
static_assert(hana::reverse(my_sequence) == my_sequence_reversed, "");
int main()
@ricejasonf
ricejasonf / large_map.cpp
Last active November 12, 2015 00:45
Hana map thing that doesn't compile on my linux box.
#include<boost/hana.hpp>
#include<vector>
#include<iostream>
namespace hana = boost::hana;
struct Tag1 {};
struct Tag2 {};
struct Tag3 {};
@ricejasonf
ricejasonf / test1.cpp
Last active November 26, 2015 02:27
Benchmark checking for duplicate types.
#include<boost/hana.hpp>
namespace hana = boost::hana;
auto list_with_no_dups =
hana::unpack(
hana::range_c<int, 0, 50>,
[](auto... i) {
return hana::tuple_c<int, i...>;
});
@ricejasonf
ricejasonf / CMakeLists.txt
Last active November 30, 2015 19:32
Bloat Tests for Large Map
cmake_minimum_required(VERSION 2.8)
add_definitions(-std=c++14)
add_definitions(-Wall)
add_definitions(-Wextra)
include_directories("/usr/local/include")
add_executable(large_map_1
large_map_1.cpp
@ricejasonf
ricejasonf / pseudocode
Last active December 2, 2015 16:19
Primality Test
function is_prime(n : integer)
if n ≤ 1
return false
else if n ≤ 3
return true
else if n mod 2 = 0 or n mod 3 = 0
return false
let i ← 5
while i×i ≤ n
if n mod i = 0 or n mod (i + 2) = 0
@ricejasonf
ricejasonf / Makefile
Last active December 3, 2015 20:39
Precompiled Header Experiment
CC=clang++ -std=c++14
all: main
main: main.cpp all.hpp.pch
$(CC) main.cpp -include-pch all.hpp.pch -o main
all.hpp.pch: expensive.hpp
$(CC) expensive.hpp -o all.hpp.pch
@ricejasonf
ricejasonf / general_make.cpp
Last active December 8, 2015 00:51
C++14 Universal `make` function
#include<type_traits>
#include<iostream>
template<typename T1, typename T2>
class Moo
{
T1 t1;
T2 t2;
public: