Skip to content

Instantly share code, notes, and snippets.

View Fraser999's full-sized avatar

Fraser Hutchison Fraser999

  • Dalrymple, Scotland.
View GitHub Profile
@Fraser999
Fraser999 / boost_optional_size.cc
Created May 15, 2013 16:39
Size of boost::optional
#include <iostream>
#include <memory>
#include <string>
#include "boost/optional.hpp"
int main() {
std::unique_ptr<std::string> ptr(new std::string("A"));
boost::optional<std::string> opt_empty;
boost::optional<std::string> opt_full("A");
std::cout << "ptr: " << sizeof(ptr) << '\n';
@Fraser999
Fraser999 / CMakeLists.txt
Created April 10, 2013 02:09
CMake's ExternalProject_Add for GMock
cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
project(Test)
# Create main.cpp which uses gmock
file(WRITE src/main.cpp "#include \"gmock/gmock.h\"\n\n")
file(APPEND src/main.cpp "struct A {\n virtual void Do() {}\n};\n\n")
file(APPEND src/main.cpp "struct MockA : public A {\n MOCK_METHOD0(Do, void());\n};\n\n")
file(APPEND src/main.cpp "TEST(A, Do) {\n")
file(APPEND src/main.cpp " MockA mock_a;\n")
file(APPEND src/main.cpp " EXPECT_CALL(mock_a, Do()).Times(testing::AtLeast(1));\n")
@Fraser999
Fraser999 / condition_variable_issue.cc
Created October 16, 2012 16:23
Shows issue relating to invoking boost::condition_variable::notify_all outside of mutex-protected scope
#include <condition_variable>
#include <thread>
#include "boost/thread/condition_variable.hpp"
#include "boost/thread/thread.hpp"
template<typename Thread, typename Lock, typename CondVar>
void Loop() {
for (int i = 0; i < 10000; ++i) {
CondVar condition_variable;
@Fraser999
Fraser999 / Git Console Output
Created March 3, 2015 13:56
MaidSafe clone and build commands with output
Fraser@FRASER-HOME /e/Test
$ git clone git@github.com:maidsafe/MaidSafe
Cloning into 'MaidSafe'...
remote: Counting objects: 64668, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 64668 (delta 2), reused 0 (delta 0), pack-reused 64659
Receiving objects: 100% (64668/64668), 98.76 MiB | 5.93 MiB/s, done.
Resolving deltas: 100% (34142/34142), done.
Checking connectivity... done.
#include <iostream>
#include <string>
using namespace std;
template <typename Child>
struct Routing
{
Routing() = delete;
explicit Routing(std::string s) : t(s) {}
void Get()
@Fraser999
Fraser999 / CMakeLists.txt
Created September 5, 2014 00:17
Demo of target_include_directories(... INTERFACE ...)
cmake_minimum_required(VERSION 3.0)
project(x)
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/include/fonts.hpp"
"#include <iostream>\ninline int Print() { std::cout << \"Running.\\n\"; return 0; }\n")
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp"
"#include \"fonts.hpp\"\nint main() { return Print(); }\n")
add_library(Fonts INTERFACE)
target_include_directories(Fonts INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")