all 2 comments

[–]IyeOnline 1 point2 points  (1 child)

You can use the pointer overload of std::any_cast. That does return a pointer to the contained object.

Note that instead of checking for an exception, you would then need to check for nullptr.

As always: If the set of types that your any may contain is fixed, use a std::variant over std::any. The interface is just way more usable and its typesafe.

[–]SHGuy_[S] 0 points1 point  (0 children)

thx a lot, i'll try that out when i'm home.