Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

6.8. Details

Abstraction

An idea that emphasizes high-level concepts and de-emphasizes implementation details. Classes in runtime C++ are one kind of abstraction commonly used to package state with associated processes. Functions are one of the most fundamental kinds of abstraction and are obviously important in any functional programming context. The MPL algorithms are abstractions of repetitive processes and are implemented as metafunctions. The abstraction value of algorithms in MPL is often higher than that of corresponding STL algorithms simply because the alternative to using them is so much worse at compile time. While we can traverse an STL sequence with a for loop and a couple of iterators, a hand-rolled compile-time sequence traversal always requires at least one new class template and an explicit specialization.

Fold

A primitive functional abstraction that applies a binary function repeatedly to the elements of a sequence and an additional value, using the result of the function at each step as the additional value for the next step. The STL captures the same abstraction under the name accumulate. MPL generalizes fold in two ways: by operating on iterators instead of elements (iter_fold) and by supplying bidirectional traversal (reverse_[iter_] fold).


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint