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::tuple

Explanation

Holds any number of values of potentially different types.

See std::tuple.

Memory: inline. Size = sum of all element sizes + padding.

Code

#include <print>
#include <string>
#include <tuple>

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

  auto [addr, name, size] = symbol;

  std::println("{} @ {:#x} (size: {:#x})", name, addr, size);

  return 0;
}

View on GitHub.

Output

$ ./src/data-structures/build/std-tuple
_main @ 0x10001000 (size: 0x100)