Skip to Content
Advanced C++ Programming Cookbook
book

Advanced C++ Programming Cookbook

by Dr. Rian Quinn
January 2020
Intermediate to advanced
454 pages
11h 25m
English
Packt Publishing
Content preview from Advanced C++ Programming Cookbook

How it works...

Variadic templates provide the programmer with the ability to define a template function without needing to define all of the arguments. These are used heavily in wrapper functions as they prevent the wrapper from having to have any knowledge of the function's arguments, as shown in this example:

#include <iostream>template<typename... Args>void foo(Args &&...args){ }int main(void){    foo("The answer is: ", 42);    return 0;}

As shown in the preceding example, we have created a foo function that can take any number of arguments. In this example, we use the universal reference notation, Args &&...args, which ensures the CV qualifiers and l-/r-valueness is preserved, meaning we can then use std::forward() to pass the variable arguments ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern C++ Programming Cookbook

Modern C++ Programming Cookbook

Marius Bancila

Publisher Resources

ISBN: 9781838559915Supplemental Content