title: How can I loop traverse a graph through const reference in D?
body: <p>I have a loop traversing a graph using a 'const' reference but when I assign my iteration variable I realize that it is non-const then I get nice compiler's complains.</p>
  
  <pre class="lang-d prettyprint-override"><code>class ClassDescriptor
  {
      const string name;
      const TypeInfo type;
      const ClassDescriptor base;
      const IPropertyDescriptor[string] propertiesByName;
  
      IPropertyDescriptor getFlattenProperty(string name)
      {
          // This declaration makes 'const(ClassDescriptor) bag'
          // Note that in this point I can't add ref keyword.
          auto bag = this;
          while(!(bag is null))
          {
              if(name in bag.propertiesByName)
              {
                  return bag.propertiesByName[name];
              }
  
              // This assigment breaks the constness
              bag = bag.base;
          }
  
          return null;
      }
  
      public this(string name, TypeInfo type, ClassDescriptor base, const IPropertyDescriptor[string] propertiesByName)
      {
          this.name = name;
          this.type = type;
          this.base = base;
          this.propertiesByName = propertiesByName;
      }
  }
  </code></pre>