Skip to content

Instantly share code, notes, and snippets.

@flomnes
flomnes / mutex-null-pattern.cpp
Last active August 20, 2024 11:37
Injected mutex & null pattern
#include <cassert>
#include <mutex>
#include <vector>
class IMutex
{
public:
virtual void lock() = 0;
virtual void unlock() noexcept = 0;
};
@flomnes
flomnes / getNumberOfCores.cpp
Created July 25, 2024 08:20
Legacy vs. New number of cores
#include <string>
#include <map>
#include <cmath>
using uint = unsigned int;
std::map<std::string, uint> getRawNumberCoresPerLevel(uint nbLogicalCores)
{
std::map<std::string, uint> table;
@flomnes
flomnes / set.cpp
Created July 10, 2024 14:24
Using a std::set with a custom comparator + typeid
#include <iostream>
class Poly
{
public:
virtual std::string name() const = 0;
virtual ~Poly() = default;
};
class Impl1 : public Poly
@flomnes
flomnes / watched-constraint.cpp
Created July 9, 2024 09:03
Infeasible constraint
class WatchedConstraint
{
public:
WatchedConstraint(std::string name, std::string regexID, std::string infeasibility, std::string infeasibilityCause) :
name(name),
regexID(regexID),
infeasibility(infeasibility),
infeasibilityCause(infeasibilityCause) {
}
std::string formattedInfeasibility(std::string constraintName) const {
@flomnes
flomnes / map.cpp
Last active February 21, 2023 08:59
Change a map by reference, not by value
#include <iostream>
#include <map>
int main() {
std::map<int, int> m;
auto display_m = [&m](const char *msg) {
std::cout << msg << " ";
for (auto [k, v] : m) {
std::cout << "m[" << k << "] = " << v << std::endl;
}
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <vector>
// GOAL : benchmark containers for these 2 operations
// - Insert a pair of ints into the container
#include <stdio.h>
#include <math.h>
double f(double x, int* nbeval) {
(*nbeval)++;
return 1/(1+x*x);
// replace with 1/(1+x) to obtain log(2) !
}
double intg(double a,double b, double eps, int* nbeval) {