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

  #5286  
Старый 13.05.2010, 17:10
rudvil
Участник форума
Регистрация: 25.08.2008
Сообщений: 187
С нами: 9320830

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

Я сделал его!!!
Может кому понадобится, вот код - правда он стал, ммм... не таким понятным как тут
Код:
#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::less_equal<int>(),
                                              boost::bind(
                                                          &map_type::value_type::second_type::first,
                                                          boost::bind(
                                                                      &map_type::value_type::second,
                                                                      _1)
                                                          ),
                                              num),
                                  boost::bind(
                                              std::greater_equal<int>(),
                                              boost::bind(
                                                          &map_type::value_type::second_type::second,
                                                          boost::bind(
                                                                      &map_type::value_type::second,
                                                                      _1)
                                                          ),
                                              num)));
  if (elem != files.end())
    std::cout << "Found in " + (*elem).first + "\n";
  return 0;
}
После выполнения мы получим следующее
Цитата:
Found in 1.txt
, т.е. 21 находится между 8 и 41.

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