add tuples::apply

This commit is contained in:
bolero-MURAKAMI 2014-12-14 12:59:51 +09:00
parent a1f6d6ffc3
commit 5ccbc4e903
16 changed files with 280 additions and 52 deletions

View file

@ -17,42 +17,42 @@
namespace sprout {
namespace detail {
template<typename PopIterator, typename SampleIterator, typename Size, typename URNG>
template<typename PopulationIterator, typename SampleIterator, typename Distance, typename URNG>
inline SPROUT_CXX14_CONSTEXPR SampleIterator
sample_impl(
PopIterator first, PopIterator last, std::input_iterator_tag*,
PopulationIterator first, PopulationIterator last, std::input_iterator_tag*,
SampleIterator out, std::random_access_iterator_tag*,
Size n, URNG&& g
Distance n, URNG&& g
)
{
typedef SPROUT_WORKAROUND_DETAIL_UNIFORM_INT_DISTRIBUTION<Size> distribution_type;
typedef SPROUT_WORKAROUND_DETAIL_UNIFORM_INT_DISTRIBUTION<Distance> distribution_type;
typedef typename distribution_type::param_type param_type;
distribution_type dist = {};
Size sample_size = 0;
Distance sample_size = 0;
while (first != last && sample_size != n) {
out[sample_size++] = *first++;
}
for (Size pop_size = sample_size; first != last; ++first, ++pop_size) {
for (Distance pop_size = sample_size; first != last; ++first, ++pop_size) {
param_type const p(0, pop_size);
Size const k = dist(g, p);
Distance const k = dist(g, p);
if (k < n) {
out[k] = *first;
}
}
return out + sample_size;
}
template<typename PopIterator, typename SampleIterator, typename Size, typename URNG>
template<typename PopulationIterator, typename SampleIterator, typename Distance, typename URNG>
inline SPROUT_CXX14_CONSTEXPR SampleIterator
sample_impl(
PopIterator first, PopIterator last, std::forward_iterator_tag*,
PopulationIterator first, PopulationIterator last, std::forward_iterator_tag*,
SampleIterator out, std::output_iterator_tag*,
Size n, URNG&& g
Distance n, URNG&& g
)
{
typedef SPROUT_WORKAROUND_DETAIL_UNIFORM_INT_DISTRIBUTION<Size> distribution_type;
typedef SPROUT_WORKAROUND_DETAIL_UNIFORM_INT_DISTRIBUTION<Distance> distribution_type;
typedef typename distribution_type::param_type param_type;
distribution_type dist = {};
Size unsampled_size = sprout::distance(first, last);
Distance unsampled_size = sprout::distance(first, last);
for (n = NS_SSCRISK_CEL_OR_SPROUT::min(n, unsampled_size); n != 0; ++first ) {
param_type const p(0, --unsampled_size);
if (dist(g, p) < n) {
@ -66,10 +66,10 @@ namespace sprout {
//
// sample
//
template<typename PopIterator, typename SampleIterator, typename Size, typename URNG>
template<typename PopulationIterator, typename SampleIterator, typename Distance, typename URNG>
inline SPROUT_CXX14_CONSTEXPR SampleIterator
sample(PopIterator first, PopIterator last, SampleIterator out, Size n, URNG&& g) {
typedef typename std::iterator_traits<PopIterator>::iterator_category* pop_category;
sample(PopulationIterator first, PopulationIterator last, SampleIterator out, Distance n, URNG&& g) {
typedef typename std::iterator_traits<PopulationIterator>::iterator_category* pop_category;
typedef typename std::iterator_traits<SampleIterator>::iterator_category* sample_category;
return sprout::detail::sample_impl(
first, last, pop_category(),