@@ -266,7 +266,7 @@ \subsection{Optional}
266266management issues characteristic of C++):
267267
268268\begin {snip }{cpp}
269- template<class T>
269+ template<typename T>
270270class optional {
271271 bool _isValid; // the tag
272272 T _v;
@@ -282,7 +282,7 @@ \subsection{Optional}
282282functions:
283283
284284\begin {snip }{cpp}
285- template<class A, class B>
285+ template<typename A, typename B>
286286std::function<optional<B>(optional<A>)>
287287fmap(std::function<B(A)> f) {
288288 return [f](optional<A> opt) {
@@ -297,7 +297,7 @@ \subsection{Optional}
297297returning a function. Here's the uncurried version of it:
298298
299299\begin {snip }{cpp}
300- template<class A, class B>
300+ template<typename A, typename B>
301301optional<B> fmap(std::function<B(A)> f, optional<A> opt) {
302302 if (!opt.isValid())
303303 return optional<B>{};
@@ -380,22 +380,22 @@ \subsection{Functor in C++}
380380\code {F}. This is the syntax for it:
381381
382382\begin {snip }{cpp}
383- template<template<class > F, class A, class B>
383+ template<template<typename > F, typename A, typename B>
384384F<B> fmap(std::function<B(A)>, F<A>);
385385\end {snip }
386386We would like to be able to specialize this template for different
387387functors. Unfortunately, there is a prohibition against partial
388388specialization of template functions in C++. You can't write:
389389
390390\begin {snip }{cpp}
391- template<class A, class B>
391+ template<typename A, typename B>
392392optional<B> fmap<optional>(std::function<B(A)> f, optional<A> opt)
393393\end {snip }
394394Instead, we have to fall back on function overloading, which brings us
395395back to the original definition of the uncurried \code {fmap}:
396396
397397\begin {snip }{cpp}
398- template<class A, class B>
398+ template<typename A, typename B>
399399optional<B> fmap(std::function<B(A)> f, optional<A> opt) {
400400 if (!opt.isValid())
401401 return optional<B>{};
@@ -456,7 +456,7 @@ \subsection{The List Functor}
456456is just a thin encapsulation of \code {std::transform}:
457457
458458\begin {snip }{cpp}
459- template<class A, class B>
459+ template<typename A, typename B>
460460std::vector<B> fmap(std::function<B(A)> f, std::vector<A> v) {
461461 std::vector<B> w;
462462 std::transform( std::begin(v)
@@ -611,7 +611,7 @@ \section{Functors as Containers}
611611arguments --- which are compile-time --- and values, which are run-time:
612612
613613\begin {snip }{cpp}
614- template<class C, class A>
614+ template<typename C, typename A>
615615struct Const {
616616 Const(C v) : _v(v) {}
617617 C _v;
@@ -622,7 +622,7 @@ \section{Functors as Containers}
622622changing its value:
623623
624624\begin {snip }{cpp}
625- template<class C, class A, class B>
625+ template<typename C, typename A, typename B>
626626Const<C, B> fmap(std::function<B(A)> f, Const<C, A> c) {
627627 return Const<C, B>{c._v};
628628}
0 commit comments