Skip to Content
C++ High Performance
book

C++ High Performance

by Viktor Sehr, Björn Andrist
January 2018
Intermediate to advanced
374 pages
9h 53m
English
Packt Publishing
Content preview from C++ High Performance

An example of a function with variadic number of arguments

If we were to create a function that makes a string out of any number of arguments without variadic template parameter packs, we would have to create a separate function for every number of arguments:

// Makes a string of by one argumenttemplate <typename T0> 
auto make_string(const T0& v0) -> std::string { 
  auto sstr = std::ostringstream{}; 
  sstr << v0; 
  return sstr.str(); 
} 
// Makes a string of by two arguments 
template <typename T0, typename T1> 
auto make_string(const T0& v0, const T1& v1) -> std::string { 
   return make_string(v0) + " " + make_string(v1); 
} 
// Makes a string of by three arguments 
template <typename T0, typename T1, typename T2> auto make_string(const T0& v0, const T1& ...
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

C++ High Performance - Second Edition

C++ High Performance - Second Edition

Björn Andrist, Viktor Sehr
Advanced C++

Advanced C++

Gazihan Alankus, Olena Lizina, Rakesh Mane, Vivek Nagarajan, Brian Price
C++ In a Nutshell

C++ In a Nutshell

Ray Lischner
C++ Cookbook

C++ Cookbook

D. Ryan Stephens, Christopher Diggins, Jonathan Turkanis, Jeff Cogswell

Publisher Resources

ISBN: 9781787120952Supplemental Content