Type Systems and Type Inference Terminology Reference

This reference provides an overview of type system and type inference terminology you'll encounter in this chapter. Use it as a quick lookup guide.

Type Conversion Basics

Term Definition Example
Implicit Conversion Automatic type conversion performed by compiler double d = 5; converts int to double
Explicit Conversion Type conversion explicitly requested by programmer static_cast<int>(3.14) converts double to int
Type Conversion Changing a value from one type to another Converting int to float
Conversion Sequence Series of conversions applied to match types short to int to double

Numeric Promotions

Term Definition Example
Integral Promotion Small integer types promoted to int or unsigned int char promoted to int in arithmetic
Floating-Point Promotion float promoted to double in expressions float f = 1.5f; double d = f;
Promotion Converting to a larger type without losing information short to int is always safe
Usual Arithmetic Conversions Rules for converting operands in arithmetic int + double results in double

Numeric Conversions

Term Definition Example
Narrowing Conversion Conversion that may lose information or precision double to int loses decimal places
Widening Conversion Conversion to larger type, typically safe int to long preserves value
Value-Preserving Conversion that maintains the exact value int to double for small integers
Lossy Conversion Conversion that loses precision or data int x = 3.9; loses .9

Initialization and Safety

Term Definition Example
List Initialization Initialization using brace syntax {} int x{5}; or double d{3.14};
Narrowing Conversion Error Compile error when list initialization would narrow int x{3.14}; generates compile error
Copy Initialization Using = to initialize variable int x = 5;
Direct Initialization Using parentheses to initialize int x(5);
Uniform Initialization Consistent initialization syntax using braces int x{5}; std::string s{"hello"};
constexpr Initializer Compile-time constant used for initialization constexpr int max{100};

Arithmetic Conversions

Term Definition Example
Mixed-Type Arithmetic Arithmetic with operands of different types int + double
Operand Promotion Converting operands to common type for operation Both operands converted to double
Type Coercion Forcing value to specific type Compiler converts int to double automatically
Binary Operator Operator taking two operands +, -, *, /

Casting Operations

Term Definition Example
static_cast Explicit type conversion checked at compile time static_cast<int>(3.14)
C-Style Cast Old-style cast using parentheses (int)3.14 not recommended
Cast Operator Operator that performs type conversion static_cast, dynamic_cast, const_cast
Reinterpret Cast Low-level reinterpretation of bits (dangerous) reinterpret_cast<int*>(&d)

Type Aliases

Term Definition Example
typedef Keyword for creating type aliases (old style) typedef unsigned int uint;
Type Alias Alternative name for an existing type using Distance = double;
using Declaration Modern syntax for type aliases using uint = unsigned int;
Alias Template Template that creates type aliases template<typename T> using Ptr = T*;

Type Deduction

Term Definition Example
auto Keyword Tells compiler to deduce type from initializer auto x = 5; deduced as int
Type Deduction Compiler automatically determining variable type Inferring double from auto x = 3.14;
Template Argument Deduction Compiler determining template parameter types max(5, 10) deduces template type is int
Initializer Expression used to determine deduced type In auto x = 5;, 5 is the initializer

Auto Type Deduction Rules

Term Definition Example
Top-Level const const on the variable itself (dropped by auto) const int x = 5; auto y = x; (y is int)
Low-Level const const on what pointer/reference points to const int* p; auto q = p; (q is const int*)
Reference Collapse Rules for combining reference types auto& from reference initializer
Decay Converting arrays/functions to pointers int arr[5]; auto p = arr; (p is int*)

Function Return Type Deduction

Term Definition Example
auto Return Type Function return type deduced from return statement auto add(int a, int b) { return a + b; }
Trailing Return Type Return type specified after parameter list auto add(int a, int b) -> int
decltype Keyword to query type of expression decltype(x + y) gets type of expression
Return Type Deduction Compiler inferring function return type Deducing int from return 5;