Related
I am trying to convert variablepixelbuffer.vbuffer() to a vector of double values using apply_visitor in boost.
I came with this piece of code till now :
struct GetVector : public boost::static_visitor<std::vector<double>>
{
//values will be returned in a pair. double is
// used since it can contain the value for any pixel type
typedef std::vector<double> result_type;
template<typename T
void myfunction (const T& i) { // function:
result_type.push_back(static_cast<double>(*i));
}
template<typename T>
result_type
operator() (const T& v)
{
typedef typename T::element_type::value_type value_type;
std::for_each (v->data(), v->data() + v->num_elements(), myfunction);
return result_type;
}
};
/* pixel-example-start */
void
readPixelData(const FormatReader& reader,
std::ostream& stream,int x,int y,int w,int h)
{
// Change the current series to this index
reader.setSeries(0);
// Get total number of planes (for this image index)
dimension_size_type pc = reader.getImageCount();
// Pixel buffer
VariantPixelBuffer buf;
dimension_size_type xd = x;
dimension_size_type yd = y;
dimension_size_type wd = w;
dimension_size_type hd = h;
// Loop over planes (for this image index)
for (dimension_size_type p = 0 ; p < pc; p++)
{
// Read the entire plane into the pixel buffer.
reader.openBytes(p, buf,xd,yd,wd,hd);
}
GetVector visitor;
GetVector::result_type result = boost::apply_visitor(visitor, buf.vbuffer());
}
But i am getting some long errors, and some piece of it are
/usr/include/boost/variant/detail/apply_visitor_unary.hpp:60:43:
required from ‘typename Visitor::result_type
boost::apply_visitor(Visitor&, Visitable&) [with Visitor =
MinMaxVisitor; Visitable =
boost::variant >,
boost::mpl::v_item >,
boost::mpl::v_item
, boost::mpl::v_item >,
boost::mpl::v_item >,
boost::mpl::v_item >,
boost::mpl::v_item
, boost::mpl::v_item
, boost::mpl::v_item
, boost::mpl::v_item
, boost::mpl::v_item
, boost::mpl::vector0, 1>, 1>, 1>, 1>, 1>, 1>, 1>, 1>, 1>, 1>, 1> >, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>;
typename Visitor::result_type = std::vector >]’ read_subimage.C:82:85: required from here
/usr/include/c++/4.8/bits/stl_algo.h:4417:14: error: must use ‘.’ or
‘->’ to call pointer-to-member function in ‘__f (...)’, e.g. ‘(...
->* __f) (...)’
How can i reslove this, I need to get the pixel buffer data into vector .
I'm trying to simply the spirit parser found in this answer:
Boolean expression (grammar) parser in c++
To remove the xor operator and logic. I'm failing to see how to do it, I tried using
expr_ = or_.alias();
or_ = (and__ >> "or" >> or_ )[ _val = phx::construct<binop<op_or >>(_1, _2) ] | and_ [ _val = _1 ];
and_ = (not_ >> "and" >> and_) [ _val = phx::construct<binop<op_and>>(_1, _2) ] | not_ [ _val = _1 ];
not_ = ("not" > simple ) [ _val = phx::construct<unop <op_not>>(_1) ] | simple [ _val = _1 ];
for the rule definitions, but I get a cryptic compiler message that I don't understand:
test\test.cpp `boost::spirit::_2' cannot appear in a constant-expression
If anyone can shed some light, I'd appreciate it.
Here is the log:
compiler: Default compiler Building Makefile:
"D:\Dev-Cpp\test\Makefile.win" Executing make... make.exe -f
"D:\Dev-Cpp\test\Makefile.win" all g++.exe -c test.cpp -o test.o
-I"D:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"D:/Dev-Cpp/include/c++/3.4.2/backward" -I"D:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"D:/Dev-Cpp/include/c++/3.4.2" -I"D:/Dev-Cpp/include"
test.cpp: In constructor `parser<It, Skipper>::parser()':
test.cpp:76: error: `boost::spirit::_1' cannot appear in a
constant-expression test.cpp:76: error: a comma operator cannot
appear in a constant-expression test.cpp:76: error:
`boost::spirit::_2' cannot appear in a constant-expression
test.cpp:76: error: `>>' should be `> >' within a nested template
argument list
test.cpp:77: error: `boost::spirit::_1' cannot appear in a
constant-expression
test.cpp:77: error: a comma operator cannot appear in a
constant-expression test.cpp:77: error: `boost::spirit::_2' cannot
appear in a constant-expression test.cpp:77: error: `>>' should be `>
>' within a nested template argument list
test.cpp:78: error: `boost::spirit::_1' cannot appear in a
constant-expression
test.cpp:78: error: `>>' should be `> >' within a nested template
argument list
test.cpp: In function `int main()': test.cpp:98: error: expected
primary-expression before "auto" test.cpp:98: error: expected `;'
before "auto"
test.cpp:111: error: expected primary-expression before ')' token
test.cpp:111: error: expected `;' before ')' token test.cpp:113:
error: ISO C++ forbids declaration of `f' with no type test.cpp:113:
error: `begin' is not a member of `std' test.cpp:113: error: `input'
undeclared (first use this function) test.cpp:113: error: (Each
undeclared identifier is reported only once for each function it
appears in.) test.cpp:113: error: ISO C++ forbids declaration of `l'
with no type test.cpp:113: error: `end' is not a member of `std'
test.cpp:114: error: `f' cannot appear in a constant-expression
test.cpp:114: error: a function call cannot appear in a
constant-expression test.cpp:114: error: template argument 1 is
invalid test.cpp:114: error: invalid type in declaration before ';'
token
test.cpp:126: error: `f' cannot appear in a constant-expression
test.cpp:126: error: a function call cannot appear in a
constant-expression test.cpp:126: error: template argument 1 is
invalid test.cpp:126: error: ISO C++ forbids declaration of `e' with
no type
test.cpp:128: error: expected primary-expression before '(' token
test.cpp:128: error: `first' has not been declared test.cpp:128:
error: request for member of non-aggregate type before ',' token
test.cpp:128: error: `last' has not been declared test.cpp:128:
error: request for member of non-aggregate type before ')' token
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h: At
global scope:
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h: In
instantiation of `std::iterator_traits<int>':
D:/Dev-Cpp/include/boost/detail/iterator.hpp:83: instantiated from
`boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:509: instantiated from
`boost::InputIterator<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:545: instantiated from
`boost::ForwardIterator<int>'
D:/Dev-Cpp/include/boost/concept/detail/has_constraints.hpp:42:
instantiated from
`boost::concepts::not_satisfied<boost::ForwardIterator<int> >'
D:/Dev-Cpp/include/boost/mpl/if.hpp:67: instantiated from
`boost::mpl::if_<boost::concepts::not_satisfied<boost::ForwardIterator<int>
>, boost::concepts::constraint<boost::ForwardIterator<int> >, boost::concepts::requirement<boost::concepts::failed************boost::ForwardIterator<int>::************>
>' D:/Dev-Cpp/include/boost/concept/detail/general.hpp:56: instantiated from `boost::concepts::requirement_<void
(*)(boost::ForwardIterator<int>)>'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:149: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:129:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:130:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:131:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:132:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:133:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/boost/concept_check.hpp: In instantiation of
`boost::InputIterator<int>':
D:/Dev-Cpp/include/boost/concept_check.hpp:545: instantiated from
`boost::ForwardIterator<int>'
D:/Dev-Cpp/include/boost/concept/detail/has_constraints.hpp:42:
instantiated from
`boost::concepts::not_satisfied<boost::ForwardIterator<int> >'
D:/Dev-Cpp/include/boost/mpl/if.hpp:67: instantiated from
`boost::mpl::if_<boost::concepts::not_satisfied<boost::ForwardIterator<int>
>, boost::concepts::constraint<boost::ForwardIterator<int> >, boost::concepts::requirement<boost::concepts::failed************boost::ForwardIterator<int>::************>
>' D:/Dev-Cpp/include/boost/concept/detail/general.hpp:56: instantiated from `boost::concepts::requirement_<void
(*)(boost::ForwardIterator<int>)>'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:149: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/concept_check.hpp:509: error: no type named
`value_type' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:510: error: no type named
`difference_type' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:511: error: no type named
`reference' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:512: error: no type named
`pointer' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:513: error: no type named
`iterator_category' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp: In function `bool
boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&,
const Skipper&, boost::spirit::qi::skip_flag::enum_type, Attr&) [with
Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]':
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:155: error:
conversion from
`mpl_::failed************(boost::spirit::qi::phrase_parse(Iterator&,
Iterator, const Expr&, const Skipper&,
boost::spirit::qi::skip_flag::enum_type, Attr&) [with Iterator = int,
Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_,
boost::detail::variant::void_>]::error_invalid_expression::************)(bool)'
to non-scalar type `mpl_::assert< false>' requested
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:155: error:
enumerator value for `mpl_assertion_in_line_155' not integer constant
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:164: error: request
for member `parse' in `boost::spirit::compile [with Domain =
boost::spirit::qi::domain, Expr = bool](((const bool&)(+expr)))',
which is of non-class type `bool'
D:/Dev-Cpp/include/boost/concept_check.hpp: In destructor
`boost::ForwardIterator<TT>::~ForwardIterator() [with TT = int]':
D:/Dev-Cpp/include/boost/concept/detail/general.hpp:38:
instantiated from `static void
boost::concepts::requirement<boost::concepts::failed************Model::************>::failed()
[with Model = boost::ForwardIterator<int>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:149: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/concept_check.hpp:548: error: no type named
`iterator_category' in `struct boost::ForwardIterator<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:548: error: `failed' is
not a member of `<declaration error>'
D:/Dev-Cpp/include/boost/concept_check.hpp:553: error: no type named
`reference' in `struct boost::InputIterator<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:554: error: no type named
`reference' in `struct boost::InputIterator<int>'
D:/Dev-Cpp/include/boost/spirit/home/qi/char/char_parser.hpp: In
member function `bool boost::spirit::qi::char_parser<Derived, Char,
Attr>::parse(Iterator&, const Iterator&, Context&, const Skipper&,
Attribute&) const [with Iterator = int, Context = const
boost::spirit::unused_type, Skipper = boost::spirit::unused_type,
Attribute = const boost::spirit::unused_type, Derived =
boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, Char = char, Attr =
char]': D:/Dev-Cpp/include/boost/spirit/home/qi/skip_over.hpp:27:
instantiated from `void boost::spirit::qi::skip_over(Iterator&, const
Iterator&, const T&) [with Iterator = int, T =
boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:169: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/spirit/home/qi/char/char_parser.hpp:68:
error: invalid type argument of `unary *'
D:/Dev-Cpp/include/boost/spirit/home/qi/char/char_parser.hpp:70:
error: invalid type argument of `unary *'
D:/Dev-Cpp/include/boost/concept_check.hpp: In destructor
`boost::InputIterator<TT>::~InputIterator() [with TT = int]':
D:/Dev-Cpp/include/boost/concept_check.hpp:547: instantiated from
`boost::ForwardIterator<TT>::~ForwardIterator() [with TT = int]'
D:/Dev-Cpp/include/boost/concept/detail/general.hpp:38:
instantiated from `static void
boost::concepts::requirement<boost::concepts::failed************Model::************>::failed()
[with Model = boost::ForwardIterator<int>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:149: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/concept_check.hpp:517: error: no type named
`difference_type' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:517: error: `failed' is
not a member of `<declaration error>'
D:/Dev-Cpp/include/boost/concept_check.hpp:518: error: no type named
`iterator_category' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:518: error: `failed' is
not a member of `<declaration error>'
D:/Dev-Cpp/include/boost/concept_check.hpp:521: error: invalid type
argument of `unary *'
make.exe: *** [test.o] Error 1
Execution terminated
You accidentally mistyped and_ as and__.
Changing and__ to and_ will make it compile.
Here's a more cleaned up version, removing the now-unneeded declarations relating to xor:
Edit Also 'backported' for old compilers that don't know about auto, decltype, proper template parsing (>> vs. > >) etc.):
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/variant/recursive_wrapper.hpp>
namespace qi = boost::spirit::qi;
namespace phx = boost::phoenix;
struct op_or {};
struct op_and {};
struct op_not {};
typedef std::string var;
template <typename tag> struct binop;
template <typename tag> struct unop;
typedef boost::variant<var,
boost::recursive_wrapper<unop <op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >
> expr;
template <typename tag> struct binop
{
explicit binop(const expr& l, const expr& r) : oper1(l), oper2(r) { }
expr oper1, oper2;
};
template <typename tag> struct unop
{
explicit unop(const expr& o) : oper1(o) { }
expr oper1;
};
struct printer : boost::static_visitor<void>
{
printer(std::ostream& os) : _os(os) {}
std::ostream& _os;
//
void operator()(const var& v) const { _os << v; }
void operator()(const binop<op_and>& b) const { print(" & ", b.oper1, b.oper2); }
void operator()(const binop<op_or >& b) const { print(" | ", b.oper1, b.oper2); }
void print(const std::string& op, const expr& l, const expr& r) const
{
_os << "(";
boost::apply_visitor(*this, l);
_os << op;
boost::apply_visitor(*this, r);
_os << ")";
}
void operator()(const unop<op_not>& u) const
{
_os << "(";
_os << "!";
boost::apply_visitor(*this, u.oper1);
_os << ")";
}
};
std::ostream& operator<<(std::ostream& os, const expr& e)
{ boost::apply_visitor(printer(os), e); return os; }
template <typename It, typename Skipper = qi::space_type>
struct parser : qi::grammar<It, expr(), Skipper>
{
parser() : parser::base_type(expr_)
{
using namespace qi;
expr_ = or_.alias();
or_ = (and_ >> "or" >> or_ ) [ _val = phx::construct<binop<op_or > >(_1, _2) ] | and_ [ _val = _1 ];
and_ = (not_ >> "and" >> and_) [ _val = phx::construct<binop<op_and> >(_1, _2) ] | not_ [ _val = _1 ];
not_ = ("not" > simple ) [ _val = phx::construct<unop <op_not> >(_1) ] | simple [ _val = _1 ];
simple = (('(' > expr_ > ')') | var_);
var_ = qi::lexeme[ +alpha ];
BOOST_SPIRIT_DEBUG_NODE(expr_);
BOOST_SPIRIT_DEBUG_NODE(or_);
BOOST_SPIRIT_DEBUG_NODE(and_);
BOOST_SPIRIT_DEBUG_NODE(not_);
BOOST_SPIRIT_DEBUG_NODE(simple);
BOOST_SPIRIT_DEBUG_NODE(var_);
}
private:
qi::rule<It, var() , Skipper> var_;
qi::rule<It, expr(), Skipper> not_, and_, or_, simple, expr_;
};
int main()
{
const std::string inputs[] = {
// From the OP:
std::string("(a and b) or ((c and d) or (a and b));"),
std::string("a and b or (c and d or a and b);"),
/// Simpler tests:
std::string("a and b;"),
std::string("a or b;"),
std::string("a or b;"),
std::string("not a;"),
std::string("not a and b;"),
std::string("not (a and b);"),
std::string("a or b or c;"),
std::string("") // marker
};
for (const std::string *i = inputs; !i->empty(); ++i)
{
typedef std::string::const_iterator It;
It f(i->begin()), l(i->end());
parser<It> p;
try
{
expr result;
bool ok = qi::phrase_parse(f,l,p > ';',qi::space,result);
if (!ok)
std::cerr << "invalid input\n";
else
std::cout << "result: " << result << "\n";
} catch (const qi::expectation_failure<It>& e)
{
std::cerr << "expectation_failure at '" << std::string(e.first, e.last) << "'\n";
}
if (f!=l) std::cerr << "unparsed: '" << std::string(f,l) << "'\n";
}
return 0;
}
Output of running this sample is
result: ((a & b) | ((c & d) | (a & b)))
result: ((a & b) | ((c & d) | (a & b)))
result: (a & b)
result: (a | b)
result: (a | b)
result: (!a)
result: ((!a) & b)
result: (!(a & b))
result: (a | (b | c))
I am going a bit nuts trying to figure out why the following won't compile:
#include <iostream>
#include <array>
#include <boost/variant.hpp>
#include <forward_list>
typedef unsigned long long very_long;
typedef boost::variant< int, std::string > variants_type;
typedef std::array< variants_type, 5 > row_type;
typedef std::forward_list<row_type> rows_holder_type;
int main() {
rows_holder_type rows;
row_type row_data;
row_data[0] = 0;
row_data[1] = 0;
row_data[2] = 0;
row_data[3] = 0;
row_data[4] = 0;
rows.push_front(row_data);
}
This is the compiler error I am getting:
/usr/include/testing/test_code.o||In function 'std::array<boost::variant<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>, 5ul>::array(std::array<boost::variant<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>, 5ul> const&)':|
store.cpp:(.text._ZNSt5arrayIN5boost7variantIiSsNS0_6detail7variant5void_ES4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_EELm5EEC2ERKS6_[_ZNSt5arrayIN5boost7variantIiSsNS0_6detail7variant5void_ES4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_S4_EELm5EEC5ERKS6_]+0x31)||undefined reference to 'boost::variant<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>::variant(boost::variant<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&)'|
||=== Build finished: 1 errors, 0 warnings ===|
If I replace:
typedef boost::variant< int, std::string > variants_type;
with:
typedef boost::any variants_type;
The code compiles, but I do not want to use boost::any for performance reasons.
I tested your code with MSVC and gcc 4.7.0. MSVC compiles and links the code fine (of course with #include <string>), but gcc gives a linker error on the last line rows.push_front(row_data);. If you comment that line out, gcc accepts the code. I see no reason why gcc gives a linker error and am concluding that it is a bug with gcc. One workaround on gcc would be to change std::array to std::vector.
(From the error message I assume you are using Code::Blocks with gcc)
I've eliminated extra code and the following example still gives the linker error:
#include <boost/variant.hpp>
#include <array>
int main()
{
std::array<boost::variant<int, double>, 5> row_type1;
std::array<boost::variant<int, double>, 5> row_type2 = row_type1;
}
You're missing #include <string>; other than that your code is fine.
I'm having issues getting a small spirit/qi grammar to compile. i am using boost 1.43 and g++ 4.4.1.
the input grammar header:
the build error seems to be pointing to the definition of the 'instruction' rule, maybe it is the '[sp::_val = sp::_1]' that somehow brokes it but this is more or less based on what the spirit documentation tutorials are doing with the xml node parser
inputGrammar.h
#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.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/foreach.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
namespace sp = boost::spirit;
namespace qi = boost::spirit::qi;
using namespace boost::spirit::ascii;
//using namespace boost::spirit::arg_names;
namespace fusion = boost::fusion;
namespace phoenix = boost::phoenix;
using phoenix::at_c;
using phoenix::push_back;
template< typename Iterator , typename ExpressionAST >
struct InputGrammar : qi::grammar<Iterator, ExpressionAST(), space_type> {
InputGrammar() : InputGrammar::base_type( block ) {
tag = sp::lexeme[+(alpha) [sp::_val += sp::_1]];//[+(char_ - '<') [_val += _1]];
block = sp::lit("block") [ at_c<0>(sp::_val) = sp::_1]
>> "(" >> *instruction[ push_back( at_c<1>(sp::_val) , sp::_1 ) ]
>> ")";
command = tag [ at_c<0>(sp::_val) = sp::_1]
>> "(" >> *instruction [ push_back( at_c<1>(sp::_val) , sp::_1 )]
>> ")";
instruction = ( command | tag ) [sp::_val = sp::_1]; //build error seems to be happening here
}
qi::rule< Iterator , std::string() , space_type > tag;
qi::rule< Iterator , ExpressionAST() , space_type > block;
qi::rule< Iterator , ExpressionAST() , space_type > function_def;
qi::rule< Iterator , ExpressionAST() , space_type > command;
qi::rule< Iterator , ExpressionAST() , space_type > instruction;
};
the test build program:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//my grammar
#include <InputGrammar.h>
struct MockExpressionNode {
std::string name;
std::vector< MockExpressionNode > operands;
typedef std::vector< MockExpressionNode >::iterator iterator;
typedef std::vector< MockExpressionNode >::const_iterator const_iterator;
iterator begin() { return operands.begin(); }
const_iterator begin() const { return operands.begin(); }
iterator end() { return operands.end(); }
const_iterator end() const { return operands.end(); }
bool is_leaf() const {
return ( operands.begin() == operands.end() );
}
};
BOOST_FUSION_ADAPT_STRUCT(
MockExpressionNode,
(std::string, name)
(std::vector<MockExpressionNode>, operands)
)
int const tabsize = 4;
void tab(int indent)
{
for (int i = 0; i < indent; ++i)
std::cout << ' ';
}
template< typename ExpressionNode >
struct ExpressionNodePrinter
{
ExpressionNodePrinter(int indent = 0)
: indent(indent)
{
}
void operator()(ExpressionNode const& node) const {
cout << " tag: " << node.name << endl;
for (int i=0 ; i < node.operands.size() ; i++ ) {
tab( indent ); cout << " arg "<<i<<": "; ExpressionNodePrinter(indent + 2)( node.operands[i]); cout << endl;
}
}
int indent;
};
int test() {
MockExpressionNode root;
InputGrammar< string::const_iterator , MockExpressionNode > g;
std::string litA = "litA";
std::string litB = "litB";
std::string litC = "litC";
std::string litD = "litD";
std::string litE = "litE";
std::string litF = "litF";
std::string source = litA+"( "+litB+" ,"+litC+" , "+ litD+" ( "+litE+", "+litF+" ) "+ " )";
string::const_iterator iter = source.begin();
string::const_iterator end = source.end();
bool r = qi::phrase_parse( iter , end , g , space , root );
ExpressionNodePrinter< MockExpressionNode > np;
np( root );
};
int main() {
test();
}
finally, the build error is the following:
(the full error trace is 20 times bigger than the allowed size for a stackoverflow question, so i posted the full version of it at http://codepad.org/Q74IVCUc)
/usr/bin/make -f nbproject/Makefile-linux_amd64_devel.mk SUBPROJECTS= .build-conf
make[1]: se ingresa al directorio `/home/mineq/NetBeansProjects/InputParserTests'
/usr/bin/make -f nbproject/Makefile-linux_amd64_devel.mk dist/linux_amd64_devel/GNU-Linux-x86/vpuinputparsertests
make[2]: se ingresa al directorio `/home/mineq/NetBeansProjects/InputParserTests'
mkdir -p build/linux_amd64_devel/GNU-Linux-x86
rm -f build/linux_amd64_devel/GNU-Linux-x86/tests_main.o.d
g++ `llvm-config --cxxflags` `pkg-config --cflags unittest-cpp` `pkg-config --cflags boost-1.43` `pkg-config --cflags boost-coroutines` -c -g -I../InputParser -MMD -MP -MF build/linux_amd64_devel/GNU-Linux-x86/tests_main.o.d -o build/linux_amd64_devel/GNU-Linux-x86/tests_main.o tests_main.cpp
from /home/mineq/third_party/boost_1_43_0/boost/spirit/include/phoenix_operator.hpp:11,
from ../InputParser/InputGrammar.h:14,
from tests_main.cpp:14:
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/phoenix/operator/self.hpp: In instantiation of ‘const int boost::phoenix::result_of_assign<MockExpressionNode&, boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&>::size’:
In file included from /home/mineq/third_party/boost_1_43_0/boost/spirit/home/phoenix/operator.hpp:16,
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/phoenix/operator/self.hpp:27: instantiated from ‘const int boost::phoenix::result_of_assign<MockExpressionNode&, boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&>::index’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/phoenix/operator/self.hpp:27: instantiated from ‘boost::phoenix::result_of_assign<MockExpressionNode&, boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&>’
/home/mineq/third_party/boost_1_43_0/boost/mpl/eval_if.hpp:38: instantiated from ‘boost::mpl::eval_if<boost::mpl::or_<boost::phoenix::is_actor<MockExpressionNode&>, boost::phoenix::is_actor<boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&>, mpl_::bool_<false>, mpl_::bool_<false>, mpl_::bool_<false> >, boost::phoenix::re_curry<boost::phoenix::assign_eval, MockExpressionNode&, boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_>, boost::phoenix::result_of_assign<MockExpressionNode&, boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&> >’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/phoenix/operator/self.hpp:69: instantiated from ‘boost::phoenix::assign_eval::result<boost::phoenix::basic_environment<boost::fusion::vector1<boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&>, boost::spirit::context<boost::fusion::cons<MockExpressionNode&, boost::fusion::nil>, boost::fusion::vector0<void> >, bool, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_>, boost::spirit::attribute<0>, boost::spirit::argument<0> >’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/phoenix/core/detail/composite_eval.hpp:89: instantiated from ‘boost::phoenix::detail::composite_eval<2>::result<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::spirit::attribute<0>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >, boost::phoenix::basic_environment<boost::fusion::vector1<boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&>, boost::spirit::context<boost::fusion::cons<MockExpressionNode&, boost::fusion::nil>, boost::fusion::vector0<void> >, bool, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/phoenix/core/composite.hpp:61: instantiated from ‘boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::spirit::attribute<0>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >::result<boost::phoenix::basic_environment<boost::fusion::vector1<boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&>, boost::spirit::context<boost::fusion::cons<MockExpressionNode&, boost::fusion::nil>, boost::fusion::vector0<void> >, bool, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/phoenix/core/actor.hpp:56: instantiated from ‘boost::phoenix::eval_result<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::spirit::attribute<0>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >, boost::phoenix::basic_environment<boost::fusion::vector1<boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&>, boost::spirit::context<boost::fusion::cons<MockExpressionNode&, boost::fusion::nil>, boost::fusion::vector0<void> >, bool, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/phoenix/core/actor.hpp:65: instantiated from ‘boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::spirit::attribute<0>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >::result<boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::spirit::attribute<0>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >(boost::fusion::vector1<boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>&>&, boost::spirit::context<boost::fusion::cons<MockExpressionNode&, boost::fusion::nil>, boost::fusion::vector0<void> >&, bool&)>’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/support/action_dispatch.hpp:44: instantiated from ‘bool boost::spirit::traits::action_dispatch<Component>::operator()(const boost::phoenix::actor<Eval>&, Attribute&, Context&) [with Eval = boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::spirit::attribute<0>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >, Attribute = boost::variant<MockExpressionNode, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_>, Context = boost::spirit::context<boost::fusion::cons<MockExpressionNode&, boost::fusion::nil>, boost::fusion::vector0<void> >, Component = boost::spirit::qi::alternative<boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode(), boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>, boost::fusion::unused_type, boost::fusion::unused_type> >, boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::string(), boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>, boost::fusion::unused_type, boost::fusion::unused_type> >, boost::fusion::nil> > >]’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/action/action.hpp:62: instantiated from ‘bool boost::spirit::qi::action<Subject, Action>::parse(Iterator&, const Iterator&, Context&, const Skipper&, Attribute&) const [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Context = boost::spirit::context<boost::fusion::cons<MockExpressionNode&, boost::fusion::nil>, boost::fusion::vector0<void> >, Skipper = boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, Attribute = const boost::fusion::unused_type, Subject = boost::spirit::qi::alternative<boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode(), boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>, boost::fusion::unused_type, boost::fusion::unused_type> >, boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::string(), boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>, boost::fusion::unused_type, boost::fusion::unused_type> >, boost::fusion::nil> > >, Action = boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::spirit::attribute<0>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >]’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/nonterminal/detail/parser_binder.hpp:33: instantiated from ‘bool boost::spirit::qi::detail::parser_binder<Parser, Auto>::call(Iterator&, const Iterator&, Context&, const Skipper&, mpl_::true_) const [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Skipper = boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, Context = boost::spirit::context<boost::fusion::cons<MockExpressionNode&, boost::fusion::nil>, boost::fusion::vector0<void> >, Parser = boost::spirit::qi::action<boost::spirit::qi::alternative<boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode(), boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>, boost::fusion::unused_type, boost::fusion::unused_type> >, boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::string(), boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>, boost::fusion::unused_type, boost::fusion::unused_type> >, boost::fusion::nil> > >, boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::assign_eval, boost::fusion::vector<boost::spirit::attribute<0>, boost::spirit::argument<0>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > > >, Auto = mpl_::bool_<false>]’
/home/mineq/third_party/boost_1_43_0/boost/spirit/home/qi/nonterminal/detail/parser_binder.hpp:53: instantiated from ‘bool boost::spirit::qi::detail::parser_binder<Parser, Auto>::operator()(Iterator&, const Iterator&, Context&, const Skipper&) const [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Skipper = boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, Context = boost::spirit::context<boost::fusion::cons<MockExpressionNode&, boost::fusion::nil>, boost::fusion::vector0<void> >, Parser = boost::spirit::qi::action<boost::spirit::qi::alternative<boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MockExpressionNode(), boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>, boost::fusion::unused_type, boost::fusion::unused_type> >, boost::fusion::cons<boost::spirit::qi::reference<const boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::string(), boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, boost::spirit::char_encoding::ascii> >, 0l>, boost::fusion::unused_type, boost::fusion::unused_type> >, boost::fusion::nil> > >,
...
... more errors but i had to truncate to fit the 30k limit
make[2]: *** [build/linux_amd64_devel/GNU-Linux-x86/tests_main.o] Error 1
make[2]: se sale del directorio `/home/mineq/NetBeansProjects/InputParserTests'
make[1]: *** [.build-conf] Error 2
make[1]: se sale del directorio `/home/mineq/NetBeansProjects/InputParserTests'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2m 13s)
Your error message tells you that you want to assign a variant<MockExpressionNode, basic_string> to a MockExpressionNode
The relevant lines are 33 and 34;
[...] error: no match for ‘operator=’ [...] boost::variant<MockExpressionNode, std::basic_string [...]
[...] candidates are: MockExpressionNode& MockExpressionNode::operator=(const MockExpressionNode&) [...]
To understand why this happens we have to look at the definitions. From the definition of a Qi rule, the signature of the returned value is defined by a template parameter. Hence
qi::rule< Iterator , ExpressionAST() , space_type > command;
means that the returned type of a command will be an ExpressionAST (i.e. a MockExpressionNode in your case). Similarly
qi::rule< Iterator , std::string() , space_type > tag;
means that tag will be of type string. Combining this with instruction = (command | tag) means that an instruction is either a string or a MockExpressionNode. This is internally stored as a variant<MockExpressionNode, string>. Finally,
qi::rule< Iterator , ExpressionAST() , space_type > instruction;
implies that the returned type of instruction is again an ExpressionAST (i.e. a MockExpressionNode). This requires the failing assignment from the variant held internally to a MockExpressionNode.
To sum up, you have to provide types in your qi::rules that somewhat "match" the types implied by your grammar in the sense that assignment is possible. Despite all the Boost.Spirit magic, C++ is still a statically typed language after all. For the issue at hand, you either have to supply a fitting operator=, or you have to assign the results of the different rules to different types that support implicit conversion. BTW, you have similar type issues for block and command at the moment. Take a careful look at the mini_xml example in the documentation: how to define types for a recursive structure and how different rules assign to different types depending on the defined grammar (especially rules xml and node).
I've got a strange problem with templates and namespaces...
I have the following code which compiles fine..
using namespace boost::multi_index;
template < typename OT, typename KT, KT (OT::* KM)() const, typename KC, typename CMP >
class OrderBook
{
public:
OrderBook() {}
~OrderBook() {}
typedef multi_index_container<
OT,
indexed_by<
ordered_unique<
const_mem_fun< OT, KT, KM >,
KC
>,
ordered_unique<
identity< OT >,
CMP
>
>
> Container;
typedef typename Container::template nth_index< 0 >::type index_0;
typedef typename Container::template nth_index< 1 >::type index_1;
typedef typename index_0::const_iterator const_iterator_0;
typedef typename index_1::const_iterator const_iterator_1;
const_iterator_0 begin0() const { return _container.get<0>().begin(); }
const_iterator_0 end0() const { return _container.get<0>().end(); }
public:
Container _container;
};
However, due to a namespace collision when I insert this code into another project I have to have... (Notice how I've had to remove the using namespace boost::multi_index and manually specify it where needed
template < typename OT, typename KT, KT (OT::* KM)() const, typename KC, typename CMP >
class OrderBook
{
public:
OrderBook() {}
~OrderBook() {}
typedef boost::multi_index::multi_index_container<
OT,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<
boost::multi_index::const_mem_fun< OT, KT, KM >,
KC
>,
boost::multi_index::ordered_unique<
boost::multi_index::identity< OT >,
CMP
>
>
> Container;
typedef typename Container::template nth_index< 0 >::type index_0;
typedef typename Container::template nth_index< 1 >::type index_1;
typedef typename index_0::const_iterator const_iterator_0;
typedef typename index_1::const_iterator const_iterator_1;
const_iterator_0 begin0() const { return _container.get<0>().begin(); }
const_iterator_0 end0() const { return _container.get<0>().end(); }
public:
Container _container;
};
Which gives me the following error from g++.
In member function 'typename boost::multi_index::multi_index_container<OT, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::const_mem_fun<OT, KT, KM>, KC, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::identity<Value>, CMP, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<_CharT> >::nth_index<0>::type::const_iterator OrderBook<OT, KT, KM, KC, CMP>::begin0() const':
error: expected primary-expression before ')' token
In member function 'typename boost::multi_index::multi_index_container<OT, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::const_mem_fun<OT, KT, KM>, KC, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::identity<Value>, CMP, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<_CharT> >::nth_index<0>::type::const_iterator OrderBook<OT, KT, KM, KC, CMP>::end0() const':
error: expected primary-expression before ')' token
Sorry for the long error messages, I did consider cleaning them up but I thought I'd better leave them intact in case I removed something crucial.
I tried this...
typedef typename Container::template boost::multi_index::nth_index< 0 >::type index_0;
typedef typename Container::template boost::multi_index::nth_index< 1 >::type index_1;
and it just made g++ even madder :(
Any ideas?
Prefix get<0>() with template:
const_iterator_0 begin0() const { return _container.template get<0>().begin(); }
const_iterator_0 end0 () const { return _container.template get<0>().end(); }
Similar to typename for dependent types, dependent templates have to be prefixed by template:
struct X {
template<class T> void f();
};
template<class T>
void test() {
T::f<int>(); // ill-formed
T::template f<int>(); // ok
}
// ...
test<X>();
And for the curious, that is §14.2/4:
When the name of a member template
specialization appears after . or ->
in a postfix-expression, or after
nested-name-specifier in a
qualified-id, and the
postfix-expression or qualified-id
explicitly depends on a
template-parameter (14.6.2), the
member template name must be prefixed
by the keyword template. Otherwise the
name is assumed to name a
non-template.
Maybe I can guess that some of these functions are not in the boost::multi_index namespace: indexed_b, ordered_unique, const_mem_fun, or identity