hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/tutorial/02_numbers.sfinae
diff options
context:
space:
mode:
Diffstat (limited to 'tutorial/02_numbers.sfinae')
-rw-r--r--tutorial/02_numbers.sfinae61
1 files changed, 61 insertions, 0 deletions
diff --git a/tutorial/02_numbers.sfinae b/tutorial/02_numbers.sfinae
new file mode 100644
index 0000000..76f7dca
--- /dev/null
+++ b/tutorial/02_numbers.sfinae
@@ -0,0 +1,61 @@
+// lesson 2: numbers
+//
+// a digit is a syntax error. the only number literal is ::difference<'a', 'b'>,
+// the distance between two characters. 'F' - 'A' is 5. ::emit takes a type, and a
+// value is not a type, so wrap it in ::decltype(...) to make it one
+
+::emit<::decltype(::difference<'F', 'A'>)>::commit;
+
+// arithmetic is ::sum, ::product and ::quotient.
+// no operators
+// no precedence
+// no problem
+
+::emit<
+ ::decltype(
+ ::sum<
+ ::difference<'F', 'A'>,
+ ::difference<'C', 'A'>
+ >
+ )
+>::commit;
+
+::emit<
+ ::decltype(
+ ::product<
+ ::difference<'D', 'A'>,
+ ::difference<'E', 'A'>
+ >
+ )
+>::commit;
+
+::emit<
+ ::decltype(
+ ::quotient<
+ ::difference<'H', 'A'>,
+ ::difference<'C', 'A'>
+ >
+ )
+>::commit;
+
+// ::integral_constant<::size_t, V>::value is V. it exists so you can write more
+// ::extent<T>::value is the length of an array type, and 0 for anything else
+// this is the long way to write 20
+
+::emit<
+ ::decltype(
+ ::extent<
+ ::array<
+ ::byte,
+ ::integral_constant<
+ ::size_t,
+ ::difference<'Z', 'F'>
+ >::value
+ >
+ >::value
+ )
+>::commit;
+
+// emitting a type that is not a value prints the name of the type
+
+::emit<::remove_cv_t<::int32_t>>::commit;