title: Thrust Gathering/Filtering
body: <p>What I am trying to do is create a filter on a vector so it removes elements that do not pass a predicate test; but not too sure how I go about it.</p>
  
  <p>I evaluate each element in my inputer vector against the predicate, for example in my code the is_even functor, in a device_vector vector. It is true if it passes the test and false if it's not. </p>
  
  <p>Now I am stuck because I now have this bool vector and I want to gather the elements that passed this predicate test. I store it in a bool vector because I want to keep the result to filter other vectors.</p>
  
  <pre><code>#include ...
  
  template&lt;typename T&gt;
  struct is_even : thrust::unary_function&lt;T, bool&gt;
  {
      __host__ __device__
      bool operator()(const T &amp;x)
      {
          return (x%2)==0;
      }
  };
  
  int main(void)
  {
      std::cout &lt;&lt; "Loading test!" &lt;&lt; std::endl;
      const int N = 1000000;
      thrust::device_vector&lt;int&gt; col1(N);
      thrust::device_vector&lt;float&gt; col2(N, 1); 
      thrust::sequence(col1.begin(), col1.end());
  
      thrust::device_vector&lt;bool&gt; filter(N);
      thrust::transform(col1.begin(), col1.end(), filter.begin(), is_even&lt;int&gt;());
  
      // filter col1 and col2 based on filter
  
      return 0;
  }
  </code></pre>