Accessing The Stored Value
Explore how to use std any cast for accessing the value stored in std any safely in C++17. Understand the three modes of access: read-only copy, read-write reference, and pointer-based access including error handling using exceptions or nullptr returns.
We'll cover the following...
We'll cover the following...
To access the currently active value in std::any you have one option:
std::any_cast<T>().
The function has three “modes” you can work with:
- read access - takes
std::anyas a reference, returns a copy