Templates and STL in C++

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/18

flashcard set

Earn XP

Description and Tags

Flashcards about Templates, Function Overloading, and Standard Template Library (STL) in C++

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

DRY (Don't Repeat Yourself) Code

A coding principle to avoid duplicating code; templates are used to achieve this.

2
New cards

Templates

Templates are used as placeholders for data types, allowing functions and classes to work with different types without being rewritten.

3
New cards

When can we use templates?

All functions have the same number of parameters, the same code block, and the same type pattern.

4
New cards

How can you define a template?

Using template or template .

5
New cards

How do templates run?

The compiler interprets the parameters passed in to determine the specific type.

6
New cards

How can you set the template type manually?

By specifying the type explicitly when calling the template function.

7
New cards

When would you use templates over function overloading?

When you want the same function to work with different types while maintaining the same logic.

8
New cards

Examples of Algorithms in STL

Sorting, searching, partitioning, and standard array algorithms.

9
New cards

Examples of Containers in STL

Vector, list, array, queue, stack, set, and map.

10
New cards

What is STL?

Standard Template Library, a set of C++ template classes for common programming data structures and functions.

11
New cards

What does sort(arr, arr+size) do?

Sort an array from the beginning to the end.

12
New cards

What does reverse(arr, arr+n) do?

Revert elements from the beginning to the end of the array.

13
New cards

What does count(arr, arr+size, 0) do?

Count the number of 0s from the beginning to the end of the array.

14
New cards

What does copy_n do?

Copy all elements from one array to another array.

15
New cards

What parameters does copy_n take?

Source array, size of array, and target array.

16
New cards

Function Overloading

Different functions with the same name but different implementations.

17
New cards

What are Functions in the context of STL?

It allows you to overload function operators.

18
New cards

What are Iterators in the context of STL?

They allow you to iterate over a sequence of values.

19
New cards

Using references (&) in templates

This will modify the original variables.