Skip to content

Instantly share code, notes, and snippets.

@meetingcpp
meetingcpp / fva.cpp
Created March 19, 2018 20:51
fusion visit & assign
namespace detail{
template <size_t I>
struct fusion_visit_impl
{
template <typename Seq, typename F>
static void visit(Seq& s, size_t idx, F&& fun)
{
static_assert(boost::fusion::result_of::size<Seq>::value >= I,"fusion index out of bounds");
if (idx == I - 1) fun(boost::fusion::get<I - 1>(s));
else fusion_visit_impl<I - 1>::visit(s, idx, std::forward<F>(fun));
@meetingcpp
meetingcpp / adapted_member_names.cpp
Created March 18, 2018 14:42
Get member names of a fusion adapted struct with mp11
template<class Seq>
constexpr std::array<const char*,boost::fusion::result_of::size<Seq>::value> get_member_names()
{
std::array<const char*,boost::fusion::result_of::size<Seq>::value> members{};
boost::mp11::mp_for_each< boost::mp11::mp_iota_c<boost::fusion::result_of::size<Seq>::value>>(
[&]( auto I ){
members[I]=boost::fusion::extension::struct_member_name<Seq,I>::call();
} );
return members;
}
@meetingcpp
meetingcpp / tagtype.hpp
Last active March 17, 2018 18:39
TMP mp11 & boost::fusion Exercise...
#include <boost/mp11.hpp>
#include <boost/mp11/mpl.hpp>
#include <boost/fusion/sequence/intrinsic/at_c.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/fusion/tuple/tuple.hpp>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/support/deduce_sequence.hpp>
//#include <boost/fusion/adapted.hpp>
@meetingcpp
meetingcpp / Selection by interface
Last active March 9, 2016 15:40
Example code for selecting by interface via enable_if/return type deduction
#include <iostream>
#include <type_traits>
#include <boost/tti/has_member_function.hpp>
#include <boost/function_types/result_type.hpp>
struct Interface
{
std::string interface()const
{
@meetingcpp
meetingcpp / qt.cmake
Created February 27, 2016 22:33
qt cmake (first try)
cmake_minimum_required(VERSION 2.8.11)
project(cmakeqttest)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
@meetingcpp
meetingcpp / jsonimport.hpp
Created February 26, 2016 20:20
Generic JSON Import - this code is accessing json via the json:: namespace and forwarding the types to various visitors to filter/import
template<class Import, class StringType = boost::string_ref>
struct JsonVisitor
{
JsonVisitor(Import& import,const boost::dynamic_bitset& filterresult):import(import),key(key),filterresult(filterresult){}
template<class Value>
bool operator()(const Value& v)const
{
import.processKeyValue(current_key,v);
return true;
}
@meetingcpp
meetingcpp / boostache_adapted_fusion_example.cpp
Created February 20, 2016 16:10
boostache example with boost fusion and adapted struct
/**
* \file boostache_adapted_fusion_example.cpp
*
* Copyright 2016 Jens Weller : meetingcpp.com
*
* Distributed under the Boost Software License, Version 1.0.
*/
#include <iostream>
#include <boost/spirit/include/support_extended_variant.hpp>