Показать сообщение отдельно

  #5285  
Старый 13.05.2010, 15:58
rudvil
Участник форума
Регистрация: 25.08.2008
Сообщений: 187
Провел на форуме:
2066562

Репутация: 86
По умолчанию

Цитата:
Сообщение от Ra$cal  
rudvil
ну тут тока std::for_each, а для связывания проще и удобнее использовать http://www.rsdn.ru/article/cpp/boost.bind.xml
Возникла проблема =/
Код:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <utility>

#include <boost/bind.hpp>

int main(int argc, char* argv[]) {
  typedef std::map<std::string, std::pair<int, int> > map_type;
  map_type files;
  files["0.txt"] = std::make_pair(0, 7);
  files["1.txt"] = std::make_pair(8, 41);
  files["2.txt"] = std::make_pair(42, 50);
  int num = 21;
  map_type::const_iterator elem;
  elem = std::find_if(
                      files.begin(),
                      files.end(),
                      boost::bind(
                                  std::logical_and<bool>(),
                                  boost::bind(
                                              std::greater_equal<int>(),
                                              boost::bind(
                                                          &map_type::value_type::second_type::first_type,
                                                          _1),
                                              num),
                                  boost::bind(
                                              std::less_equal<int>(),
                                              boost::bind(
                                                          &map_type::value_type::second_type::second_type,
                                                          _1),
                                              num)));
  if (elem != files.end())
    std::cout << "Found in " + (*elem).first + "\n";
  return 0;
}
Компилятор ругается
Цитата:
main.cpp:26: error: expected primary-expression before ',' token
main.cpp:32: error: expected primary-expression before ',' token
т.е. на это:
линия (26) &map_type::value_type::second_type::first_type,
и на это:
линия (32) &map_type::value_type::second_type::second_type ,

т.е. как это expected, если с примером который тут http://www.rsdn.ru/article/cpp/boost.bind.xml#EYVAE всё ок(компилирует без ошибок), а тут на тебе...

Последний раз редактировалось rudvil; 13.05.2010 в 16:04..
 
Ответить с цитированием