Skip to content

Instantly share code, notes, and snippets.

@Jiwan
Jiwan / Guegant Jean
Created July 10, 2014 16:08
A c++11 way to apply a map function to some tuples
/***** maptuple.cpp *****/
#include <tuple>
#include <iostream>
#include <functional>
template<int ...S> struct indexes{};
template<int N, int ...S> struct generate_indexes : generate_indexes<N - 1, N - 1, S...> {};
@Jiwan
Jiwan / gist:380618c1b21291097ef2
Created September 5, 2014 21:44
A c++11 way to apply a map function to some tuples
/***** maptuple.cpp *****/
#include <tuple>
#include <iostream>
#include <functional>
template<int ...S> struct indexes{};
template<int N, int ...S> struct generate_indexes : generate_indexes<N - 1, N - 1, S...> {};
@Jiwan
Jiwan / main.cpp
Created October 29, 2015 12:09
C++98 SFINAE usage for serialization
#include <iostream>
struct A {};
std::string to_string(const A&)
{
return "I am a A!";
}
// Type B with a serialize method.
@Jiwan
Jiwan / main.cpp
Created October 30, 2015 16:13
C++11 example 1
#include <iostream>
struct A {};
std::string to_string(const A&)
{
return "I am a A!";
}
// Type B with a serialize method.
@Jiwan
Jiwan / main.cpp
Last active November 3, 2018 05:49
C++11 example 2 SFINAE
#include <iostream>
struct A {};
std::string to_string(const A&)
{
return "I am a A!";
}
// Type B with a serialize method.
@Jiwan
Jiwan / main.cpp
Created October 31, 2015 19:27
C++ 14 example SFINAE!
#include <boost/hana.hpp>
#include <iostream>
#include <type_traits>
struct A {};
std::string to_string(const A&)
{
return "I am a A!";
}
@Jiwan
Jiwan / repository_base.cpp
Created February 3, 2016 21:19
C++11 example for my post - An introduction to C++'s variadic templates: a thread-safe multi-type map
#include <iostream>
#include <string>
struct DefaultSlotKey;
template <class Type, class Key = DefaultSlotKey>
class Slot
{
protected:
Type& doGet()
@Jiwan
Jiwan / repository_shared_ptr.cpp
Last active December 13, 2020 15:11
C++11 example for my post - An introduction to C++'s variadic templates: a thread-safe multi-type map - using shared_ptr
#include <iostream>
#include <string>
struct DefaultSlotKey;
template <class Type, class Key = DefaultSlotKey>
class Slot
{
public:
std::shared_ptr<Type> doGet() const
@Jiwan
Jiwan / main.cpp
Created February 4, 2016 22:05
Final C++14 example for my post - An introduction to C++'s variadic templates: a thread-safe multi-type map
#include <iostream>
#include <memory>
#include <string>
#include "repository.hpp"
// Incomplete types used as compile-time keys.
struct Key1;
struct Key2;
if [ -z "$BH_ENV" ];
then
echo "Variable BH_ENV must be set and be the name of a folder in /opt";
else
echo "Configuring compiler environment.";
INSTALL_DIR=/opt/${BH_ENV}
THIRD_PARTY_DIR=${INSTALL_DIR}/thirdparty
export GCC_ENV_DIR=${INSTALL_DIR}
export GCC_BIN_DIR=${GCC_ENV_DIR}/bin