1. How does the keyword mutable modify a lambda?
mutable
2. Which of the following is only allowed to appear once in a single translation unit?
3. Consider the function template: template <typename T> void process(T&& arg) { /* ... */ } If an lvalue int a is passed to process, what type is deduced for T?
template <typename T>
void process(T&& arg) { /* ... */ }
int a
process
T
int
int&
int&&
int*
arg
4. What does it mean for a lambda to be "generic"?
5. Consider the following function template that takes in a container and returns its size as a double: template <typename T> double dsize(const T & container) { return static_cast<double>( container.size() ); } When the compiler first encounters this template (before instantiation with a specific type for T), it checks any aspects that it can for syntax correctness. Which of the following aspects will NOT be checked until the template is instantiated with a specific type for T?
double dsize(const T & container) {
return static_cast<double>( container.size() );
}
return
container
static_cast
double
size
6. Consider this code: template <typename T=int> T getValue() { return T(); } What will getValue() return if called without any arguments?
template <typename T=int>
T getValue() {
return T();
""
'a'
7. What is the difference between template parameters and template arguments?
template
8. Given the following function template: template <typename T> void Print(const T & item) { std::cout << item << std::endl; } Which call to Print would cause a compile-time error?
void Print(const T & item) {
std::cout << item << std::endl;
Print
Print(x)
x
std::map<std::string, std::string>
Print(22);
Print(nullptr);
Print("This is my literal string");
9. What is an explicit specialization of a template?
10. Which of that following is a potential downside of excessive use of templates, even when fully adhering to the C++ standard?
Click Check Answers to identify any errors and try again. Click Show Answers if you also want to know which answer is the correct one.