When should I use std::any

When to Use

void* as an extremely unsafe pattern with some limited use cases, std::any adds type-safety, and that’s why it has some real use cases.

Some possibilities:

  • In Libraries – when a library type has to hold or pass anything without knowing the
    set of available types.
  • Parsing files – if you really cannot specify what are the supported
    types.
  • Message passing.
  • Bindings with a scripting language.
  • Implementing an interpreter for a scripting language
  • User Interface – controls might hold anything
  • Entities in an editor
    (ref)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)