Skip to content

Instantly share code, notes, and snippets.

View flomnes's full-sized avatar
🏠
Working from home

Florian Omnès flomnes

🏠
Working from home
View GitHub Profile
@flomnes
flomnes / hashable.cpp
Created September 24, 2024 17:26
hashable factorization
#include <string>
#include <utility>
class Hashable
{
public:
Hashable(const std::string& s1, const std::string& s2):
s1(s1),
s2(s2)
{
@flomnes
flomnes / simplification.cpp
Last active September 4, 2024 16:56
AST Simplification
#include <optional>
#include <string>
#include <utility>
class Node
{
public:
virtual ~Node() = default;
};
@flomnes
flomnes / default operator.cpp
Created August 26, 2024 13:49
Default operator error
class EmptyClass
{
virtual ~EmptyClass() = default;
};
class DerivedFromEmpty: public EmptyClass
{
bool operator==(const DerivedFromEmpty&) const = default;
};
@flomnes
flomnes / exception_visitor.cpp
Created August 23, 2024 13:26
Exception throw in visitors
#include <stdexcept>
class IName
{
public:
virtual const std::string& name() const = 0;
};
class EqualNode: public IName
@flomnes
flomnes / enumclass.cpp
Created August 20, 2024 13:33
Operator overloading with enum class
#include <cassert>
enum class C
{
LINEAR,
NON_LINEAR,
CONSTANT
};
C operator+(C x, C y)
@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;
}