aboutsummaryrefslogtreecommitdiffhomepage
path: root/development
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2023-04-12 20:57:45 +0000
committerjohannst <johannst@users.noreply.github.com>2023-04-12 20:57:45 +0000
commit4b3a334cf553b9f0b7f831538cb4d23fbdb0594f (patch)
tree3a8e4df94497b437656454bc29e522b56f9765cb /development
parent3f1d25c3e62f91f2555f0649c7c71f3b730717be (diff)
downloadnotes-4b3a334cf553b9f0b7f831538cb4d23fbdb0594f.tar.gz
notes-4b3a334cf553b9f0b7f831538cb4d23fbdb0594f.zip
deploy: d6deac54dd372c946942637636846893694ce521
Diffstat (limited to 'development')
-rw-r--r--development/c++.html129
-rw-r--r--development/c++/Makefile5
-rw-r--r--development/c++/concepts-11.cc3
-rw-r--r--development/c++/tmpl-pair.cc73
-rw-r--r--development/c++/tmpl-void_t.cc47
-rw-r--r--development/c++filt.html6
-rw-r--r--development/gcc.html6
-rw-r--r--development/glibc.html6
-rw-r--r--development/index.html6
-rw-r--r--development/ld.so.html6
-rw-r--r--development/make.html6
-rw-r--r--development/python.html6
-rw-r--r--development/symbolver.html6
13 files changed, 286 insertions, 19 deletions
diff --git a/development/c++.html b/development/c++.html
index c8ed843..811aa7d 100644
--- a/development/c++.html
+++ b/development/c++.html
@@ -32,6 +32,7 @@
</head>
<body>
+ <div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
@@ -69,10 +70,12 @@
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var html = document.querySelector('html');
- var sidebar = 'hidden';
+ var sidebar = null;
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
+ } else {
+ sidebar = 'hidden';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
@@ -446,8 +449,7 @@ struct is_entry {
template&lt;typename TT&gt;
using val = decltype(std::declval&lt;TT&gt;().val());
- static constexpr bool value = is_valid_v&lt;T, init&gt; &amp;&amp;
- is_valid_with_ret_v&lt;T, int, tag&gt; &amp;&amp;
+ static constexpr bool value = is_valid_v&lt;T, init&gt; &amp;&amp; is_valid_with_ret_v&lt;T, int, tag&gt; &amp;&amp;
is_valid_with_ret_v&lt;T, typename T::Type, val&gt;;
};
@@ -470,18 +472,128 @@ int main() {
of the <code>decltype(std:declval&lt;T&gt;...</code> expressions is ill-formed, the template
specialization for <code>is_valid</code> will be removed from the candidate set due to
<a href="https://en.cppreference.com/w/cpp/language/sfinae">SFINAE</a>.</p>
-<pre><code class="language-cpp">template&lt;typename T, typename = void&gt;
+<pre><code class="language-cpp">#include &lt;type_traits&gt;
+
+// (1) Primary template.
+template&lt;typename T, typename = void&gt;
struct is_valid : std::false_type {};
+// (2) Partial template specialization.
template&lt;typename T&gt;
-struct is_valid&lt;T, std::void_t&lt;
- decltype(std::declval&lt;T&gt;().some_fun1()),
- decltype(std::declval&lt;T&gt;().some_fun2())
- &gt;&gt; : std::true_type {};
+struct is_valid&lt;T, std::void_t&lt;decltype(std::declval&lt;T&gt;().some_fun1()),
+ decltype(std::declval&lt;T&gt;().some_fun2())&gt;&gt; : std::true_type {};
+struct A {
+ void some_fun1() {}
+ void some_fun2() {}
+};
+
+struct B {};
+
+static_assert(is_valid&lt;A&gt;::value, &quot;is true&quot;);
+// * Compare template arg list with primary template, we only supplied one
+// arg, the second one will be defaulted as
+// is_valid&lt;A, void&gt;
+// * Compare template arg list against available specializations, this will
+// try to match the pattern &lt;A, void&gt; against the patterns defined in the
+// partial specializations.
+// * Try specialization (2)
+// * T -&gt; A
+// * Evaluate std::void_t -&gt; decltype's are well-formed
+// std::void_t&lt;...&gt; -&gt; void
+// * Specialization (2) matches &lt;A, void&gt;
+// * Pick the most specialized version -&gt; (2)
+
+static_assert(!is_valid&lt;B&gt;::value, &quot;is false&quot;);
+// * Compare template arg list with primary template, we only supplied one
+// arg, the second one will be defaulted as
+// is_valid&lt;A, void&gt;
+// * Compare template arg list against available specializations, this will
+// try to match the pattern &lt;B, void&gt; against the patterns defined in the
+// partial specializations.
+// * Try specialization (2)
+// * T -&gt; B
+// * Evaluate std::void_t -&gt; decltype's are ill-formed
+// * Specialization (2) is removed from candidate set, no hard error (SFINAE)
+// * No specialization matches, take the primary template.
</code></pre>
<blockquote>
<p><code>std::declval&lt;T&gt;()</code> creates an instance of type T in an unevaluated context.</p>
</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="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,
+ kTT,
+ kIntBool,
+ kIntInt,
+};
+
+// (1) Primary template.
+template&lt;typename T, typename U = bool&gt;
+struct pair {
+ static constexpr Kind kind = kPrimary;
+};
+
+// (2) Partial template specialization.
+template&lt;typename T&gt;
+struct pair&lt;T, T&gt; {
+ static constexpr Kind kind = kTT;
+};
+
+// (3) Template specialization.
+template&lt;&gt;
+struct pair&lt;int, bool&gt; {
+ static constexpr Kind kind = kIntBool;
+};
+
+// (4) Template specialization.
+template&lt;&gt;
+struct pair&lt;int, int&gt; {
+ static constexpr Kind kind = kIntInt;
+};
+
+int main() {
+ static_assert(pair&lt;int&gt;::kind == kIntBool, &quot;&quot;);
+ // * Compare template arg list with primary template, we only supplied one
+ // arg, the second one will be defaulted as
+ // pair&lt;int, bool&gt;
+ // * Compare template arg list against available specializations, this will
+ // try to match the pattern &lt;int, bool&gt; against the patterns defined in the
+ // partial specializations.
+ // * (2) &lt;int, bool&gt; pattern does not match
+ // * (3) &lt;int, bool&gt; pattern does match
+ // * (4) &lt;int, bool&gt; pattern does not match
+ // * Pick the most specialized version -&gt; (3)
+
+ static_assert(pair&lt;char, char&gt;::kind == kTT, &quot;&quot;);
+ // * Compare template arg list against available specializations, this will
+ // try to match the pattern &lt;char, char&gt; against the patterns defined in the
+ // partial specializations.
+ // * (2) &lt;char, char&gt; pattern does match
+ // * (3) &lt;char, char&gt; pattern does not match
+ // * (4) &lt;char, char&gt; pattern does not match
+ // * Pick the most specialized version -&gt; (2)
+
+ static_assert(pair&lt;int, int&gt;::kind == kIntInt, &quot;&quot;);
+ // * Compare template arg list against available specializations, this will
+ // try to match the pattern &lt;int, int&gt; against the patterns defined in the
+ // partial specializations.
+ // * (2) &lt;int, int&gt; pattern does match
+ // * (3) &lt;int, int&gt; pattern does match
+ // * (4) &lt;int, int&gt; pattern does not match
+ // * Pick the most specialized version -&gt; (3)
+
+ static_assert(pair&lt;char, short&gt;::kind == kPrimary, &quot;&quot;);
+ // * Compare template arg list against available specializations, this will
+ // try to match the pattern &lt;char, short&gt; against the patterns defined in the
+ // partial specializations.
+ // * (2) &lt;char, short&gt; pattern does not match
+ // * (3) &lt;char, short&gt; pattern does not match
+ // * (4) &lt;char, short&gt; pattern does not match
+ // * No specialization matches, take the primary template.
+}
+</code></pre>
</main>
@@ -531,5 +643,6 @@ struct is_valid&lt;T, std::void_t&lt;
<!-- Custom JS scripts -->
+ </div>
</body>
</html>
diff --git a/development/c++/Makefile b/development/c++/Makefile
index 610b5a2..ca752d9 100644
--- a/development/c++/Makefile
+++ b/development/c++/Makefile
@@ -1,4 +1,4 @@
-SRC = concepts-11.cc meta.cc meta2.cc meta4.cc
+SRC = concepts-11.cc meta.cc meta2.cc meta4.cc tmpl-pair.cc tmpl-void_t.cc
BIN = $(SRC:.cc=)
all: $(BIN)
@@ -6,5 +6,8 @@ all: $(BIN)
%: %.cc
$(CXX) -o $* $^ -std=c++17 -g -fsanitize=address -fsanitize=undefined -fsanitize=leak
+fmt:
+ clang-format -i $(SRC)
+
clean:
$(RM) $(BIN)
diff --git a/development/c++/concepts-11.cc b/development/c++/concepts-11.cc
index 888ff4d..cec8716 100644
--- a/development/c++/concepts-11.cc
+++ b/development/c++/concepts-11.cc
@@ -32,8 +32,7 @@ struct is_entry {
template<typename TT>
using val = decltype(std::declval<TT>().val());
- static constexpr bool value = is_valid_v<T, init> &&
- is_valid_with_ret_v<T, int, tag> &&
+ static constexpr bool value = is_valid_v<T, init> && is_valid_with_ret_v<T, int, tag> &&
is_valid_with_ret_v<T, typename T::Type, val>;
};
diff --git a/development/c++/tmpl-pair.cc b/development/c++/tmpl-pair.cc
new file mode 100644
index 0000000..a8acaed
--- /dev/null
+++ b/development/c++/tmpl-pair.cc
@@ -0,0 +1,73 @@
+// Copyright (C) 2023 johannst
+
+enum Kind {
+ kPrimary,
+ kTT,
+ kIntBool,
+ kIntInt,
+};
+
+// (1) Primary template.
+template<typename T, typename U = bool>
+struct pair {
+ static constexpr Kind kind = kPrimary;
+};
+
+// (2) Partial template specialization.
+template<typename T>
+struct pair<T, T> {
+ static constexpr Kind kind = kTT;
+};
+
+// (3) Template specialization.
+template<>
+struct pair<int, bool> {
+ static constexpr Kind kind = kIntBool;
+};
+
+// (4) Template specialization.
+template<>
+struct pair<int, int> {
+ static constexpr Kind kind = kIntInt;
+};
+
+int main() {
+ static_assert(pair<int>::kind == kIntBool, "");
+ // * Compare template arg list with primary template, we only supplied one
+ // arg, the second one will be defaulted as
+ // pair<int, bool>
+ // * Compare template arg list against available specializations, this will
+ // try to match the pattern <int, bool> against the patterns defined in the
+ // partial specializations.
+ // * (2) <int, bool> pattern does not match
+ // * (3) <int, bool> pattern does match
+ // * (4) <int, bool> pattern does not match
+ // * Pick the most specialized version -> (3)
+
+ static_assert(pair<char, char>::kind == kTT, "");
+ // * Compare template arg list against available specializations, this will
+ // try to match the pattern <char, char> against the patterns defined in the
+ // partial specializations.
+ // * (2) <char, char> pattern does match
+ // * (3) <char, char> pattern does not match
+ // * (4) <char, char> pattern does not match
+ // * Pick the most specialized version -> (2)
+
+ static_assert(pair<int, int>::kind == kIntInt, "");
+ // * Compare template arg list against available specializations, this will
+ // try to match the pattern <int, int> against the patterns defined in the
+ // partial specializations.
+ // * (2) <int, int> pattern does match
+ // * (3) <int, int> pattern does match
+ // * (4) <int, int> pattern does not match
+ // * Pick the most specialized version -> (3)
+
+ static_assert(pair<char, short>::kind == kPrimary, "");
+ // * Compare template arg list against available specializations, this will
+ // try to match the pattern <char, short> against the patterns defined in the
+ // partial specializations.
+ // * (2) <char, short> pattern does not match
+ // * (3) <char, short> pattern does not match
+ // * (4) <char, short> pattern does not match
+ // * No specialization matches, take the primary template.
+}
diff --git a/development/c++/tmpl-void_t.cc b/development/c++/tmpl-void_t.cc
new file mode 100644
index 0000000..fd95315
--- /dev/null
+++ b/development/c++/tmpl-void_t.cc
@@ -0,0 +1,47 @@
+// Copyright (C) 2023 johannst
+
+#include <type_traits>
+
+// (1) Primary template.
+template<typename T, typename = void>
+struct is_valid : std::false_type {};
+
+// (2) Partial template specialization.
+template<typename T>
+struct is_valid<T, std::void_t<decltype(std::declval<T>().some_fun1()),
+ decltype(std::declval<T>().some_fun2())>> : std::true_type {};
+struct A {
+ void some_fun1() {}
+ void some_fun2() {}
+};
+
+struct B {};
+
+static_assert(is_valid<A>::value, "is true");
+// * Compare template arg list with primary template, we only supplied one
+// arg, the second one will be defaulted as
+// is_valid<A, void>
+// * Compare template arg list against available specializations, this will
+// try to match the pattern <A, void> against the patterns defined in the
+// partial specializations.
+// * Try specialization (2)
+// * T -> A
+// * Evaluate std::void_t -> decltype's are well-formed
+// std::void_t<...> -> void
+// * Specialization (2) matches <A, void>
+// * Pick the most specialized version -> (2)
+
+static_assert(!is_valid<B>::value, "is false");
+// * Compare template arg list with primary template, we only supplied one
+// arg, the second one will be defaulted as
+// is_valid<A, void>
+// * Compare template arg list against available specializations, this will
+// try to match the pattern <B, void> against the patterns defined in the
+// partial specializations.
+// * Try specialization (2)
+// * T -> B
+// * Evaluate std::void_t -> decltype's are ill-formed
+// * Specialization (2) is removed from candidate set, no hard error (SFINAE)
+// * No specialization matches, take the primary template.
+
+int main() {}
diff --git a/development/c++filt.html b/development/c++filt.html
index cf26ce8..c9c486f 100644
--- a/development/c++filt.html
+++ b/development/c++filt.html
@@ -32,6 +32,7 @@
</head>
<body>
+ <div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
@@ -69,10 +70,12 @@
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var html = document.querySelector('html');
- var sidebar = 'hidden';
+ var sidebar = null;
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
+ } else {
+ sidebar = 'hidden';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
@@ -201,5 +204,6 @@
<!-- Custom JS scripts -->
+ </div>
</body>
</html>
diff --git a/development/gcc.html b/development/gcc.html
index 9ddb112..170c5e0 100644
--- a/development/gcc.html
+++ b/development/gcc.html
@@ -32,6 +32,7 @@
</head>
<body>
+ <div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
@@ -69,10 +70,12 @@
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var html = document.querySelector('html');
- var sidebar = 'hidden';
+ var sidebar = null;
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
+ } else {
+ sidebar = 'hidden';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
@@ -259,5 +262,6 @@ run1:
<!-- Custom JS scripts -->
+ </div>
</body>
</html>
diff --git a/development/glibc.html b/development/glibc.html
index b16240c..7f0f10b 100644
--- a/development/glibc.html
+++ b/development/glibc.html
@@ -32,6 +32,7 @@
</head>
<body>
+ <div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
@@ -69,10 +70,12 @@
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var html = document.querySelector('html');
- var sidebar = 'hidden';
+ var sidebar = null;
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
+ } else {
+ sidebar = 'hidden';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
@@ -223,5 +226,6 @@ LD_PRELOAD=./libmtrace.so &lt;binary&gt;
<!-- Custom JS scripts -->
+ </div>
</body>
</html>
diff --git a/development/index.html b/development/index.html
index 5529df6..8b220d5 100644
--- a/development/index.html
+++ b/development/index.html
@@ -32,6 +32,7 @@
</head>
<body>
+ <div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
@@ -69,10 +70,12 @@
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var html = document.querySelector('html');
- var sidebar = 'hidden';
+ var sidebar = null;
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
+ } else {
+ sidebar = 'hidden';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
@@ -204,5 +207,6 @@
<!-- Custom JS scripts -->
+ </div>
</body>
</html>
diff --git a/development/ld.so.html b/development/ld.so.html
index e720486..afe0dee 100644
--- a/development/ld.so.html
+++ b/development/ld.so.html
@@ -32,6 +32,7 @@
</head>
<body>
+ <div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
@@ -69,10 +70,12 @@
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var html = document.querySelector('html');
- var sidebar = 'hidden';
+ var sidebar = null;
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
+ } else {
+ sidebar = 'hidden';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
@@ -304,5 +307,6 @@ As we can see the offset from relocation at index <code>0</code> points to <code
<!-- Custom JS scripts -->
+ </div>
</body>
</html>
diff --git a/development/make.html b/development/make.html
index 36b115e..bb004a2 100644
--- a/development/make.html
+++ b/development/make.html
@@ -32,6 +32,7 @@
</head>
<body>
+ <div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
@@ -69,10 +70,12 @@
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var html = document.querySelector('html');
- var sidebar = 'hidden';
+ var sidebar = null;
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
+ } else {
+ sidebar = 'hidden';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
@@ -288,5 +291,6 @@ $(realpath fname1 fname2 ..)
<!-- Custom JS scripts -->
+ </div>
</body>
</html>
diff --git a/development/python.html b/development/python.html
index 7f4bf73..8b0c3ce 100644
--- a/development/python.html
+++ b/development/python.html
@@ -32,6 +32,7 @@
</head>
<body>
+ <div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
@@ -69,10 +70,12 @@
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var html = document.querySelector('html');
- var sidebar = 'hidden';
+ var sidebar = null;
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
+ } else {
+ sidebar = 'hidden';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
@@ -286,5 +289,6 @@ def sum(a: int, b: int) -&gt; int:
<!-- Custom JS scripts -->
+ </div>
</body>
</html>
diff --git a/development/symbolver.html b/development/symbolver.html
index bd506cb..3fa715a 100644
--- a/development/symbolver.html
+++ b/development/symbolver.html
@@ -32,6 +32,7 @@
</head>
<body>
+ <div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
@@ -69,10 +70,12 @@
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var html = document.querySelector('html');
- var sidebar = 'hidden';
+ var sidebar = null;
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
+ } else {
+ sidebar = 'hidden';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
@@ -397,5 +400,6 @@ func_v2
<!-- Custom JS scripts -->
+ </div>
</body>
</html>