Skip to content

Instantly share code, notes, and snippets.

// ----------------------------------------------------------------------------------------------
// Copyright 2015 Mårten Rånge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
@mrange
mrange / enter.cpp
Last active September 11, 2015 18:10
C++ Enter macros
#include <iostream>
#include <sstream>
#include <type_traits>
#define TRACE_ENTER(...) trace_enter (__FILE__, __LINE__, __FUNCTION__, "(" #__VA_ARGS__ ")", ##__VA_ARGS__); leave_guard lg (__FILE__, __LINE__, __FUNCTION__);
void trace_enter_impl (std::ostream & os)
{
}
#include <cstdint>
#include <istream>
#include <sstream>
struct saved_state
{
saved_state ()
: head (0xAABBCCDD)
, tail (0xEEFF0000)
{
#include <cstdint>
#include <cstring>
#include <type_traits>
#include <stdexcept>
template<typename T, std::uint32_t size>
struct sticky_circular_buffer
{
static_assert (size > 0 , "size must be greater than 0" );
@mrange
mrange / bprintf.cpp
Last active September 28, 2015 12:42
#include <cassert>
#include <cstdlib>
#include <cstdint>
#include <vector>
#include <string>
#include <type_traits>
#include <typeindex>
#define BPRINTF_ASSERT assert
@mrange
mrange / ts_printf.cpp
Last active October 6, 2015 07:08
Type-safe printf
// ----------------------------------------------------------------------------------------------
// Copyright 2015 Mårten Rånge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
#include <ostream>
#include <type_traits>
namespace
{
namespace details
{
template<typename T>
struct sfinae_true : std::true_type
{
#include <array>
#include <iostream>
#include <iterator>
#include <map>
#include <ostream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <cassert>
#include <iostream>
#include <map>
#include <tuple>
#include <type_traits>
namespace
{
template<typename T>
using System;
using System.Collections.Generic;
using System.Linq;
namespace TR
{
static class Program
{
static int Length2<T> (int l, IEnumerator<T> e)
{