diff options
author | johannst <johannst@users.noreply.github.com> | 2024-04-10 19:37:02 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2024-04-10 19:37:02 +0000 |
commit | 269caa8ae18eb33e1286e4c21d434ea07228a619 (patch) | |
tree | b9c0ae7bf44a6873adc4c9da9204de2bdf4a1de1 /print.html | |
parent | 92fc0e8e46352a593c3ce7f87292ee1c4ee4c4e4 (diff) | |
download | notes-269caa8ae18eb33e1286e4c21d434ea07228a619.tar.gz notes-269caa8ae18eb33e1286e4c21d434ea07228a619.zip |
deploy: ae498864bb638e597b589c52ff27237835625281
Diffstat (limited to 'print.html')
-rw-r--r-- | print.html | 114 |
1 files changed, 113 insertions, 1 deletions
@@ -1095,6 +1095,11 @@ list-keys -t vi-copy list keymaps for vi-copy mode | remote repository | +-------------------+ </code></pre> +<h2 id="config"><a class="header" href="#config">Config</a></h2> +<pre><code class="language-markdown"> git config --list --show-origin ..... list currently set configs and where + they are coming from + git --edit [--global] ............... open config in editor (local or global) +</code></pre> <h2 id="clean"><a class="header" href="#clean">Clean</a></h2> <pre><code class="language-markdown"> git clean -X ......... remove only ignored files (-n for dry run) git clean -f -d -x ... remove untracked & ignored files / folders @@ -4201,6 +4206,110 @@ static_assert(!is_valid<B>::value, "is false"); </blockquote> <p>A more detailed description is available in the SO discussion <a href="https://stackoverflow.com/a/27688405">How does <code>void_t</code> work</a>.</p> +<h2 id="example-concepts-since-c20"><a class="header" href="#example-concepts-since-c20">Example: Concepts since c++20</a></h2> +<pre><code class="language-cpp">// REQUIRES EXPRESSION +// requires { requirement-seq } +// requires ( parameter-list ) { requirement-seq } +// +// [1] https://en.cppreference.com/w/cpp/language/requires +// [2] https://en.cppreference.com/w/cpp/language/constraints#Constraints +// +// REQUIREMENT CLAUSE +// Not the same as a REQUIREMENT EXPRESSIONS, and is used to require +// constraints (express concept bounds). +// +// [1] https://en.cppreference.com/w/cpp/language/constraints#Requires_clauses + +// -- HELPER ------------------------------------------------------------------- + +template<typename T> +using Alias = T; + +void print(int); + +// -- CONCEPTS & REQUIRE EXPRESSIONS ------------------------------------------- + +// Simple concept from a type trait. +template<typename T, typename U> +concept Same = std::is_same<T, U>::value; + +// Simple requirement concepts. +template<typename T> +concept TraitAddAndPrint = requires(T t, int i) { + // Adding T + int must be supported. + t + i; + // Calling print(T) must be available. + print(t); +}; + +// Type requirement concepts. +template<typename T> +concept TraitTypes = requires(T t) { + // T must have a type definition inner. + typename T::inner; + // Type alias must exist. + typename Alias<T>; +}; + +// Compound requirement concepts. +template<typename T> +concept TraitFns = requires(T t, const T c) { + // void T::foo() must exist. + { t.foo() }; + // bool T::bar() const; must exist. + { c.bar() } -> Same<bool>; + // static void T::stat(); must exist. + { T::stat() } -> Same<int>; +}; + +// Nested requirement concepts. +template<typename T> +concept TraitNested = requires(T t) { + // Must satisfy other concepts. + requires TraitTypes<T>; + requires TraitFns<T>; +}; + +// -- REQUIRE EXPRESSIONS ------------------------------------------------------ + +// Require expressions can be evaluated to booleans. +template<typename T> +static constexpr bool IsTraitFns = requires { requires TraitFns<T>; }; + +// Require expressions can also be used in static assertions. +static_assert(requires { requires Same<int, int>; }); +static_assert(!requires { + typename Alias<int>; + requires Same<int, void>; +}); + +// -- TESTS -------------------------------------------------------------------- + +static_assert(requires { requires TraitAddAndPrint<int>; }); + +struct FnTypeGood { + using inner = int; +}; +struct FnTypeBad {}; +static_assert(requires { requires TraitTypes<FnTypeGood>; }); +static_assert(!requires { requires TraitTypes<FnTypeBad>; }); + +struct FnGood { + void foo(); + bool bar() const; + static int stat(); +}; +struct FnBad {}; +static_assert(requires { requires TraitFns<FnGood>; }); +static_assert(!requires { requires TraitFns<FnBad>; }); + +struct NestedGood : FnTypeGood, FnGood {}; +struct NestedBad1 : FnGood {}; +struct NestedBad2 : FnTypeGood {}; +static_assert(requires { requires TraitNested<NestedGood>; }); +static_assert(!requires { requires TraitNested<NestedBad1>; }); +static_assert(!requires { requires TraitNested<NestedBad2>; }); +</code></pre> <h2 id="template-selection-with-partially--fully-specializations"><a class="header" href="#template-selection-with-partially--fully-specializations">Template selection with partially / fully specializations.</a></h2> <pre><code class="language-cpp">enum Kind { kPrimary, @@ -4274,7 +4383,7 @@ int main() { // * No specialization matches, take the primary template. } </code></pre> -<h1 id="example-perfect-forwarding"><a class="header" href="#example-perfect-forwarding">Example: Perfect forwarding</a></h1> +<h2 id="example-perfect-forwarding"><a class="header" href="#example-perfect-forwarding">Example: Perfect forwarding</a></h2> <pre><code class="language-cpp">#include <cassert> #include <cstdio> #include <new> @@ -4921,6 +5030,9 @@ symbol=default_main; lookup in file=/usr/lib/libc.so.6 [0] symbol=default_main; lookup in file=/lib64/ld-linux-x86-64.so.2 [0] ./main: error: symbol lookup error: undefined symbol: default_main (fatal) </code></pre> +<h2 id="load-lib-with-same-name-from-different-locations"><a class="header" href="#load-lib-with-same-name-from-different-locations">Load lib with same name from different locations</a></h2> +<p>The sources in <a href="https://github.com/johannst/notes/tree/master/src/development/ldso/samename">ldso/samename</a> show some experiments, loading the +libs with the same name but potentially from different locations (paths).</p> <h2 id="dynamic-linking-x86_64"><a class="header" href="#dynamic-linking-x86_64">Dynamic Linking (x86_64)</a></h2> <p>Dynamic linking basically works via one indirect jump. It uses a combination of function trampolines (<code>.plt</code> section) and a function pointer table (<code>.got.plt</code> |