Skip to content

Instantly share code, notes, and snippets.

@caiorss
caiorss / CMakeLists.txt
Last active May 1, 2019 14:35
Experiments with C++ ranges v3 Library
cmake_minimum_required(VERSION 3.9)
project(cppexperiments)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(FORCE_CLANG ON)
# Force compiler to Clang++
if(FORCE_CLANG)
@caiorss
caiorss / mymodule.cpp
Last active January 21, 2022 09:42
Sample C++ Python native module
// Author: Caio Rodrigues
// Descr: Sample Native Python 3 module (library) DLL
//
// Compile with:
// $ clang++ mymodule.cpp -o mymodule.so -g -std=c++1z -fPIC -shared -I/usr/include/python3.6m
//-------------------------------------------------------
#include <iostream>
#include <string>
#include <functional>
@caiorss
caiorss / Program-output.txt
Created February 14, 2019 00:15
Boost Operators:
$ clang++ boost-operator.cpp -o boost-operator.bin -std=c++1z -g -O0 -Wall && ./boost-operator.bin
=>> v1 = Vec3D{ x = 3 ; y = 5 ; z = 6 }
=>> v2 = Vec3D{ x = 12 ; y = 5 ; z = 9 }
=>> v1.norm() = 8.3666
=>> v2.norm() = 15.8114
EXPERIMENT 1 boost::less_than_comparable<Vec3D>
--------------------------------------------------
[a] v1 < v2 = true
@caiorss
caiorss / cstr.cpp
Created February 10, 2019 06:19
Python Ctypes wrapper to C++ shared library returning dynamically allocated string buffers
// Compile with:
// $ clang++ cstr.cpp -o cstr.so -std=c++1z -O0 -g -shared -fPIC -std=c++1z
//----------------------------------------------------
#include <iostream>
#include <string>
#include <sstream>
#include <cstring> // std::strncpy
#include <cmath>
#if defined(_WIN32)
@caiorss
caiorss / Doxyfile
Last active March 8, 2021 17:11
C++ Doxygen Detailed Example
# Doxyfile 1.8.14
# This file describes the settings to be used by the documentation system
# doxygen (www.doxygen.org) for a project.
#
# All text after a double hash (##) is considered a comment and is placed in
# front of the TAG it is preceding.
#
# All text after a single hash (#) is considered a comment and will be ignored.
# The format is:
@caiorss
caiorss / optional1.cpp
Last active January 22, 2019 04:22
C++17 Optional Example
#include <iostream>
#include <string> // std::stof
#include <ostream> // operator (<<) and class ostream
#include <vector>
#include <iomanip> // setprecision
#include <optional>
// Class with optional field.
struct Location{
@caiorss
caiorss / CMakeLists.txt
Last active January 9, 2019 02:56
Example: Cmake C++ project with VCPKG package manager and OpengGL/FreeGlut on Windows
cmake_minimum_required(VERSION 3.9)
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
message(" [INFO] VCPKG CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
endif()
#========== Global Configurations =============#
#----------------------------------------------#
@caiorss
caiorss / CMakeLists.txt
Created January 9, 2019 00:38
Example C++ project with Cmake + VCPKG package manager + Nana GUI library
cmake_minimum_required(VERSION 3.9)
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
message(" [INFO] VCPKG CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
endif()
#======= Global Project Configuration =========#
@caiorss
caiorss / ws-scripting.cpp
Created January 2, 2019 07:44
Add scripting capability to your C++ project using Windows Script Host
#include <windows.h>
#include <objbase.h>
#include <activscp.h>
#include <atomic>
#include <cassert>
#include <cstdio>
class ScriptSite : public IActiveScriptSite
{
public:
@caiorss
caiorss / cpp17-filesys1.cpp
Created December 28, 2018 08:21
C++17 File System Library
#include <iostream>
#include <string>
#include <iterator>
#include <iomanip>
// C++17 - Requires compiler linking flag: -lstdc++fs on CLang or GCC.
#include <filesystem>
namespace fs = std::filesystem;