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 ebook as a suite of recommendations that would convey a brand new type in C++ and make code tremendously transparent and effective. The e-book offers with language facets, layout styles, examples and functions (seen as case studies). particular emphasis is wear small reusable strategies that may increase the standard of day-by-day paintings.

What makes the ebook unheard of is the extent of knowing of the thoughts concerned imparted via the writer. this isn't only a rote review of metaprogramming. you are going to really comprehend tough themes like static assertions, find out how to write metafunctions, overload solution, lambda expressions, etc. greater than that, you'll paintings via them with sensible examples guided by way of the author's frank reasons. This ebook calls for you to imagine and to benefit and to appreciate the language that you can application at the next level.

Show description

Read or Download Advanced Metaprogramming in Classic C++ PDF

Best c & c++ books

Mastering Asp.Net with Visual C#

ASP. web is Microsoft's new know-how for constructing complicated, interactive internet purposes. This entire advisor takes C# programmers via the entire steps of constructing net purposes that leverage the total energy of the . internet applied sciences. It contains in-depth assurance of server-side programming with ASP.

Practical C++ Programming, Second Edition

C++ is a strong, hugely versatile, and adaptable programming language that permits software program engineers to prepare and technique details speedy and successfully. yet this high-level language is comparatively tough to grasp, whether the c program languageperiod. The second version of functional C++ Programming is a whole creation to the C++ language for programmers who're studying C++.

C++ Toolkit for Engineers and Scientists

This publication describes the layout, development, and use of a numerical research software program toolkit. it truly is written in C+ +, model 2. zero, and makes crucial use of that language's Object-Oriented Programming (OOP) beneficial properties. Its improvement setting is the Borland foreign, Inc. , Borland C++ compiler, model five.

Extra info for Advanced Metaprogramming in Classic C++

Sample text

As an example, you could agree that all macros begin with MXT_. e. never undefined, the prefix will be MXT. If the macro’s scope is limited (it’s defined and undefined later in the same file), the prefix will be mXT_. #ifndef MXT_filename_ #define MXT_filename_ // this is "exported" – let's name it MXT_* #define mXT_MYVALUE 3 // this macro has limited "scope" const int VALUE = mXT_MYVALUE; // let's name it mXT_* #undef mXT_MYVALUE // #endif //MXT_filename_ A lowercase prefix mxt is reserved to remap standard/system function names in different platforms: #ifdef _WIN32 #define mxt_native_dbl_isfinite _finite #else #define mxt_native_dbl_isfinite isfinite #endif For better code appearance, you could decide to replace some keywords with a macro: #define MXT_NAMESPACE_BEGIN(x) namespace x { #define MXT_NAMESPACE_END(x) } #define MXT_NAMESPACE_NULL_BEGIN() namespace { #define MXT_NAMESPACE_NULL_END() } And/or enclose the namespace directives in an ASCII-art comment box: ///////////////////////////////////////////////////////////////// MXT_NAMESPACE_BEGIN(XT) ///////////////////////////////////////////////////////////////// It’s useful to have some (integer) functions as a set of macros: #define MXT_M_MAX(a,b) ((a)<(b) ?

3 for a detailed example. 33 Some authors reserve the keyword typename for this purpose. In other words, they declare template to mean that T is “any type” and template to suggest that T is indeed a class as opposed to a native type. However, this distinction is rather artificial. 32 49 Chapter 1 ■ Templates Otherwise, you might want to use a (meaningful) lowercase name ending with _t (for example, int_t, scalar_t, object_t, any_t, or that_t). ; }; The suffix _t, which in C originally means typedef, is also widely used for (private) typedefs standing for template instances: template class SomeContainer { // informally means: // within this class, a pair always denotes a pair of scalars private: typedef std::pair pair_t; }; On the other hand, a public typedef name usually is composed of lowercase regular English words (such as iterator_category).

A predicate is a non-modifying functor that takes all arguments of the same type and returns a boolean. 31 Functors are usually stateless or they carry few data members, so they are built on the fly. 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.

Download PDF sample

Rated 4.94 of 5 – based on 44 votes
Category: C C