fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <utility>
  4. #include <iterator>
  5.  
  6. template<class Mark, class T>
  7. struct marked_type {
  8. T raw;
  9. marked_type(T&& in):raw(std::forward<T>(in)) {}
  10. };
  11. template<typename Mark, typename T>
  12. marked_type<Mark, T> mark_type( T&& t ) {
  13. return {std::forward<T>(t)};
  14. }
  15.  
  16. struct strange_iteration {};
  17. template<typename T>
  18. auto begin( marked_type<strange_iteration, T> const& container )
  19. -> decltype( std::begin(std::forward<T>(container.raw)) )
  20. {
  21. std::cout << "BEGIN";
  22. return std::begin(std::forward<T>(container.raw));
  23. }
  24. template<typename T>
  25. auto end( marked_type<strange_iteration, T> const& container )
  26. -> decltype( std::end(std::forward<T>(container.raw)) )
  27. {
  28. std::cout << "END";
  29. return std::end(std::forward<T>(container.raw));
  30. }
  31. int main() {
  32. std::string s = "hello world";
  33. for( char c : mark_type<strange_iteration>(s) ) {
  34. std::cout << c;
  35. }
  36. std::cout << "\n";
  37. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
BEGINENDhello world