@@ -465,85 +465,6 @@ class counting_iterator {
465
465
value_type operator *() const { return {}; }
466
466
};
467
467
468
- template <typename OutputIt> class truncating_iterator_base {
469
- protected:
470
- OutputIt out_;
471
- size_t limit_;
472
- size_t count_ = 0 ;
473
-
474
- truncating_iterator_base () : out_(), limit_(0 ) {}
475
-
476
- truncating_iterator_base (OutputIt out, size_t limit)
477
- : out_(out), limit_(limit) {}
478
-
479
- public:
480
- using iterator_category = std::output_iterator_tag;
481
- using value_type = typename std::iterator_traits<OutputIt>::value_type;
482
- using difference_type = std::ptrdiff_t ;
483
- using pointer = void ;
484
- using reference = void ;
485
- using _Unchecked_type =
486
- truncating_iterator_base; // Mark iterator as checked.
487
-
488
- OutputIt base () const { return out_; }
489
- size_t count () const { return count_; }
490
- };
491
-
492
- // An output iterator that truncates the output and counts the number of objects
493
- // written to it.
494
- template <typename OutputIt,
495
- typename Enable = typename std::is_void<
496
- typename std::iterator_traits<OutputIt>::value_type>::type>
497
- class truncating_iterator ;
498
-
499
- template <typename OutputIt>
500
- class truncating_iterator <OutputIt, std::false_type>
501
- : public truncating_iterator_base<OutputIt> {
502
- mutable typename truncating_iterator_base<OutputIt>::value_type blackhole_;
503
-
504
- public:
505
- using value_type = typename truncating_iterator_base<OutputIt>::value_type;
506
-
507
- truncating_iterator () = default ;
508
-
509
- truncating_iterator (OutputIt out, size_t limit)
510
- : truncating_iterator_base<OutputIt>(out, limit) {}
511
-
512
- truncating_iterator& operator ++() {
513
- if (this ->count_ ++ < this ->limit_ ) ++this ->out_ ;
514
- return *this ;
515
- }
516
-
517
- truncating_iterator operator ++(int ) {
518
- auto it = *this ;
519
- ++*this ;
520
- return it;
521
- }
522
-
523
- value_type& operator *() const {
524
- return this ->count_ < this ->limit_ ? *this ->out_ : blackhole_;
525
- }
526
- };
527
-
528
- template <typename OutputIt>
529
- class truncating_iterator <OutputIt, std::true_type>
530
- : public truncating_iterator_base<OutputIt> {
531
- public:
532
- truncating_iterator () = default ;
533
-
534
- truncating_iterator (OutputIt out, size_t limit)
535
- : truncating_iterator_base<OutputIt>(out, limit) {}
536
-
537
- template <typename T> truncating_iterator& operator =(T val) {
538
- if (this ->count_ ++ < this ->limit_ ) *this ->out_ ++ = val;
539
- return *this ;
540
- }
541
-
542
- truncating_iterator& operator ++() { return *this ; }
543
- truncating_iterator& operator ++(int ) { return *this ; }
544
- truncating_iterator& operator *() { return *this ; }
545
- };
546
-
547
468
// <algorithm> is spectacularly slow to compile in C++20 so use a simple fill_n
548
469
// instead (#1998).
549
470
template <typename OutputIt, typename Size , typename T>
0 commit comments