fork download
  1.  
  2. template <typename InputIterator>
  3. char32_t next_codepoint(InputIterator first, InputIterator last) {
  4. std::array<char,4> units;
  5. int i = 0;
  6. assert(first != last); // replace with an actual throw if you want
  7. while(should_read_one_more(*first)) {
  8. units[i++] = *first;
  9. ++first;
  10. assert(first != last);
  11. }
  12. return codepoint_from(units);
  13. }
  14.  
  15. class istream_unicode_iterator
  16. : boost::iterator_facade<
  17. istream_unicode_iterator,
  18. char32_t,
  19. std::input_iterator_tag> {
  20. istream_unicode_iterator() = default;
  21. istream_unicode_iterator(std::istream& is) : is(&is) {
  22. ++*this;
  23. }
  24.  
  25. char32_t const& dereference() const {
  26. return codepoint;
  27. }
  28.  
  29. void increment() {
  30. if(*is) {
  31. codepoint = next_codepoint(std::istream_iterator{*is}, std::istream_iterator{});
  32. } else {
  33. is = nullptr;
  34. }
  35. }
  36.  
  37. bool equal(istream_unicode_iterator const& that) const {
  38. return is == nullptr && that.is == nullptr;
  39. }
  40.  
  41. private:
  42. std::istream* is = nullptr;
  43. char32_t codepoint;
  44. };
  45.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty