Skip to content

Instantly share code, notes, and snippets.

@SeanCline
SeanCline / filesystem_test.cpp
Created February 28, 2013 03:31
Playing with VS2012's preliminary implementation of <filesystem> before work on tr2 was halted.
#include <iostream>
#include <string>
#include <filesystem>
#include <vector>
#include <algorithm>
#include <exception>
using namespace std;
using namespace std::tr2::sys;
@SeanCline
SeanCline / http_listener_test.cpp
Last active May 12, 2022 04:52
A simple test of the experimental http_listener provided by the C++ REST SDK (Casablanca).
#define _CRT_SECURE_NO_DEPRECATE
#include <cpprest/http_listener.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <thread>
#include <chrono>
#include <ctime>
#include <stdexcept>
#include <iostream>
#include <chrono>
using namespace std;
using namespace std::chrono;
typedef long long number;
typedef int count_type;
#pragma once
#include <memory>
#include <utility>
#include <cassert>
template <typename T>
class cow_ptr
{
public:
/*
* Usage:
* void test(string s, int n) { }
* cout << function_traits<decltype(test)>::arity << endl; //< Prints 2.
* function_traits<decltype(test)>::arg<0>::type s; //< Declares a string.
* function_traits<decltype(test)>::arg<1>::type n; //< Declares an int.
*/
namespace utility {
template<typename FunctionType>
#include <iostream>
#include <string>
#include <utility>
#include <boost/format.hpp>
template<typename T>
boost::format& apply_format_args(boost::format& form, T&& t)
{
return form % std::forward<T>(t);
}
@SeanCline
SeanCline / Signal.js
Last active September 20, 2015 02:10
A minimal Signal class that lets you connect and disconnect handlers.
/*
* File: Signal.js
* Classes: Signal, Signal.Connection
* Author: Sean Cline
* Version: .1
* Description: A minimal Signal class that lets you connect and disconnect handlers to be called when .emit(...) is called.
* License: You may do whatever you please with this file and any code it contains. It is public domain.
* Usage:
* let sig = new Signal();
* let connection1 = sig.connect(function(str) { alert(str + "1") });
@SeanCline
SeanCline / clone_ptr.h
Last active April 27, 2016 17:38
A quick (mostly untested) go at a `clone_ptr` implementation that keeps from slicing polymorphic objects by type erasing their copy constructor and storing them in the clone_ptr.
#pragma once
#include <memory>
#include <utility>
#include <type_traits>
#include <functional> // TODO: Stop using functional.
template <class T>
struct default_clone {
T* operator()(const T* ptr) const
@SeanCline
SeanCline / hrm.h
Last active August 13, 2017 21:53
Implementing the assembly-like language syntax in Human Resources Machine using the C preprocessor.
#pragma once
#include <iostream>
#include <deque>
#include <vector>
struct hrm_num {
static int validate(int n)
{
if (n < -999 || n > 999)
#pragma once
#include <string>
// Why can't MFC and ATL just get along?
#if defined(_AFX) || defined(_AFXDLL)
# include <cstringt.h>
#else
# include <atlstr.h>
#endif