Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

std::pair

Explanation

Holds exactly two values of potentially different types.

See std::pair.

Memory: inline (stack if local). Size = sizeof(T1) + sizeof(T2) + padding.

Code

#include <print>
#include <utility>

int main() {
  std::pair<uint64_t, std::string> symbol{0x10001000, "_main"};

  auto [addr, name] = symbol;
  std::println("{} @ {:#x}", name, addr);

  return 0;
}

View on GitHub.

Output

$ ./src/data-structures/build/std-pair
_main @ 0x10001000