- Won't talk about preprocessor tricks
- Topic is very deep! To drill further, consult one or more of these books:
- 2001: Modern C++ Design: Generic Programming and Design Patterns Applied by Andrei Alexandrescu
- 2004: C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond by David Abrahams and Aleksey Gurtovoy
- 2017: C++ Templates: The Complete Guide (2nd Edition) by David Vandevoorde, Nicolai M. Josuttis, Douglas Gregor
- Template Review
- Template expansion
- Function Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST( Foo, foo ) | |
{ | |
int failures = 0; | |
for (int i = 0; i < 50; ++i) { | |
EXPECT_TRUE( i % 2 == 0 ) << ([&failures]() { ++failures; return ""; })(); | |
} | |
if (failures > 0) { | |
std::cout << "There were " << failures << " failures.\n"; | |
} | |
} |
- clang tooling library:
- AST matchers:
- extend
hasType
to work withTypedefDecl
nodes - add
functionProtoType
matcher for matchingFunctionProtoType
nodes - extend
parameterCountIs
matcher toFunctionProtoType
nodes
- extend
- AST matchers:
- clang-tidy checks:
modernize-macro-to-enum
converts groups of macros to unscoped anonymous enums
modernize-raw-string-literal
converts string literals with escaped characters to raw string literals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "type_traits.h" | |
#include <type_traits> | |
// In each test, replace XXX with syntax that passes the test. | |
BOOST_AUTO_TEST_CASE(is_void) | |
{ | |
BOOST_REQUIRE_EQUAL(true, std::is_void<XXX>::value); | |
std::is_void<XXX> val; | |
BOOST_REQUIRE_EQUAL(true, static_cast<bool>(val)); |
NewerOlder