C++11 Flashcards

(17 cards)

1
Q

trailing return type

A
template
auto multiply(T lhs, S rhs) -> decltype(lhs * rhs) {
  return lhs * rhs;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

decltype

A

A keyword to query the type of an expression. It is typically to express types depending on template parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

range-based “for” loop

A

int my_array [5] = {1, 2, 3, 4, 5};

for (auto& x : my_array ) { x *= 2; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

lambda functions/expressions

A

-> int { return x + y; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

expose base-class c’tors in a derived class

A

using BaseClass::BaseClass; // all of them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

override

A

The override special identifier means that the compiler will check the base class(es) to see if there is a virtual function with this exact signature. This is to prevent accidental creation of a new virtual function where an override was meant.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

final

A

virtual void f() final;

This prevents derived classes from overriding it or using the same method name in derived classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

nullptr type

A

nullptr_t, which is implicitly convertible and comparable with pointer types and bool.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

strongly typed enumerations

A

enum class E1: unsigned {Val1 = 1, Val2}; // unsigned is the underlying type for E1. However, elements of E1 cannot be directly compared to unsigned. Their scoping is also limited to E1 rather than the enclosing scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

variadic templates

A
Templates can take a variable number of parameters. Example:
template class tuple;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

template aliases

A

template
class SomeType ;
template
using TypedefName = SomeType ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

tuples

A
typedef std::tuple  test_tuple;
long lengthy = 12;
test_tuple proof (18, 6.5, lengthy, "Ciao!");
lengthy = std::get<0>(proof);
std::get<3>(proof) = " Beautiful!";
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

STL hash tables

A

unordered_{set, multiset, map, multimap}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

regex

A

regex_search, regex_replace, match_results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

smart pointers

A

unique_ptr, shared_ptr, weak_ptr.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

wrapper references

A

int i = 0;
g(func, i);
g(func, std::ref(i));

17
Q

initializer list constructor

A
std::vector x {4};
// vs. std::vector x (4);