allendaicool / thrust

Automatically exported from code.google.com/p/thrust
Apache License 2.0
0 stars 0 forks source link

resolve partition_copy and stable_partition_copy #157

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Are we confident that these are the right signatures?  If so, I think we should 
promote them from thrust::experimental:: to the thrust:: namespace.

The only question I have is whether the right thing is a 
(InputIterator,OutputIterator) pair as opposed to the 
(ForwardIterator,ForwardIterator) pair.  The stable variant is most naturally 
implemented as a two pass algorithm (otherwise a temp buffer is needed) so the 
input sequence should probably be specified by ForwardIterators.  The output 
sequence could be specified by an OutputIterator, but then we'd need to return 
two OutputIterators (for the middle and end of the output).  However, the 
middle OutputIterator (pointing to the end of the first subsequence) wouldn't 
have any value if it was truly an OutputIterator.

To summarize, while it seems like (ForwardIterator,ForwardIterator) pair might 
be to restrictive, I think it's probably the right choice for these functions.

template<typename ForwardIterator1,
         typename ForwardIterator2,
         typename Predicate>
  ForwardIterator2 partition_copy(ForwardIterator1 first,
                                  ForwardIterator1 last,
                                  ForwardIterator2 result,
                                  Predicate pred);

template<typename ForwardIterator1,
         typename ForwardIterator2,
         typename Predicate>
  ForwardIterator2 stable_partition_copy(ForwardIterator1 first,
                                         ForwardIterator1 last,
                                         ForwardIterator2 result,
                                         Predicate pred);

Original issue reported on code.google.com by wnbell on 17 Jun 2010 at 4:37

GoogleCodeExporter commented 9 years ago
No, we should abide by C++0x:

template <class InputIterator, class OutputIterator1,
          class OutputIterator2, class Predicate>
  pair<OutputIterator1, OutputIterator2>
  partition_copy(InputIterator first, InputIterator last,
                 OutputIterator1 out_true, OutputIterator2 out_false,
                 Predicate pred);

Should be cheap for users to precompute the size of both out_true & out_false 
compared to the cost of partition_copy.

There actually isn't a stable_partition_copy in the STL -- no compelling reason 
to add one right now.

Original comment by jaredhoberock on 17 Jun 2010 at 5:09

GoogleCodeExporter commented 9 years ago
We should recommend stable_partition_copy exist in the standard and provide it 
as well.

Original comment by jaredhoberock on 8 Sep 2010 at 1:19

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 2ef46b6741.

Original comment by jaredhoberock on 8 Sep 2010 at 1:29