boost-any

boost::spirit::hold_any memory corruption

試著忘記壹切 提交于 2019-12-01 01:03:26
I have a large code base that can use boost::any or boost::spirit::hold_any (depending on a macro definition). hold_any seems to be compatible with boost::any (e.g. How to print boost::any to a stream? or Type erasure - Part IV ) and faster ( Why you shouldn’t use boost::any ) but I'm experiencing several segmentation fault errors using hold_any (Boost v1.55 / 1.54 / 1.53). This is a minimal working example that exhibits the same problem as the original code: #include <iostream> #include <string> #include <vector> #include <boost/spirit/home/support/detail/hold_any.hpp> typedef boost::spirit:

C++ - boost::any serialization

淺唱寂寞╮ 提交于 2019-11-30 17:47:55
As far as I understand, there is no serialization ( boost::serialization , actually) support for boost::any placeholder. Does someone know if there is a way to serialize a custom boost::any entity? The problem here is obvious: boost::any uses template-based placeholders to store objects and typeid to check if boost::any_cast is appropriate. So, there is a custom abstract superclass placeholder and custom template-based derived classes, which are created the following way: template <T> custom_placeholder : public placeholder { virtual std::type_info type() const { return typeid(T); } virtual ..

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:

visitor pattern for boost::any

一个人想着一个人 提交于 2019-11-30 05:44:48
问题 I found this https://gist.github.com/2945472 but I need an implementation that does not depend on c++11. I tried my hand at converting it to use only boost, but I'm having some trouble. Here is what I came up with: #include <boost/any.hpp> #include <boost/function.hpp> #include <boost/bind.hpp> #include <boost/lambda/lambda.hpp> #include <boost/unordered_map.hpp> struct type_info_hash { std::size_t operator()(std::type_info const & t) const { return t.hash_code(); } }; struct equal_ref {

C++ - boost::any serialization

孤街浪徒 提交于 2019-11-30 01:53:21
问题 As far as I understand, there is no serialization ( boost::serialization , actually) support for boost::any placeholder. Does someone know if there is a way to serialize a custom boost::any entity? The problem here is obvious: boost::any uses template-based placeholders to store objects and typeid to check if boost::any_cast is appropriate. So, there is a custom abstract superclass placeholder and custom template-based derived classes, which are created the following way: template <T> custom

boost::any replacement for the code below

吃可爱长大的小学妹 提交于 2019-11-29 17:11:53
I wish get rid of boost dependency on my code. I have the following struct construct. When calling and using this struct at another place in the code boost::any_cast is used. I know a template class would do it, but finding it hard to write this template. - C++ Rookie. struct Properties { public: Properties() {} Properties(const std::string &s, const boost::any & p) { name = s; value = p; } template <typename T> Properties(T n) { value = n; } boost::any value; std::string name; }; Just for fun, I thought I'd create a minimalist any implementation: ////////////////////////////////////////// //

Generic function to convert boost::any to boost::variant

白昼怎懂夜的黑 提交于 2019-11-29 14:52:50
Assume that you have a boost::any object and a boost::variant object. I'm looking for a generic function convert , that takes a template parameter T being a specialized boost::variant e.g. boost::variant<int, std::string> and magically converts the boost::any to one of the available types of the given boost::variant . template<T> T convert(const boost::any& any) { // Some generic conversion code here or throw exception if conversion is not possible! } int main(int argc, char** args) { typedef boost::variant<int, std::string> TVar; boost::any any="Hello World"; TVar variant=convert<TVar>(any);

Generic function to convert boost::any to boost::variant

て烟熏妆下的殇ゞ 提交于 2019-11-28 09:16:20
问题 Assume that you have a boost::any object and a boost::variant object. I'm looking for a generic function convert , that takes a template parameter T being a specialized boost::variant e.g. boost::variant<int, std::string> and magically converts the boost::any to one of the available types of the given boost::variant . template<T> T convert(const boost::any& any) { // Some generic conversion code here or throw exception if conversion is not possible! } int main(int argc, char** args) { typedef

Building boost::options from a string/boost::any map

喜你入骨 提交于 2019-11-28 06:36:40
I have a map which represents a configuration. It's a map of std::string and boost::any . This map is initialized at the start and I'd like the user to be able to override these options on the command line. What I'd love to do is build the program options from this map using the options_description::add_option() method. However, it takes a template argument po::value<> whereas all I have is boost::any . So far, I just have the shell of the code. m_Config represents my configuration class, and getTuples() returns a std::map<std::string, Tuple> . TuplePair is a typedef of std::pair<std::string,

How do boost::variant and boost::any work?

∥☆過路亽.° 提交于 2019-11-27 17:06:16
How do variant and any from the boost library work internally? In a project I am working on, I currently use a tagged union. I want to use something else, because unions in C++ don't let you use objects with constructors, destructors or overloaded assignment operators. I queried the size of any and variant, and did some experiments with them. In my platform, variant takes the size of its longest possible type plus 8 bytes: I think it my just be 8 bytes o type information and the rest being the stored value. On the other hand, any just takes 8 bytes. Since i'm on a 64-bit platform, I guess any