Advanced Metaprogramming in Classic C++ by Davide Di Gennaro

By Davide Di Gennaro

Advanced Metaprogramming in vintage C++ goals to be either an advent and a connection with C++ template metaprogramming (TMP); TMP is gifted within the booklet as a suite of innovations that may carry a brand new variety in C++ and make code tremendously transparent and effective. The publication offers with language facets, layout styles, examples and functions (seen as case studies). distinct emphasis is wear small reusable strategies that might enhance the standard of day-by-day paintings.

What makes the publication remarkable is the extent of figuring out of the recommendations concerned imparted via the writer. this isn't only a rote assessment of metaprogramming. you'll actually comprehend tricky themes like static assertions, the best way to write metafunctions, overload answer, lambda expressions, etc. greater than that, you are going to paintings via them with functional examples guided by means of the author's frank reasons. This e-book calls for you to imagine and to profit and to appreciate the language that you can application at a better level.

Show description

Read Online or Download Advanced Metaprogramming in Classic C++ PDF

Similar c & c++ books

A Numerical Library in C for Scientists and Engineers

It is a large library of c workouts to do exactly approximately whatever. the one sore spots are a few of the vector and matrix workouts. they're divided up in order that a few extremely simple operations require numerous exercises. in fact this used to be performed for flexibility, yet a few could locate that writing their very own is extra effective.

Objects, Abstraction, Data Structures and Design: Using C++

Imagine, Then CodeWhen it involves writing code, practise is important to good fortune. sooner than you can start writing winning code, you must first paintings via your ideas and examine the anticipated functionality of your layout. Thats why Elliot Koffman and Paul Wolfgangs gadgets, Abstraction, information constructions, and layout: utilizing C++ encourages you to imagine, Then Code, that will help you make reliable judgements in these serious first steps within the software program layout method.

Algorithms in a nutshell

Growing strong software program calls for using effective algorithms, yet programmers seldom take into consideration them till an issue happens. This up to date variation of Algorithms in a Nutshell describes various present algorithms for fixing numerous difficulties, and is helping you decide and enforce definitely the right set of rules on your needs—with barely enough math to allow you to comprehend and research set of rules functionality.

Extra resources for Advanced Metaprogramming in Classic C++

Example text

1. Deduction Function templates can deduce their parameters, matching argument types with their signature: template struct arg; template void f(arg); template void g(arg); arg a; f(a); // will deduce T = int* arg b; f(b); // will deduce T = const int g(b); // will deduce X = int Deduction also covers non-type arguments: template < int I> struct arg; template arg f(arg); arg<3> a; f(a); // will deduce I=3 and thus return arg<4> However, remember that deduction is done via “pattern matching” and the compiler is not required to perform any kind of algebra20: // this template is formally valid, but deduction will never succeed...

Occasionally, you may need a meaningful name for an instance, and this may not be so easy, because if the functor has a limited “scope,” the only meaningful name has already been given to the class. end(), is_holiday(myCal)); // is_holiday is a class // how do we name an instance? end(), is_holiday); The reader might want to review the simple example early in this chapter. 1. 4. Generality The best way to improve generality is to reuse standard classes, such as std::pair. This brings in well-tested code and increases interoperability; however, it may often hide some specific logic, for example the meaning of pair::first and pair::second may not be obvious at first sight.

If an object has a member function size(), then a call to empty() is expected to be no slower than size()==0. Note that an object may be empty but still control resources. For example, an empty vector might hold a raw block of memory, where in fact no element has yet been constructed. In particular, it’s unspecified if a clear function will or won’t release object resources; clear is a synonym of reset. To enforce resource cleanup of an auto variable, the usual technique is to swap the instance with a temporary: T x; // now x holds some resources...

Download PDF sample

Rated 4.11 of 5 – based on 38 votes

Related posts