stdany

How can I design storage that conforms to the standard's implementation of std::any?

扶醉桌前 提交于 2019-12-05 04:46:46
The standard working draft (n4582, 20.6.3, p.552) states the following suggestion for implementations of std::any : Implementations should avoid the use of dynamically allocated memory for a small contained object. [ Example: where the object constructed is holding only an int. —end example ] Such small-object optimization shall only be applied to types T for which is_nothrow_move_constructible_v is true. As far as I know, std::any can be easily implemented through type erasure/virtual functions and dynamically allocated memory. How can std::any avoid dynamic allocation and still destroy such

Does C++11 standard provide something like boost::any?

不羁岁月 提交于 2019-11-30 17:11:42
for example boost::function is moved almost entirely to std::function , the same is with boost::shared_ptr But I can't find std::any ? Was it renamed or was not it placed in new standard at all by any reason? Grizzly Not every library from boost makes it into the standard (and even those that do may have components removed). Generally the commitee is pretty conservative when it comes to adding to the standardlibrary (since it's next to impossible to get something removed at a later point if the inclusion was a mistake (.e.g. because there is a better alternative)). boost::function and boost:

Type erasing type erasure, `any` questions?

夙愿已清 提交于 2019-11-26 22:00:23
So, suppose I want to type erase using type erasure. I can create pseudo-methods for variants that enable a natural: pseudo_method print = [](auto&& self, auto&& os){ os << self; }; std::variant<A,B,C> var = // create a variant of type A B or C (var->*print)(std::cout); // print it out without knowing what it is My question is, how do I extend this to a std::any ? It cannot be done "in the raw". But at the point where we assign to/construct a std::any we have the type information we need. So, in theory, an augmented any : template<class...OperationsToTypeErase> struct super_any { std::any data

Type erasing type erasure, `any` questions?

为君一笑 提交于 2019-11-26 08:08:53
问题 So, suppose I want to type erase using type erasure. I can create pseudo-methods for variants that enable a natural: pseudo_method print = [](auto&& self, auto&& os){ os << self; }; std::variant<A,B,C> var = // create a variant of type A B or C (var->*print)(std::cout); // print it out without knowing what it is My question is, how do I extend this to a std::any ? It cannot be done \"in the raw\". But at the point where we assign to/construct a std::any we have the type information we need.