Skip to content

Instantly share code, notes, and snippets.

#include <vector>
#include <iostream>
#include <numeric>
#include <string>
#include <optional>
void printStringLine(std::string s)
{
std::cout << s << '\n';
}
@ChemistAion
ChemistAion / arity.hpp
Created March 18, 2019 19:54
Aggregate arity calculations, based on: Björn Fahller and Anatoliy V. Tomilov implementations
// https://playfulprogramming.blogspot.com/2016/12/serializing-structs-with-c17-structured.html
// https://codereview.stackexchange.com/questions/142804/get-n-th-data-member-of-a-struct
// https://stackoverflow.com/questions/39768517/structured-bindings-width
// https://stackoverflow.com/questions/35463646/arity-of-aggregate-in-logarithmic-time
// https://stackoverflow.com/questions/38393302/returning-variadic-aggregates-struct-and-syntax-for-c17-variadic-template-c
#pragma once
#include <type_traits>
@diegum
diegum / bitset_iter.h
Last active May 1, 2024 22:10
Missed an iterator for C++ STL bitset? Have mine!
// bitset_iter.h v1.1.0
// Copyright 2019, Diego Dagum
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
@bwedding
bwedding / msvc17parallel.cpp
Last active October 21, 2018 19:28
Testing Parallel sorting using MSVC 17 and C++17 parallel algorithms
// Be sure to set your project to use the ISO C++17 Standard (/std:c++17) under
// C++ Language Standard in Properties... C/C++... Language...
#include <string>
#include <iostream>
#include <algorithm>
#include <execution>
#include <random>
#include <chrono>
#include <iomanip>
@johnmcfarlane
johnmcfarlane / begin(C++).md
Last active June 7, 2024 14:58
Resources for C++ beginners
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active June 12, 2024 00:42
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@ernstki
ernstki / README.md
Last active April 8, 2024 12:12
List the ABI versions of all detected libc and libstdc++'s (GNU/Linux only)

Linker error messages related to libc and libstdc++

We run into the dreaded

/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found

error messages a lot around here. This article is an attempt to explain what's going on with that.

@lefticus
lefticus / get_llvm.sh
Last active August 22, 2023 22:58
A script for building LLVM
if [ $# -gt 1 ]
then
echo "Checking out LLVM '$1' branch from svn into '`pwd`/llvm' and setting install prefix to '$2'"
echo "Press Return To Continue"
read $VAR
else
echo "Usage: $0 <branch name> <install prefix>"
exit
fi
@mbinna
mbinna / effective_modern_cmake.md
Last active June 12, 2024 00:36
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

#!/usr/bin/env bash
# --slave /usr/bin/$1 $1 /usr/bin/$1-\${version} \\
function register_clang_version {
local version=$1
local priority=$2
update-alternatives \
--install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${version} ${priority} \