Skip to content

Instantly share code, notes, and snippets.

@bkuhns
bkuhns / gist:4612326
Last active December 11, 2015 14:09
Is std::async().... async?
#include "stdafx.h"
#include <iostream>
#include <thread>
#include <future>
#include <chrono>
using namespace std;
using namespace std::chrono;
class my_class
{
public:
struct args {
nullable<int> some_int;
nullable<float> some_float;
};
template<typename args_func>
my_class(args_func get_args)
#include "IDbService.h"
class AdoService : public IDbService {
public:
static AdoService& instance() override;
QueryResult runQuery(string query) override;
};
// main()
course.where(course.name == "Argh" && course.name == "Test");
//////////////////////
// FieldExpression.h
//////////////////////
// && operator for two FieldExpression<>'s.
template<typename L, typename R>
class Course : public Model {
[...]
public:
Field<std::string> name;
Field<long> weeks;
public:
Relation<Course, HasOne, Professor> professor;
@bkuhns
bkuhns / hippomocks.patch
Created March 12, 2013 12:13
Modifications to HippoMocks. Pulled latest from https://www.assembla.com/code/hippomocks/git/nodes/master/HippoMocks/hippomocks.h on 2013-03-13. Adds support for move-only return types like std::unique_ptr. Also attempted to patch COM support; it builds, but setting expectations is ineffective at runtime.
1133,1135c1133
< case 0x60ff018b:
< case 0x0424448b: // bkuhns: added just for fiddling with COM. Doesn't seem to work...
< return *(unsigned char *)(func + 4) / 4;
---
> case 0x60ff018b: return *(unsigned char *)(func + 4) / 4;
1568d1565
< #if 0
1580,1604d1576
< #else
@bkuhns
bkuhns / gist:5142716
Last active December 14, 2015 20:19
Example of trying to mock a COM interface.
#import <system/ado/msado15.dll> rename_namespace("ADONS"), rename("EOF", "adoEOF")
#include <hippomocks.h>
int main()
{
MockRepository mocks;
auto pConn = mocks.Mock<ADONS::_Connection>();
mocks.OnCall(pConn, ADONS::_Connection::AddRef).Return(1);
SCENARIO("...", "[...]")
{
QEventLoop eventLoop;
MockRepository mockRepo;
GIVEN("An exporter") {
auto exporterAndMocks = setUpExporterAndMocks();
auto exporter = exporterAndMocks.first;
auto mocks = exporterAndMocks.second;
#include <iostream>
#include <cstdint>
using namespace std;
//The following iterative sequence is defined for the set of positive integers:
//
//n → n/2 (n is even)
//n → 3n + 1 (n is odd)
@bkuhns
bkuhns / 0_main.cpp
Last active December 23, 2015 01:58
In reply to http://stackoverflow.com/a/18803611/245869 "For a value type Foo, why does a shared_ptr<const Foo> act like a value type even though it is a pointer type?"
#include <iostream>
#include <memory>
#include "Foo.hpp"
#include "Bar.hpp"
int main()
{
auto bar = Bar{};