-
ghr
Type restoring without heap memory allocation (Fastest)
struct DelegateList { int f1(double d) { } int f2(double d) { } }; typedef int (DelegateList::* DelegateType)(double d); DelegateType d = &DelegateList::f1; DelegateList list; int a = (list.*d)(3.14);
Reference
https://www.codeproject.com/Articles/13287/Fast-C-Delegate
https://stackoverflow.com/questions/9568150/what-is-a-c-delegate
http://www.codeproject.com/Articles/7150/Member-Function-Pointers-and-the-Fastest-Possible
http://www.codeproject.com/Articles/11015/The-Impossibly-Fast-C-Delegates
http://www.codeproject.com/Articles/13287/Fast-C-Delegate -
ghr
// lvalues: // int i = 42; i = 43; // ok, i is an lvalue int* p = &i; // ok, i is an lvalue int& foo(); foo() = 42; // ok, foo() is an lvalue int* p1 = &foo(); // ok, foo() is an lvalue // rvalues: // int foobar(); int j = 0; j = foobar(); // ok, foobar() is an rvalue int* p2 = &foobar(); // error, cannot take the address of an rvalue j = 42; // ok, 42 is an rvalue
http://thbecker.net/articles/rvalue_references/section_01.html
-
ghr
Prevent multiple definitions in header files
When there definitions in a header file that can not be made twice, the code below should be used. A header file may be included twice other include files include it, or an included file includes it and the source file includes it again.
To prevent bad effects from a double include, it is common to surround the body in the include file with the following (where MYHEADER_H is replaced by a name that is appropriate for your program).
#ifndef MYHEADER_H #define MYHEADER_H // This will be seen by the compiler only once #endif /* MYHEADER_H */
http://www.fredosaurus.com/notes-cpp/preprocessor/ifdef.html
-
ghr
Log Levels
TRACE
- during development, comment before commit to vcsDEBUG
- run in local machineINFO
- log all actions by user, system scheduled eventWARN
- potential errorERROR
- error conditionsFATAL
- critical errors
-
ghr
Pointers are more powerful than references in the sense that they allow two things that references don’t: nullability and rebinding.
Summary
References
cannot be null and cannot rebindstd::reference_wrapper
cannot be null but can rebindPointers
can be null and can rebind (and can do low-level address manipulations)boost optional references
can be null and can rebind (but are incompatible with std::optional)
https://www.fluentcpp.com/2018/10/02/pointers-references-optional-references-cpp/
-
ghr
Examples (TL;DR)
Find files containing "foo", and print the line matches in context:
ag foo
Find files containing "foo" in a specific directory:
ag foo path/to/directory
Find files containing "foo", but only list the filenames:
ag -l foo
Find files containing "FOO" case-insensitively, and print only the match, rather than the whole line:
ag -i -o FOO
Find "foo" in files with a name matching "bar"
ag foo -G bar
Find files whose contents match a regular expression:
ag '^ba(r|z)$'
Find files with a name matching "foo":
ag -g foo
-
ghr
My favourite theme:
clean
https://ohmyz.sh/
https://www.howtoforge.com/tutorial/how-to-setup-zsh-and-oh-my-zsh-on-linux/