Meeting 30 May 2019
What was your latest discovery about C++?
https://www.reddit.com/r/cpp/comments/blu0a4/what_was_your_latest_discovery_about_c/
void fn() { https://www.google.com cout << "Everything is fine.\n" }
- Using template to disambiguate dependent names | CppReference | SO
- Type covariance for virtual functions
- Switch statement discoveries
- Function-level try/catch
- delete this
- Fun with nested classes
- Unique object address
- A class can have a static member of incomplete class type
- Namespaces can recursively refer to themselves
- C++ is popular
- The "arrow operator"
int x = 10; while (x --> 0) // x goes to 0 { printf("%d ", x); }
- Non-void function surprises
- Alternative tokens
- Void functions can return result of other void function
- CRTP
- Unary plus to force a lambda-to-function-pointer conversion
+[]{}
For every type T the unary operator+(T*) is considered to exist which returns the given pointer as is. Here, T is not restricted to object types but includes function types. A lambda object that didn't capture anything has a conversion operator to a function pointer. The unary + triggers this conversion.
Initialisation in C++17 – the matrix
C++ Weekly - Ep 144 - Pure Functions in C++
https://www.reddit.com/r/cpp/comments/a2qzsv/c_weekly_ep_144_pure_functions_in_c/
int square(int value) __attribute__((pure)); [[gnu::pure]] int square2(int value); [[gnu::const]] int square3(int value);
C++ Logging Libraries
https://www.reddit.com/r/cpp/comments/a3gp0s/best_logging_libraries/
- Spdlog https://github.com/gabime/spdlog
- Loguru https://github.com/emilk/loguru
- EasyLogging https://github.com/zuhd-org/easyloggingpp
- Plog https://github.com/SergiusTheBest/plog
- Google Log https://github.com/google/glog
- P7 http://baical.net/p7.html
sol3 is Released
https://thephd.github.io/sol3-released
https://sol2.readthedocs.io/en/latest/
https://www.reddit.com/r/cpp/comments/bs0piq/sol3_a_modern_luac_binding_is_released/
Exhaustive and Composable Error Handling in C++
TL;DR: You can emulate OCaml polymorphic sum type error handling in C++17.
class AST; struct SyntaxError {int line; int column;}; struct GrammarError {int line; int column; std::string explanation;}; auto parse(std::string input) -> Result<AST, SyntaxError, GrammarError>; struct LengthError {int length;}; struct HeightError {int height;}; auto validate(AST ast) -> Result<AST, LengthError, HeightError>; struct DisplayError {std::string explanation;}; auto display(AST ast) -> void;
auto result = parse(my_input) .then(validate) .then(display); Switch(result) .Case<SyntaxError>([](auto err){ report_error("Invalid syntax at line", e.line, ":", e.column);}) .Case<GrammarError>([](auto err){ report_error(e.explanation, "at ", e.line, ":", e.column);}) .Case<LengthError>([](auto err){ report_errror("illegal length: ", e.length);}) .Case<DisplayError>([](auto err){ report_error(e.explanation);}) | ESAC; // Triggers static_assert as HeightError is unhandled
Having fun in life!
Quote
Elizabeth Zwicky:
The only thing more frightening than a programmer with a screwdriver or a hardware engineer with a program is a user with a pair of wire cutters and the root password.