Abstract
Templates are used as interfaces in two different ways: to provide sets of atomic functions and to obtain .
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
The notion of concept was introduced in Section 2.2.4.
- 2.
The black hole iterator is a hack, not a perfect output iterator.
- 3.
This is why, for example, the standard describes carefully what happens to functors passed to STL algorithms, such as how many times they are copied, and so on.
- 4.
The boost library contains some more general code. See http://www.boost.org/doc/libs/1_57_0/libs/utility/operators.htm .
- 5.
See [2] page 135.
- 6.
The downside of this technique is that the macro may confuse some IDEs that parse headers to build a graphical representation of the project.
- 7.
Apparently, the term “memberspace” was introduced by Joaquín M López Muñoz in “An STL-Like Bidirectional Map” (see www.codeproject.com/vcpp/stl/bimap.asp ). Also, the double-end queue example is from the same author.
- 8.
In the pseudo-code that follows, you should pretend that C is a class; of course a non-template container would be an unusual beast.
- 9.
This code does not compile, because for conciseness, we removed all const versions of the member functions. However, the fix should be obvious.
- 10.
Modern C++ offers two new keywords: decltype and auto. The former returns the exact type of any expression, similarly to sizeof. The latter allows an instance to “copy” the type of its initializer, so auto i = f() would declare a variable i having the best possible type to store the result of f() locally. See Chapter 12 for more details.
- 11.
This example is important and it will be analyzed again in Section 5.4.1.
- 12.
The prefix is a fixed character sequence, usually "-", "--", or "/".
- 13.
The implementation uses short-circuit to prevent null pointer dereferencing, and it’s extremely concise. See also an exercise in Appendix B.
- 14.
The implementation is obviously faulty; option map cannot be safely copied/assigned. To keep the code as simple as possible, and even simpler, the discussion of this topic is deferred to Section 5.35.
- 15.
This is also known as an unbounded discriminated union. The code should be taken as a proof-of-concept, not as production ready. Two big issues are not considered: const-ness and aligned storage. I suggest as a quick-and-dirty f ix that you put variant::storage_ in a union with a dummy structure having a single member double. See. A. Alexandrescu’s “An Implementation of Discriminated Unions in C++”.
- 16.
The mapped memory area is usually not resizable. Merely for simplicity, we assume it’s const, but that need not be the case. A vector needs to store three independent pieces of data (for example, “begin,” “size,” and “capacity”; everything else can be deduced). A read_write_memory_block would also need these members, but the capacity would be a constant and equal to “max size” from the beginning.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2015 Davide Di Gennaro
About this chapter
Cite this chapter
Gennaro, D.D. (2015). Interfaces. In: Advanced Metaprogramming in Classic C++. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-1010-9_5
Download citation
DOI: https://doi.org/10.1007/978-1-4842-1010-9_5
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-1011-6
Online ISBN: 978-1-4842-1010-9
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books