Skip to content

Instantly share code, notes, and snippets.

@sjrdc
sjrdc / polypimpl.cpp
Created May 22, 2019 20:01
polymorphism in pimpl
#include <iostream>
#include <memory>
enum class FooType
{
Bar,
Baz
};
namespace Impl
@sjrdc
sjrdc / arrayview.cpp
Last active February 21, 2019 07:42
multidimensional view of continuous memory array
#include <iostream>
#include <string>
#include <cassert>
#include <iterator>
#include <array>
#include <numeric>
#include <vector>
template<bool...> struct bool_pack{};
@sjrdc
sjrdc / templates_arrays.cpp
Created February 12, 2019 20:35
templated functions that work with fixed size arrays
// Example program
#include <iostream>
#include <iterator>
#include <algorithm>
template <typename T, size_t N>
void Show(const T (&array)[N])
{
std::copy(std::begin(array), std::end(array), std::ostream_iterator<T>(std::cout, " "));
}
@sjrdc
sjrdc / private_override.cpp
Created January 8, 2019 18:31
private virtual function override cannot be called on derived class
#include <iostream>
class Base
{
public:
virtual ~Base() {}
virtual void Bar() = 0;
};
class Derived : public Base
@sjrdc
sjrdc / crtp_poly.cpp
Created January 2, 2019 08:03
mixing crtp and polymorphism
#include <iostream>
#include <memory>
#include <typeinfo>
using namespace std;
namespace
{
class IPrintable
{
@sjrdc
sjrdc / tokenize.cpp
Last active March 1, 2018 14:18
tokenize string
#include <string>
#include <vector>
std::vector<std::string> Tokenize(const std::string& str, const std::string& delimiter)
{
std::vector<std::string> tokens;
if (delimiter.empty())
{
tokens.push_back(str);
}
template <typename R>
class MultiFuncObject
{
std::unordered_map<std::type_index, void(*)()> m_funcs;
public:
template <typename ...A1>
MultiFuncObject<R> operator +=(R(*f)(A1...))
{
@sjrdc
sjrdc / Makefile
Created February 7, 2017 22:30 — forked from ddemidov/Makefile
odeint with boost.compute backend
lorenz: lorenz.cpp
g++ -o $@ $^ -std=c++11 -O3 \
-I${HOME}/work/odeint-v2 \
-I${HOME}/work/opencl/compute/include/ \
-lOpenCL -lboost_system -lboost_timer
@sjrdc
sjrdc / change_year
Created September 30, 2016 11:25
change year in jpeg date/time metadata
#!/bin/bash
newyear=$1
for j in *.JPG; do
tag=CreateDate
datetime=$(exiftool -$tag $j | sed -e 's|^.*: ||')
year=$(echo $datetime | sed -e 's|:[0-9 :]*||')
newdatetime=${datetime/$year/$newyear}
@sjrdc
sjrdc / list_of_mri_simulators.md
Last active March 1, 2024 06:59
List of MRI simulators