/*std::any is a type-safe container defined in the C++ Standard Library. It is used
to store values of any type, including objects and primitives. The main advantage
of std::any over traditional void* is that std::any provides type-safe access to
the stored value.

Here is a simple example of how to use std::any:*/

#include <iostream>
#include <any>
#include <string>

int main()
{
  std::any a = 5;
  std::any b = std::string("Hello");
  
  try
  {
    int value = std::any_cast<int>(a);
    std::cout << "a holds int " << value << std::endl;
  }
  catch (const std::bad_any_cast& e)
  {
    std::cerr << "Error: " << e.what() << std::endl;
  }
  
  try
  {
    std::string value = std::any_cast<std::string>(b);
    std::cout << "b holds string " << value << std::endl;
  }
  catch (const std::bad_any_cast& e)
  {
    std::cerr << "Error: " << e.what() << std::endl;
  }
  
  return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: