boost-variant

Output of a boost::variant type using boost::spirit::karma

左心房为你撑大大i 提交于 2019-12-24 13:19:46
问题 I'm trying to output parameters, they can either be a single parameter or a vector of parameters. The following code does not what I'd like it to do: #include <iostream> #include <string> #include <boost/variant.hpp> #include <boost/spirit/include/karma.hpp> namespace karma = boost::spirit::karma; typedef std::vector<int> ParameterList; typedef boost::variant<int, ParameterList> Parameter; main() { using karma::int_; using karma::eol; using karma::lit; std::string generated; std::back_insert

Storing function pointers with different types c++ boost::bind

ⅰ亾dé卋堺 提交于 2019-12-24 02:42:37
问题 I have dug around quite a bit today and have come up empty. Is there any way to store a functor that is returned from a boost::bind with different types? I found an example that used boost::variants but not sure that this is needed. (Foo and Bar have been simplified for simplicity sake) #include <boost/bind.hpp> #include <boost/variant.hpp> #include <boost/function.hpp> #include <map> #include <iostream> template <typename FooType> struct Foo { const FooType tmp_value; Foo(const FooType& tmp_

Boost Spirit and abstract syntax tree design

…衆ロ難τιáo~ 提交于 2019-12-24 02:39:29
问题 I'm using Qi from Boost Spirit to parse VRML 1.0. There is a group node called Separator and immediately under Separator, many different types of nodes can be held. The AST is based upon Boost.Variant and so far is looking lengthy. I'm close to hitting the limit of 20 types in the variant. I know I can extend number of types a variant has, but I'm sure there must be a better way to design this. Ideas welcome. typedef boost::variant< Nil, Coordinate3, Info, Material, MaterialBinding, Normal,

Boost variant ambiguous construction [duplicate]

喜欢而已 提交于 2019-12-23 08:49:13
问题 This question already has answers here : boost::variant - why is “const char*” converted to “bool”? (2 answers) Closed 5 years ago . The Boost Variant documentation says the following of the constructor that accepts arbitrary type: template<typename T> variant(T & operand); Requires: T must be unambiguously convertible to one of the bounded types (i.e., T1, T2, etc.). The same is true of the constructors accepting const T& and T&& . So I expect that the following code won't compile: boost:

C++ Mutually Recursive Variant Type (Again)

空扰寡人 提交于 2019-12-22 05:45:05
问题 I have a problem similar to that described here: C++ Mutually Recursive Variant Type I am trying to create a JSON representation in C++. Many libraries already offer excellent JSON representations and parsers that are very fast, but I am not reinventing this wheel. I need to create a C++ JSON representation that supports certain space optimizations under specific conditions. In short, if and only if a JSON array contains homogenous data, rather than storing every element as bloated variant

Why does boost::spirit::qi::parse() not set this boost::variant's value?

↘锁芯ラ 提交于 2019-12-21 04:59:13
问题 When trying to parse text into a boost::variant, the variant's value does not get changed. The parsers by themselves appear to work fine, so my assumption is that I'm doing something wrong with the variant code. I'm using boost 1.46.1 and the following code compiles in Visual Studio 2008. 1st Update hkaiser noted that the rule and grammar template arguments must not be Variant but Variant() . This got a bit "further" as I now have a compilation error in boost_1_46_1\boost\variant\variant.hpp

How to achieve dynamic polymorphism (run-time call dispatch) on unrelated types?

♀尐吖头ヾ 提交于 2019-12-20 09:37:56
问题 GOAL: I would like to achieve type-safe dynamic polymorphism (i.e. run-time dispatch of a function call) on unrelated types - i.e. on types which do not have a common base class . It seems to me that this is achievable, or at least theoretically sound. I will try to define my problem more formally. PROBLEM DEFINITION: Given the following: two or more unrelated types A1, ..., An , each of which has a method called f , possibly with different signatures, but with the same return type R ; and a

String-bool comparsion - why?

时光毁灭记忆、已成空白 提交于 2019-12-20 02:52:14
问题 I was working with boost::variant<int,std::string,bool> and its visitors when I runned into an unexpected behavior: the string and bool values were comparable. I don't know, why does it work like this, but I found it interesting. My only idea is that the variant with the bool value was interpreted as a char? Someone could explain it to me? The comparsion visitor: #include <iostream> #include <algorithm> #include <vector> #include <boost/variant.hpp> #include <boost/function.hpp> struct my

What is the equivalent of boost::variant in the C++ standard library?

三世轮回 提交于 2019-12-19 05:14:17
问题 I am looking for an alternative to C-style union. boost::variant is one such option. Is there anything in std C++ ? union { int i; double d; } 回答1: As several commenters said: No, there is no Boost Variant-alike in standard C++. Maybe in a few years there will be, but why wait--use Boost Variant today! Edit (four years later, 2016): In C++17 there will be std::variant . Similar but not identical to boost::variant . So when your compiler supports C++17, you will have a solution in the standard

String parser with boost variant recursive wrapper

我们两清 提交于 2019-12-19 03:46:08
问题 The code below (adapted from spirit qi mini_xml example) does not compile. There is an error related to the rule brac that has an attribute of an recursive boost::variant . However, all commented out versions of brac do compile. I am very curious to know what makes the simple string parser so special in this case: #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator