Remarks on std::any

Unlike the lean objects std::optional (C++17) and std::variant (C++17), std::any (C++17) is a very heavy class with generally complex interactions.

I would be pressed to recommend it unless there is a very specific reason. Most often than not, all of intended uses of std::any can be replaced with std::variant.

Remember: it is not because it is legal that you should use.

Sources: https://lnkd.in/dPmbK-BU
https://lnkd.in/dZYxKvWW

Compiler explorer with a simple std::any routine and the lengthy asm result
Compiler explorer for std::variant and the simple asm result
Compiler explorer for std::optional and the simple asm result