{"id":4982,"date":"2014-03-30T17:28:17","date_gmt":"2014-03-30T17:28:17","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-boost-any-collection-of-common-programming-errors\/"},"modified":"2014-03-30T17:28:17","modified_gmt":"2014-03-30T17:28:17","slug":"problem-about-boost-any-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-boost-any-collection-of-common-programming-errors\/","title":{"rendered":"problem about boost-any-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/941587f86c2f65a08dec808da1e3c1ce?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFrozenHeart<br \/>\nc++ boost boost-spirit boost-spirit-qi boost-any<br \/>\nI have the following code:#include &lt;boost\/any.hpp&gt; #include &lt;boost\/spirit\/include\/qi.hpp&gt;#include &lt;iostream&gt; #include &lt;string&gt;template &lt;typename Iterator&gt; struct parser : boost::spirit::qi::grammar&lt;Iterator, boost::any, boost::spirit::qi::ascii::space_type&gt; {parser() : parser::base_type(start){start %= boost::spirit::qi::int_;}boost::spirit::qi::rule&lt;Iterator, boost::any, boost::spirit::qi::ascii::space_type&gt; start; };int main() {const std::string input_<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/ba65fe61781731f1b551098a887b4212?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMaxpm<br \/>\nc++ oop derived-class boost-any<br \/>\nI&#8217;m making a simple boost::any-like class for educational purposes, but I can&#8217;t figure out how to access the stored value. I can set the value perfectly, but when I try to access any member in the &#8220;holder&#8221; class the compiler just complains that the member wasn&#8217;t found in the class it was derived from. I can&#8217;t declare the members as virtual because of the templates.Here&#8217;s the relevant code:class Element {struct ValueStorageBase{};template &lt;typename Datatype&gt;struct ValueStorage: public Val<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c90de868a7e95d75bdfd6a906dfedac7?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKennyTM<br \/>\nc++ templates metaprogramming boost-any<br \/>\nSuppose I have a list of type list&lt;boost::any&gt; that has some type in it that is unknown. Now suppose I want to apply some operation to the elements in the list that is polymorphic. In this case, consider the + operator. Suppose that I know that the list will always contain a homogenous set of objects that support operator+, and I want to get the result of applying operator+ (the &#8220;sum&#8221; in one sense) between each element of the list into a new boost::any. Something like this:boost::any sum(l<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/5cff5843c95e06b228bb33993d6e527a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nlizarisk<br \/>\nc++ boost casting boost-any<br \/>\nI&#8217;d like to use boost::any as a universal type to store in a container and to pass to different functions. But inside these functions I always know the real type, so in runtime I don&#8217;t need any type safety checks and the imposed overhead, static_cast is enough.The ideal solution would be to use something like boost::polymorphic_downcast, but as I can see it can&#8217;t be applied in this case.Should I just write my own wrapper for void* or is there another option?<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>FrozenHeart c++ boost boost-spirit boost-spirit-qi boost-any I have the following code:#include &lt;boost\/any.hpp&gt; #include &lt;boost\/spirit\/include\/qi.hpp&gt;#include &lt;iostream&gt; #include &lt;string&gt;template &lt;typename Iterator&gt; struct parser : boost::spirit::qi::grammar&lt;Iterator, boost::any, boost::spirit::qi::ascii::space_type&gt; {parser() : parser::base_type(start){start %= boost::spirit::qi::int_;}boost::spirit::qi::rule&lt;Iterator, boost::any, boost::spirit::qi::ascii::space_type&gt; start; };int main() {const std::string input_ Maxpm c++ oop derived-class boost-any I&#8217;m making a simple boost::any-like class for educational purposes, but I can&#8217;t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4982","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4982"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4982\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}