Skip to content

Instantly share code, notes, and snippets.

View martinmoene's full-sized avatar

Martin Moene martinmoene

View GitHub Profile
@martinmoene
martinmoene / gist:9091556
Created February 19, 2014 13:04
element_or(), container_element_or()
// element_or()
// container_element_or()
#include <map>
#include <vector>
/**
* return element of vector if present, def otherwise.
*/
template< typename E, typename I, typename D >
@martinmoene
martinmoene / catch_tostring.cpp
Last active December 16, 2015 11:09
CATCH to_string based on CATCH v0.9 build 33, with different has_insertion_operator<>. 1. 'direct' tranfer from catch_tostring.hpp. 2. Replaced stream inserter detection with has_insertion_operator<>. 3. Added conditional changes for VC6.
// Notes at bottom.
// catch_common.h -----------------------------
#ifndef TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
#define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
#define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
@martinmoene
martinmoene / InsertionOpDetector.cpp
Last active December 16, 2015 10:19
Check for global operator<< for GCC 4.7.2, lang 3.1, VC2010, VC8, VC6
// http://stackoverflow.com/a/5771273/437272
#include <iosfwd>
namespace detail {
typedef char no;
typedef char yes[2];
struct any_t {
@martinmoene
martinmoene / DynLibString.cpp
Last active December 15, 2015 11:38
A String class to use over a DLL boundary, enabling the use of different compiler versions at both ends.
//
// Note: use _bstr_t. It's part of COM and present in VC6 and newer versions of Visual C++.
// It's an encapsulation of the BSTR string type that has a shared *C* API. It's used for
// interlanguage operability, so going between compiler/library versions is *not* a problem.
//
// Thanks to the kind people on the accu-general mailing list of http://accu.org/
//
//============================================================================
// String.h
@martinmoene
martinmoene / TestOpAssign-variations.cpp
Created October 4, 2012 10:23
Variations on Performance test of X& operator=(X?)
/*
* TestOpAssign-variations-variations.cpp
*
* Created by Martin on 4 October 2012.
* Copyright 2012 Universiteit Leiden. All rights reserved.
*
* 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)
*/
@martinmoene
martinmoene / TestOpAssign_Niels_Martin.cpp
Created October 2, 2012 12:38
Performance test of X& operator=(X?)
/*
* TestOpAssign_Niels_Martin.cpp
*
* Created by Martin on 28 September 2012.
* Adapted by Niels Dekker, 1 Oct 2012
* Copyright 2012 Universiteit Leiden. All rights reserved.
*
* 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)
*/
@martinmoene
martinmoene / TestOpAssign.cpp
Created September 29, 2012 22:05
Performance test of X& operator=(X)
/*
* TestOpAssign.cpp
*
* Created by Martin on 28 September 2012.
* Copyright 2012 Universiteit Leiden. All rights reserved.
*
* 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)
*/