From 6d8b0392bb0c0df82285eec1b0f692113e66eb1a Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 15:47:03 +0200 Subject: feat: enable_if --- examples/enable_if.sfinae | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/enable_if.sfinae (limited to 'examples') 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; -- cgit v1.3