hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/tutorial/03_variables.sfinae
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-19 22:04:44 +0200
committerhachem <im@hachem.wtf>2026-09-19 22:04:44 +0200
commit2da2c56c72e7085bd9a52f848df90c6fc701de7f (patch)
tree96cf837a606297aed921b9adaac783940a1aa7cd /tutorial/03_variables.sfinae
parent6487b5b5301f6cb37c95c3571578d5a42adb2a1a (diff)
docs: add tutorial
Diffstat (limited to 'tutorial/03_variables.sfinae')
-rw-r--r--tutorial/03_variables.sfinae46
1 files changed, 46 insertions, 0 deletions
diff --git a/tutorial/03_variables.sfinae b/tutorial/03_variables.sfinae
new file mode 100644
index 0000000..6f200f1
--- /dev/null
+++ b/tutorial/03_variables.sfinae
@@ -0,0 +1,46 @@
+// lesson 3: variables
+//
+// a name is a list of characters. a variable holds a type, not a value, and the
+// only type that carries a value is ::decltype(...). the ::conditional_t around
+// it is not required. it is just what everyone does
+
+::declare<
+ ::name<'x'>,
+ ::conditional_t<
+ ::true_type::value,
+ ::decltype(::difference<'F', 'A'>),
+ ::void
+ >
+>::commit;
+
+// reading it back is ::value_of<NAME>, which is a value, so ::decltype it again
+
+::emit<::decltype(::value_of<::name<'x'>>)>::commit;
+
+::declare<
+ ::name<'y'>,
+ ::decltype(
+ ::sum<
+ ::value_of<::name<'x'>>,
+ ::difference<'B', 'A'>
+ >
+ )
+>::commit;
+
+::emit<::decltype(::value_of<::name<'y'>>)>::commit;
+
+// there is no assignment. to change x, undeclare it and declare it again
+
+::undeclare<::name<'x'>>::commit;
+
+::declare<
+ ::name<'x'>,
+ ::decltype(
+ ::product<
+ ::value_of<::name<'y'>>,
+ ::difference<'C', 'A'>
+ >
+ )
+>::commit;
+
+::emit<::decltype(::value_of<::name<'x'>>)>::commit;