Challenge: Concatenate Strings

Test your understanding of variadic templates by solving this challenge on concatenating strings.

We'll cover the following

Problem statement

In the dynamic world of programming, optimizing string operations is a vital skill for developers to master. You are tasked to construct a class template strOps that concatenates a variable number of strings, counts the total number of characters in the concatenated string, and counts the total number of strings combined. Additionally, create a function template display_info to display this information. You also need to create supporting functions to accomplish these tasks.

Note: Ensure that your implementation utilizes variadic templates, fold expressions, and variadic variable templates to achieve the required functionality.

Analysis

We can extract the following information from the problem statement:

  • The strOps class: A variadic template class that takes any number of string arguments. It has three member variables.

  • The concatenate function: A member function that concatenates the input strings using fold expressions. We can use the following expression to concatenate all the arguments using the + operator.

Get hands-on with 1200+ tech skills courses.