From 2da2c56c72e7085bd9a52f848df90c6fc701de7f Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 22:04:44 +0200 Subject: docs: add tutorial --- tutorial/03_variables.sfinae | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tutorial/03_variables.sfinae (limited to 'tutorial/03_variables.sfinae') 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, 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; -- cgit v1.3