@@ -490,7 +490,7 @@ you'll probably want to use a library like
490
490
the older `MPL <http://www.boost.org/doc/libs/1_61_0/libs/mpl/doc/index.html >`_
491
491
or the newer `boost::hana <http://www.boost.org/doc/libs/1_61_0/libs/hana/doc/html/index.html >`_.
492
492
493
- More case studies to come!
493
+ Some readers have taken umbrage with this example -- see my thoughts in the issues.
494
494
495
495
Case Study 2: Building an awesome event interface
496
496
-------------------------------------------------
@@ -616,6 +616,24 @@ The big takeaway here is that ``void_t`` can be used to really easily determine
616
616
Along with ``enable_if `` (which can also be used for this purpose, but the implementation is much more verbose)
617
617
we can start building much more complex data structures and metafunctions.
618
618
619
+ Some readers have pointed out that ``count `` can be implemented with fewer template instantiations.
620
+ And they're right! So check out this alternate implementation that doesn't use SFINAE at all:
621
+
622
+ .. code :: c++
623
+
624
+ /* Alternate implementation uses fewer template instantiations */
625
+ template <typename... Elts>
626
+ struct different_count;
627
+
628
+ template <typename... Elts>
629
+ struct different_count<type_list<Elts...>> : std::integral_constant<int, sizeof...(Elts)> {};
630
+
631
+ We only define a specialization here -- you can't instantiate ``different_count `` with anything other than a
632
+ ``type_list ``. This is an example of pattern matching, which we'll see used to good effect in the next example!
633
+ The interesting thing to note here is that matching the pattern ``type_list<Elts...> `` actually unpacks ``Elts `` so
634
+ that we can use it elsewhere in the template, namely as the argument of ``sizeof... ``, which counts the number of
635
+ types in a parameter pack.
636
+
619
637
Here's another metafunction that we'll be using:
620
638
621
639
.. code :: c++
0 commit comments