mirror of
				https://github.com/mozilla/gecko-dev.git
				synced 2025-10-31 16:28:05 +02:00 
			
		
		
		
	 11dd9afb58
			
		
	
	
		11dd9afb58
		
	
	
	
	
		
			
			Differential Revision: https://phabricator.services.mozilla.com/D4210 --HG-- extra : moz-landing-system : lando
		
			
				
	
	
		
			43 lines
		
	
	
	
		
			972 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
	
		
			972 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| // Iterator returning by value.
 | |
| template <typename T>
 | |
| struct Iterator {
 | |
|   void operator++();
 | |
|   T operator*();
 | |
|   bool operator!=(const Iterator& other);
 | |
| };
 | |
| 
 | |
| // The template argument is an iterator type, and a view is an object you can
 | |
| // run a for loop on.
 | |
| template <typename T>
 | |
| struct View {
 | |
|   T begin();
 | |
|   T end();
 | |
| };
 | |
| 
 | |
| // With this class, the implicit conversion is a call to the (implicit)
 | |
| // constructor of the class.
 | |
| template <typename T>
 | |
| class ImplicitWrapper {
 | |
|  public:
 | |
|   // Implicit!
 | |
|   ImplicitWrapper(const T& t);
 | |
| };
 | |
| 
 | |
| template <typename T>
 | |
| class OperatorWrapper {
 | |
|  public:
 | |
|   OperatorWrapper() = delete;
 | |
| };
 | |
| 
 | |
| struct SimpleClass {
 | |
|   int foo;
 | |
|   operator OperatorWrapper<SimpleClass>();
 | |
| };
 | |
| 
 | |
| typedef View<Iterator<SimpleClass>> SimpleView;
 | |
| 
 | |
| void ImplicitSimpleClassIterator() {
 | |
|   for (const ImplicitWrapper<SimpleClass>& foo : SimpleView()) {}
 | |
|   for (const ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
 | |
|   for (ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
 | |
| }
 |