Something went wrong. Try again.
C++ Standard Template Library browser.
Something went wrong. Try again.
3.3 kB · 141 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142/* ======================================================================== * * Filename: prelude.hpp * Description: C++ sensible prelude - Declarations * Author: Diego A. Estrada Rivera * Version: 0.0.4 * * ======================================================================== */#pragma once
/* === Generic includes === */#include <list>
#include <queue>#include <span>#include <stack>#include <unordered_map>#include <unordered_set>
#include <algorithm>#include <numeric>#include <ranges>
#include <format>#include <fstream>
/* === Numeric Types === */#include <cstdint>#include <limits.h>using Size = std::size_t;
/* Floating Point */// brain floating point// see https://en.wikipedia.org/wiki/Bfloat16_floating-point_formattypedef __bf16 BF16;typedef _Float16 F16;typedef float F32;static_assert(sizeof(F32) * CHAR_BIT == 32); //typedef double F64;static_assert(sizeof(F64) * CHAR_BIT == 64);#if __float80_max < __float128_maxtypedef __float80 F80; // sometimes is the same as F128#endiftypedef __float128 F128;
// decimal floating points// see decimal32/64/128 in https://en.wikipedia.org/wiki/IEEE_754#if 0typedef float __attribute__((mode(SD))) D32;typedef float __attribute__((mode(DD))) D64;typedef float __attribute__((mode(TD))) D128;#endif
/* Integer */typedef uint8_t U8;typedef uint16_t U16;typedef uint32_t U32;typedef uint64_t U64;typedef __uint128_t U128;
typedef int8_t I8;typedef int16_t I16;typedef int32_t I32;typedef int64_t I64;typedef __int128_t I128;
// generic Integer typetypedef int_fast32_t Int;
/* === Other Types === */typedef bool Bool;typedef char Char;typedef const char* CString;
#include <vector>template <typename T> using Vector = std::vector<T>;
#include <string>using String = std::string;using namespace std::string_literals;
namespace ra = std::ranges;namespace vi = std::ranges::views;
// Unit typeenum class Unit { unit };
// Void typeenum class Void {};
// Pointer typestemplate <typename T> using Ref = T&;
template <typename T> using Handle = T*;
/* === Keywords === */#define let auto const#define var auto#define fn [[nodiscard, gnu::const]] auto#define proc [[nodiscard]] auto
/* This is included as a static member variable of <tuple>. * However, there is no way to bring the std::ignore namespace static variable * into the current scope. This is a way to do that. * https://en.cppreference.com/w/cpp/utility/tuple/ignore */namespace detail {struct ignore_t { template <typename T> constexpr // required since C++14 void operator=(T&&) const noexcept { }};} // namespace detailinline constinit const detail::ignore_t ignore; // changed to constinit
// manage tuples better#define fst std::get<0>#define snd std::get<1>#define thr std::get<2>
/* === Miscellaneous Functions */template <class D, class C> fn memoize(let& op) noexcept{ static var mp = std::unordered_map<D, C>(); return [=](D const& x) noexcept { return mp.contains(x) ? mp.at(x) : mp[x] = op(x); };}
/* Sensible IO */#include <iostream>proc getLine() noexcept -> String;
proc getChar() noexcept -> Char;
proc print(const std::string_view& f) noexcept -> Unit;
proc println(const std::string_view& f) noexcept -> Unit;