boost-any

Access a type in a variadic template by index

柔情痞子 提交于 2021-02-10 11:47:38
问题 I would like to obtain a type in a variadic template by index. The index is specified as a template argument. I managed to find a 'hack' that works, but I believe that it is not in the spirit of variadic template programming. Besides, it uses extra memory. Here is the code with some explanations: template <typename... InputPortTypes> class PipelineReceiver { protected: // This tuple is used for storing types only // Hence, I would like to get rid of it, but I am not sure how. std::tuple< std:

Access a type in a variadic template by index

巧了我就是萌 提交于 2021-02-10 11:45:09
问题 I would like to obtain a type in a variadic template by index. The index is specified as a template argument. I managed to find a 'hack' that works, but I believe that it is not in the spirit of variadic template programming. Besides, it uses extra memory. Here is the code with some explanations: template <typename... InputPortTypes> class PipelineReceiver { protected: // This tuple is used for storing types only // Hence, I would like to get rid of it, but I am not sure how. std::tuple< std:

Storing objects in the array

◇◆丶佛笑我妖孽 提交于 2020-01-15 12:47:46
问题 I want to save boost signals objects in the map (association: signal name → signal object). The signals signature is different, so the second type of map should be boost::any . map<string, any> mSignalAssociation; The question is how to store objects without defining type of new signal signature? typedef boost::signals2::signal<void (int KeyCode)> sigKeyPressed; mSignalAssociation.insert(make_pair("KeyPressed", sigKeyPressed())); // This is what I need: passing object without type definition

Boost.Any vs. Boost.Variant

强颜欢笑 提交于 2019-12-31 08:41:09
问题 I'm having trouble choosing between Boost.Any and Boost.Variant. When should I use each one? What are the advantages and disadvantages of each? I am basically looking to store some states from external sources. 回答1: Have you looked at the comparison in the variant library already? (Not sure what states from external sources are, so it's kind of hard to say what's more appropriate for you.) 来源: https://stackoverflow.com/questions/1366524/boost-any-vs-boost-variant

set/access jagged map values made with map<string, boost::any>

时间秒杀一切 提交于 2019-12-24 19:37:57
问题 I've been shown how to create a jagged multidimensional std::map by using boost::any. However, I'm having trouble setting the values like in this answer. When I use accounts["bank"]["cash"] = 100; gcc gives this error error: no match for ‘operator[]’ in ‘accounts.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<std::basic_string<char>, boost::any, std::less<std::basic_string<char> >, std::allocator<std::pair<const std::basic_string<char>, boost::any> > >((* & std::basic_string<char>(((const

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

送分小仙女□ 提交于 2019-12-18 18:47:17
问题 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? 回答1: 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

boost::any replacement for the code below

你说的曾经没有我的故事 提交于 2019-12-18 09:24:33
问题 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; }; 回答1: Just

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

妖精的绣舞 提交于 2019-12-17 18:10:02
问题 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

boost spirit, boost any and quoted string - compile-time error

梦想与她 提交于 2019-12-13 18:10:01
问题 I have the following code: #include <boost/any.hpp> #include <boost/spirit/include/qi.hpp> #include <iostream> #include <string> template <typename Iterator> struct parser : boost::spirit::qi::grammar<Iterator, boost::any(), boost::spirit::qi::ascii::space_type> { parser() : parser::base_type(start) { start %= boost::spirit::qi::int_ | boost::spirit::qi::lexeme['"' >> +(boost::spirit::qi::char_ - '"') >> '"']; // example: 0 or "str" } boost::spirit::qi::rule<Iterator, boost::any(), boost:

Does boost::any need RTTI?

狂风中的少年 提交于 2019-12-11 05:53:22
问题 On the Boost web site I found no information regarding the use or RTTI by boost::any. I read in a few places that this is a requirement, but then I built a simple test project, and it builds both with and without RTTI. So, is RTTI, with its performance and memory issues, needed by boost::any and similar classes? 回答1: Since boost 1.57 RTTI is not needed for boost::any . Rememeber that all objects used as boost::any must by copyable. https://svn.boost.org/trac/boost/ticket/10346 来源: https:/