logic_error | generic error in condition or invariant |
invalid_argument | argument invalid |
domain_error | argument domain error |
length_error | argument of excessive size |
out_of_range | argument outside expected range |
runtime_error | errors in the runtime context |
range_error | computational range errors |
overflow_error | arithmetic overflows |
underflow_error | arithmetic underflows |
operator signatures
assignment | R &operator=(L l) {} |
arithmetic | R operator+(L l) const {} R operator-(L l) const {} R operator*(L l) const {} R operator/(L l) const {} R operator%(L l) const {} |
compound arithmetic | R &operator+=(L l) {} R &operator-=(L l) {} R &operator*=(L l) {} R &operator/=(L l) {} R &operator%=(L l) {} |
incremental | R &operator++() {} R &operator++(int) {} R &operator--() {} R &operator--(int) {} |
logical | R operator!() const {} R operator&&(L l) const {} R operator||(L l) const {} |
bitwise | R operator~() const {} R operator&(L l) const {} R operator|(L l) const {} R operator^(L l) const {} |
compound bitwise | R &operator&=(L l) {} R &operator|=(L l) {} R &operator^=(L l) {} |
shift | R operator<<(L l) const {} R operator>>(L l) const {} |
compound shift | R &operator<<=(L l) {} R &operator>>=(L l) {} |
comparison | R operator==(L const &l) const {} R operator!=(L const &l) const {} R operator<(L const &l) const {} R operator>(L const &l) const {} R operator<=(L const &l) const {} R operator>=(L const &l) const {} |
subscript | R &operator[](L l) {} |
indirection | R &operator*(L l) {} |
address of | R *operator&(L l) {} |
dereference | R *operator->(L l) {} R &operator->*(L l) {} |
comma | R operator,(L l) {} |
self embedded script
#ifdef _SCRIPT
filename=$0; set -x; g++ -std=c++20 -O2 -o ${filename%%.*} ${filename}; exit
#endif
makefile template
CPPFLAGS = -O2 @gcc.conf -MMD -MP
LDFLAGS = -O2
%.elf: %.o
$(CXX) $(LDFLAGS) -o $@ $^ && ln -sf $@ $*
-include *.d
error checking gcc configuration
-std=c++20
-Wall
-Wextra
logging to a debug file
#include <fstream>
static std::ofstream debug("debug.log");
⋮
debug << "test" << std::endl;
timing an operation
#include <chrono>
auto t_start = std::chrono::high_resolution_clock::now();
⋮
auto t_elapsed = std::chrono::high_resolution_clock::now() - t_start;
… << elapsed.count()/1e9 …
process lines in text file
#include <string>
using std::string, std::getline;
#include <iostream>
using std::cin;
⋮
for (string text; getline(cin, text);)
{
// process text
}