Skip to content

Instantly share code, notes, and snippets.

@bolry
bolry / windows32-toolchain.cmake
Created June 23, 2024 21:42
CMake toolchain files for building Windows applications on Linux
# windows32-toolchain.cmake
# Specify the cross-compilation target system
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86)
# Specify the cross-compilation toolchain
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
@bolry
bolry / updateGitRepos.sh
Last active November 3, 2023 21:35
Update Git repositories available in the current directory and reset them to the status of a freshly cloned repository
#!/bin/bash
#set -o xtrace
set -o errexit
set -o nounset
set -o pipefail
IFS=$'\t\n'
unset CDPATH
for f in *
do
@bolry
bolry / example.cpp
Created November 4, 2021 09:06
Visual struct layout and padding bytes by Vittorio Romeo, gcc.godbolt.org/z/aG5dedPbn
// Pretty-printer for `struct` layout and padding bytes
// by Vittorio Romeo (@supahvee1234) (https://vittorioromeo.info)
#include <boost/pfr.hpp>
#include <iostream>
#include <tuple>
#include <utility>
#include <type_traits>
#include <typeinfo>
#include <cmath>
@bolry
bolry / constexpreif.cpp
Created November 4, 2021 06:24
Avoiding macros for your printing example
#include <utility>
#include <fmt/printf.h>
constexpr bool verboseMode{false};
constexpr bool logPrinting{false};
namespace my {
template<typename ... T>
inline void print(T &&... args) {
if constexpr(!verboseMode) {}
@bolry
bolry / reverse_if.hpp
Created December 28, 2019 23:58
reverse_if and reverseOnlyLetters
#include <algorithm>
#include <boost/iterator/filter_iterator.hpp>
template <class Iter, class Predicate>
void reverse_if(Iter first, Iter last, Predicate pred) {
std::reverse(boost::make_filter_iterator(pred, first, last),
boost::make_filter_iterator(pred, last, last));
}
#include <locale>
@bolry
bolry / singlethreadedptr.h
Created March 2, 2019 19:58
Singel Threaded Ptr from Andrei Alexandrescu talk at CppCon 2014
template<typename T>
class SingleThreadedPtr {
T *m_p;
mutable unsigned *m_c;
public:
SingleThreadedPtr();
explicit SingleThreadedPtr(T *a_p);
SingleThreadedPtr(SingleThreadedPtr const &a_rhs);
SingleThreadedPtr(SingleThreadedPtr &&a_rhs);
~SingleThreadedPtr();
@bolry
bolry / Dockerfile
Created November 7, 2018 16:27
Make a CppCheck binary for CentOS
FROM centos:7.5.1804
RUN yum -y update && yum -y install redhat-lsb
RUN yum -y install gcc-c++
RUN yum -y install cmake
WORKDIR /opt/cppcheck
ADD https://github.com/danmar/cppcheck/archive/1.85.tar.gz .
RUN tar xf 1.85.tar.gz
WORKDIR /opt/cppcheck/cppcheck-1.85/build
RUN cmake -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/opt/cppcheckresult ..
RUN make -j$(nproc)
@bolry
bolry / NoRawLoops.cpp
Created July 11, 2018 08:04
Source currently unknown
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
template<typename C>
void pr(C const&c)
{
for (auto const& e : c)
@bolry
bolry / main.cpp
Created July 11, 2018 07:24
Tricky C++ question
template<class T, int ... X>
T pi(T(X...));
#include <iostream>
void foo() { std::cout << __LINE__ << '\n'; }
void foo(int) { std::cout << __LINE__ << '\n'; }
template<typename T> void foo(T) { std::cout << __LINE__ << '\n'; }
template<> void foo(int) { std::cout << __LINE__ << '\n'; }
template<typename T>void foo(T *) { std::cout << __LINE__ << '\n'; }
@bolry
bolry / extactcmake.sh
Last active May 14, 2018 19:20
Extract new release of CMake for Linux
tar xf ~/Downloads/cmake-3.11.1-Linux-x86_64.tar.gz -C ~/.local/ --strip-components=1
or
tar --extract --directory=$HOME/.local --file=$HOME/Downloads/cmake-3.11.1-Linux-x86_64.tar.gz --strip-components=1
I.e., tar-file content like this
cmake-3.11.1-Linux-x86_64/share/cmake-3.11/completions/cpack
cmake-3.11.1-Linux-x86_64/bin/ctest
cmake-3.11.1-Linux-x86_64/bin/cmake
cmake-3.11.1-Linux-x86_64/bin/cmake-gui