Модераторы: bsa
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> boost::spirit::qi semantic action и c++0x лямбда, как корректно передать лямбу в action 
V
    Опции темы
rudvil
Дата 31.12.2010, 18:04 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 155
Регистрация: 20.11.2009
Где: Latvia/Riga

Репутация: 1
Всего: 3



Есть правило в boost::spirit::qi, как корректно передать action'у лямбду?
Код
some_rule = "some_string" >> another_rule[
[](){std::cout << "qwerty";}
];

Код выше не работает
Цитата

c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.5.1/../../../../include/boost/spirit/home/support/action_dispatch.hpp:29:13: error: no match for call to '(const test<Iterator>::test() [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]::<lambda()>) (std::basic_string<char>&, boost::spirit::context<boost::fusion::cons<boost::fusion::unused_type&, boost::fusion::nil>, boost::fusion::vector0<> >&, bool&)'
main.cc:69:53: note: candidate is: test<Iterator>::test() [with Iterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]::<lambda()>
как это исправить?
--------------------
xor
PM MAIL Skype   Вверх
kosmonaFFFt
Дата 2.1.2011, 14:06 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 538
Регистрация: 14.4.2008
Где: Иннополис

Репутация: нет
Всего: 5



А в опциях компилятора задана поддержка c++0x?


--------------------
user posted image
PM MAIL ICQ   Вверх
rudvil
Дата 2.1.2011, 16:11 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 155
Регистрация: 20.11.2009
Где: Latvia/Riga

Репутация: 1
Всего: 3



Цитата(kosmonaFFFt @ 2.1.2011,  14:06)
А в опциях компилятора задана поддержка c++0x?

конечно...
--------------------
xor
PM MAIL Skype   Вверх
null56
Дата 2.1.2011, 17:07 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 721
Регистрация: 19.3.2008

Репутация: нет
Всего: 12



rudvil, приведи больше кода.... он вроде ругается на const перед test
PM MAIL   Вверх
rudvil
Дата 2.1.2011, 17:26 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 155
Регистрация: 20.11.2009
Где: Latvia/Riga

Репутация: 1
Всего: 3



Самый простой пример
Код
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>

#include <iostream>
#include <string>

template <typename Iterator>
bool parse_numbers(Iterator first, Iterator last) {
  bool result = boost::spirit::qi::phrase_parse(
                                                first,
                                                last,
                                                boost::spirit::qi::double_
                                                [
                                                [](double val) {std::cout << val << "\n";} // LAMBDA!!!
                                                ],
                                                boost::spirit::ascii::space
                                                );
  if (first != last)
    return false;
  return result;
}

int main(int argc, char* argv[]) {
  std::string str = "1234";
  if (parse_numbers(str.begin(), str.end())) {
    std::cout << "OK" << std::endl;
  } else {
    std::cout << "FAIL" << std::endl;
  }
  return 0;
}

получаем
Цитата
In file included from boost/spirit/home/qi/action/action.hpp:21:0,
                 from boost/spirit/home/qi/action.hpp:14,
                 from boost/spirit/home/qi.hpp:14,
                 from boost/spirit/include/qi.hpp:16,
                 from source.cpp:3:
boost/spirit/home/support/action_dispatch.hpp: In member function 'bool boost::spirit::traits::action_dispatch<Component>::operator()(const F&, Attribute&, Context&) [with F = parse_numbers(Iterator, Iterator) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]::<lambda(double)>, Attribute = double, Context = const boost::fusion::unused_type, Component = boost::spirit::qi::real_parser_impl<double, boost::spirit::qi::real_policies<double> >]':
boost/spirit/home/qi/action/action.hpp:67:17:   instantiated from 'bool boost::spirit::qi::action<Subject, Action>::parse(Iterator&, const Iterator&, Context&, const Skipper&, Attribute&) const [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, Context = const boost::fusion::unused_type, 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::real_parser_impl<double, boost::spirit::qi::real_policies<double> >, Action = parse_numbers(Iterator, Iterator) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]::<lambda(double)>]'
boost/spirit/home/qi/detail/parse.hpp:84:13:   instantiated from 'static bool boost::spirit::qi::detail::phrase_parse_impl<Expr, typename boost::enable_if<boost::spirit::traits::matches<boost::spirit::qi::domain, Expr> >::type>::call(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, Skipper = 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>, Expr = boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const parse_numbers(Iterator, Iterator) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]::<lambda(double)>&>, 0l> >, 2l>]'
boost/spirit/home/qi/parse.hpp:100:50:   instantiated from 'bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&, const Skipper&, boost::spirit::qi::skip_flag) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, Expr = boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::double_>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<const parse_numbers(Iterator, Iterator) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]::<lambda(double)>&>, 0l> >, 2l>, Skipper = 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>]'
source.cpp:18:49:   instantiated from 'bool parse_numbers(Iterator, Iterator) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]'
source.cpp:26:43:   instantiated from here
boost/spirit/home/support/action_dispatch.hpp:29:13: error: no match for call to '(const parse_numbers(Iterator, Iterator) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]::<lambda(double)>) (double&, const boost::fusion::unused_type&, bool&)'
source.cpp:15:62: note: candidate is: parse_numbers(Iterator, Iterator) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]::<lambda(double)>

Build finished with errors


http://liveworkspace.org/code/ec100e4c6fd6...b9836c526bf4dc6
--------------------
xor
PM MAIL Skype   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "C/C++: Для новичков"
JackYF
bsa

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Вопросы по реализации алгоритмов рассматриваются здесь


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, JackYF, bsa.

 
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C/C++: Для новичков | Следующая тема »


 




[ Время генерации скрипта: 0.0600 ]   [ Использовано запросов: 21 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.