4

I am writing a code, in which one of the files uses set_intersection function, and the last parameter to this function is supposed to be an inserter. But when I compile the code, I see the following errors:

error C2039: 'inserter' : is not a member of 'std'
error C2873: 'inserter' : symbol cannot be used in a using-declaration
error C3861: 'inserter': identifier not found

Following is the code in the file which uses set_intersection function

#include "Query.h"
#include "TextQuery.h"
#include <set>
#include <algorithm>
#include <iostream>

using std::set;
using std::ostream;
using std::inserter; 
using std::set_intersection;

// returns intersection of its operands' result sets
set<TextQuery::line_no>
AndQuery::eval(const TextQuery& file) const
{
    // virtual calls through the Query handle to get result sets for the operands
    set<line_no> left = lhs.eval(file), 
                 right = rhs.eval(file);

    set<line_no> ret_lines;  // destination to hold results 

    // writes intersection of two ranges to a destination iterator
    // destination iterator in this call adds elements to ret
    set_intersection(left.begin(), left.end(), 
                  right.begin(), right.end(),
                  inserter(ret_lines, ret_lines.begin()));
    return ret_lines;
}
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
user1232138
  • 5,451
  • 8
  • 37
  • 64

2 Answers2

22

You need to include <iterator> header.

Cătălin Pitiș
  • 14,123
  • 2
  • 39
  • 62
12

You forgot to #include <iterator>.

Jon
  • 428,835
  • 81
  • 738
  • 806