Skip to content

Instantly share code, notes, and snippets.

@andijcr
andijcr / README.md
Last active December 15, 2022 13:07
const ref parameter that rejects termporaries
@andijcr
andijcr / hello.ast
Created March 11, 2022 09:31
to view the ast for this snippet: clang++ -Xclang -ast-dump -fsyntax-only hello.cpp
|-TypedefDecl 0x154f310 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x154efb0 '__int128'
|-TypedefDecl 0x154f380 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x154efd0 'unsigned __int128'
|-TypedefDecl 0x154f6f8 <<invalid sloc>> <invalid sloc> implicit __NSConstantString '__NSConstantString_tag'
| `-RecordType 0x154f470 '__NSConstantString_tag'
| `-CXXRecord 0x154f3d8 '__NSConstantString_tag'
|-TypedefDecl 0x154f790 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'
| `-PointerType 0x154f750 'char *'
| `-BuiltinType 0x154eab0 'char'
@andijcr
andijcr / Makefile
Created March 8, 2022 16:47
gcc 11 module example
all: hello
gcm.cache:
g++ -std=c++20 -fmodules-ts -xc++-system-header iostream
helloworld.o: helloworld.cxx gcm.cache
g++ -std=c++20 -fmodules-ts -c helloworld.cxx -o helloworld.o
hello: helloworld.o
g++ -std=c++20 -fmodules-ts main.cpp helloworld.o -o hello
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
@andijcr
andijcr / is_t_or_fn.hpp
Created August 8, 2019 13:51
c++: detecting if a type is a T or a function returning T (here demostrated with std::pair)
#include <type_traits>
#include <tuple>
template <typename T> struct is_pair : public std::false_type {};
template <typename T1, typename T2>
struct is_pair<std::pair<T1, T2>> : public std::true_type {};
template <typename T> constexpr auto is_pair_v = is_pair<T>::value;
template <typename T, typename = std::void_t<>>
@andijcr
andijcr / trim.cpp
Created April 3, 2019 11:54
simple in-place trim functions, copied from somewhere
// trim from start (in place)
void ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
[](int ch) { return !std::isspace(ch); }));
}
// trim from end (in place)
void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(),
[](int ch) { return !std::isspace(ch); })
@andijcr
andijcr / lazy_proxy.h
Last active March 7, 2019 08:48
lazy_loading::DelayProxy : an approach to delay the creation of an object while still permitting to code with it
#include <functional>
#include <memory>
#include <optional>
#include <type_traits>
#include <utility>
namespace lazy {
template <typename T> class DelayProxy {
std::unique_ptr<T> subject{};
@andijcr
andijcr / date_parse.c++
Created January 3, 2019 10:14
quick and dirty and not safe date parsing function, lacks a input sanitizer
#include <string_view>
#include <cstdlib>
#include <ctime>
#include <tuple>
auto str_date = "02/03/88 00:54:56+04";
using namespace std;
auto parse_time(string_view str_date) -> pair<tm, int>{
auto next_token = [=, token_pos=0](auto delimiter, bool consume_delimiter = true) mutable{
token_pos = str_date.find(delimiter, token_pos) + consume_delimiter? 1: 0;
# chi sono
[contatti]
ciao sono andrea, lavoro qui a 2hire come sviluppatore embedded e smontacose.
Visto che chi non sa fare insegna, oggi voglio parlarvi di entity component system e perché penso sia veramente bello
e perché non l'ho mai usato
# survey
vedo un po' di facce conosciute.
quanti di voi sono programmatori puri?
quanti sono programmatori per necessità di videogioco?