Skip to content

Instantly share code, notes, and snippets.

View YannickJadoul's full-sized avatar

Yannick Jadoul YannickJadoul

View GitHub Profile
@YannickJadoul
YannickJadoul / CMakeLists.txt
Last active December 3, 2018 16:12
Shared data between two pybind11 modules
cmake_minimum_required(VERSION 3.8)
project(SharedDataPybind11)
add_subdirectory(pybind11)
add_library(SharedCounter SHARED SharedCounter.cpp)
target_compile_features(SharedCounter PUBLIC cxx_std_11)
if (WIN32)
target_compile_definitions(SharedCounter PRIVATE SharedCounter_EXPORTS)
endif()
@YannickJadoul
YannickJadoul / main.cpp
Last active October 21, 2022 05:58
Python with-statement in pybind11
#include <pybind11/embed.h>
#include "with.h"
#include <fstream>
#include <iostream>
namespace py = pybind11;
class PrintingMgr { public: int enter() { std::cout << "__enter__" << " - " << std::flush; return 42; }; void exit(const py::object &type, const py::object &value, const py::object &traceback) { std::cout << " - " << "__exit__" << std::endl; py::print(type, value, traceback); }; };
@YannickJadoul
YannickJadoul / functor_signature.h
Last active November 21, 2017 00:04
get_signature function for the usage of lambdas and functors in Boost.Python
#ifndef INC_FUNCTOR_SIGNATURE_H
#define INC_FUNCTOR_SIGNATURE_H
#include <boost/mpl/erase.hpp>
#include <boost/mpl/vector.hpp>
namespace boost {
namespace python {
namespace detail {
template <class Functor>