Skip to content

Instantly share code, notes, and snippets.

View johnmcfarlane's full-sized avatar

John McFarlane johnmcfarlane

View GitHub Profile
@johnmcfarlane
johnmcfarlane / yaml_deep_compare.hpp
Created November 2, 2015 22:59
For yaml-cpp: `bool isEqual(YAML::Node const &lhs, YAML::Node const &rhs)`
bool isEqual(YAML::Node const &lhs, YAML::Node const &rhs) {
if (lhs == rhs) {
return true;
}
YAML::NodeType::value lhs_type = lhs.Type();
if (lhs_type != rhs.Type()) {
return false;
}
zoox::unique_ptr<FRawMesh> ReadPly(ByteBuffer const & buffer)
{
// read the header
constexpr auto header =
"ply\n\n"
"format binary_little_endian 1.0\n"
"comment This contains a Splatted Point Cloud\n"
"element vertex %d\n"
"property float x\n"
"property float y\n"
@johnmcfarlane
johnmcfarlane / functor.c
Last active May 3, 2020 17:08
Illustrates run-time polymorphism in C
// functor.c : Illustrates run-time polymorphism in C.
//
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
////////////////////////////////////////////////////////////////////////////////
// APIs
@johnmcfarlane
johnmcfarlane / fixed_point.md
Created July 9, 2016 20:41
Result of running fixed_point.h through standardese

Header file fixed_point.h

#define SG14_FIXED_POINT_H 1

#include "type_traits.h"

#include "bits/common.h"

#define SG14_FIXED_POINT_EXCEPTIONS_ENABLED

Header file fixed_point.h

#define SG14_FIXED_POINT_H 1

#include "type_traits.h"

#include "bits/common.h"

#define SG14_FIXED_POINT_EXCEPTIONS_ENABLED 
static auto start = std::chrono::system_clock::now();
auto t = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::system_clock::now() - start).count();
@johnmcfarlane
johnmcfarlane / iso_4217.cpp
Created November 11, 2016 08:31
ISO 4217 vs ISO C++
namespace iso_4217 {
struct code {
const char* entity;
const char* currency;
const char* alpha;
int numeric;
int minor_unit;
};
constexpr const char* currency_na = nullptr;
@johnmcfarlane
johnmcfarlane / elastic
Last active November 15, 2016 04:11
single-header version of header, elastic.h, from johnmcfarlane/fixed_point
// Copyright John McFarlane 2015 - 2016.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file ../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
/// \file
/// \brief essential definitions related to the `sg14::elastic` type
#define SG14_USE_INT128
@johnmcfarlane
johnmcfarlane / godbold_square.cpp
Last active June 24, 2017 09:30
example of zero-cost abstraction using the fixed_point library
// Signed 15:16 Fixed-Point Square Function Using sg14::elastic
#include <https://gist.githubusercontent.com/johnmcfarlane/23b8bc5fefb77d482306c5bc837b5df1/raw/ed6cdfc3de42ae3c140bbbdd0ce5b8bc131d1f02/fixed_point.h>
using namespace sg14;
// square a nunber using 15:16 fixed-point arithmetic
// without using a fixed-point library
float square_int(float input) {
// user must scale values by the correct amount
@johnmcfarlane
johnmcfarlane / value_type.hpp
Created December 12, 2016 07:41
possible implementation of proposed standard library additions, std::value_type and std::value_type_t
#include <array>
#include <atomic>
#include <complex>
#include <cstddef>
#include <functional>
#include <list>
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>