hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-19 15:47:03 +0200
committerhachem <im@hachem.wtf>2026-09-19 15:47:03 +0200
commit6d8b0392bb0c0df82285eec1b0f692113e66eb1a (patch)
treec08fde36b934b759b1255bac33dc69ae1adf7169 /examples
parente5cc80fb6a608aa1fbd0d6fabd1cf614a0fc004a (diff)
feat: enable_if
Diffstat (limited to 'examples')
-rw-r--r--examples/enable_if.sfinae22
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/enable_if.sfinae b/examples/enable_if.sfinae
new file mode 100644
index 0000000..ff7dacc
--- /dev/null
+++ b/examples/enable_if.sfinae
@@ -0,0 +1,22 @@
+// ::enable_if_t runs a ::sequence of statements when its condition holds
+// the statements inside are separated by commas and each one is still committed
+
+::enable_if_t<
+ ::is_same<::remove_cv_t<::int32_t>, ::int32_t>::value,
+ ::sequence<
+ ::declare<::name<'x'>, ::decltype(::difference<'C', 'A'>)>::commit,
+ ::emit<::decltype(::value_of<::name<'x'>>)>::commit
+ >
+>::commit;
+
+// this one never runs, so nothing is printed and nothing is asserted
+::enable_if_t<
+ ::false_type::value,
+ ::sequence<
+ ::static_assert<::false_type::value>::commit,
+ ::emit<::decltype(::difference<'Z', 'A'>)>::commit
+ >
+>::commit;
+
+// an empty sequence is allowed, for when you have nothing to say
+::enable_if_t<::true_type::value, ::sequence<>>::commit;