Category : stdany

I am trying to create a compile time polymorphism design that will not require virtual functions with all their drawbacks. However I am struggling with creating simple, effective and easy to understand container that can simulate the ability to hold derived class in it’s base class container. My previous attempts with compile time variadic vectors ..

Read more

How to iterate an std::array with std::any value type. Suppose we don’t use the std::tuple and std::get but only a std::array<std::any, SIZE>. I have declared it: std::array<std::any, 5> array_any = { "Hello", 50, 3.1415926535897l, true, nullptr }; I could print like this without a loop: std::cout << std::boolalpha << std::any_cast<const char*>(array_any[0]) << ‘ ‘ << ..

Read more

I’m in search of a way to set up and call functions with arbitrary arguments and return types. One use case would be high level scripting. Something like this: // universal function using dynfunction = std::any (*)(std::vector<std::any> args); I made a simplified example: #include <any> #include <vector> #include <map> #include <string> #include <iostream> using namespace ..

Read more

Is only the way to modify, not replace, an object stored as std::any is to declare changeable data mutable? E.g. to avoid creation and copy of class S instances: #include <iostream> #include <vector> #include <any> #include <string> struct S { mutable std::string str; S(S&& arg) : str(std::move(arg.str)) { std::cout << ">> S moved" << std::endl; ..

Read more