boost zip_iterator и std :: sort

У меня есть два массива значений и ключей одинаковой длины. Я хочу отсортировать массив values ​​ по ключам, используя массив keys в качестве ключей. Мне сказали, что zip-итератор boost - как раз подходящий инструмент для блокировки двух массивов вместе и одновременного выполнения действий с ними.

Вот моя попытка использовать boost :: zip_iterator для решения проблемы сортировки, которая не может быть скомпилирована с gcc . Может ли кто-нибудь помочь мне исправить этот код?

Проблема заключается в строке

std :: sort (boost :: make_zip_iterator (ключи, значения), boost :: make_zip_iterator (keys + N, values ​​+ N));

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <boost/iterator/zip_iterator.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>



int main(int argc, char *argv[])
{
  int N=10;
  int    keys[N];
  double values[N];
  int M=100;

  //Create the vectors.
  for (int i = 0; i < N; ++i)
   {
     keys[i]   = rand()%M;
     values[i] = 1.0*rand()/RAND_MAX;
   }


  //Now we use the boost zip iterator to zip the two vectors and sort them "simulatneously"
  //I want to sort-by-key the keys and values arrays
   std::sort ( boost::make_zip_iterator( keys, values  ), 
               boost::make_zip_iterator( keys+N  , values+N    )
             );
    //The values array and the corresponding keys in ascending order. 
   for (int i = 0; i < N; ++i)
    {
      std::cout << keys[i]   <<  "\t"  << values[i]    << std::endl;  
     }
  return 0;
}

ПРИМЕЧАНИЕ: сообщение об ошибке на компиляция

g++ -g -Wall boost_test.cpp 
boost_test.cpp: In function ‘int main(int, char**)’:
boost_test.cpp:37:56: error: no matching function for call to ‘make_zip_iterator(int [(((unsigned int)(((int)N) + -0x00000000000000001)) + 1)], double [(((unsigned int)(((int)N) + -0x00000000000000001)) + 1)])’
boost_test.cpp:38:64: error: no matching function for call to ‘make_zip_iterator(int*, double*)’
11
задан curiousexplorer 18 February 2012 в 18:24
поделиться