How can I loop traverse a graph through const reference in D?

Jairo Andres Velasco Romero

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.

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;
    }
}
Adam D. Ruppe

Sounds like a job for std.typecons.Rebindable:

http://dpldocs.info/experimental-docs/std.typecons.Rebindable.html

import std.typecons;
Rebindable!(const typeof(this)) bag = this;

then the rest should work the same.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I loop traverse a graph through const reference in D?

From Dev

How can I traverse through my result?

From Dev

How can I iterate through a function with for loop?

From Dev

How can I loop through twig data

From Dev

How can I loop through multiple arrays?

From Dev

How can I loop through an array

From Dev

How can i loop through These with A CASE statement?

From Dev

How can I iterate through a function with for loop?

From Dev

how can I make a loop through parsing

From Dev

How do I loop through bar graph elements in webdriver?

From Dev

How can I reference the Form Ext Object through a listener?

From Dev

Why can I bind rvalues to non const reference with a for loop in C++?

From Dev

How can I add edges to my graph in a for loop?

From Dev

How can I access element reference from *ngFor loop element?

From Dev

How can I loop through my array in reverse order?

From Java

How can I loop through enum values for display in radio buttons?

From Dev

How can I loop through a set of strings in Javascript?

From Java

How can I loop through a List<T> and grab each item?

From Dev

How can I loop through an array of JSON objects?

From Dev

How can I loop through values in my json file?

From Dev

How can I loop through two arrays at once?

From Dev

How can I loop through this array and get first elements?

From Dev

How can I loop through subgroups of an OrderedDict in ZPT?

From Dev

How can I loop through all <p> elements?

From Dev

How can I run through three separate arrays in the same for loop?

From Dev

How can I write a loop that cycles through my if statements?

From Dev

How can I loop through multidimensional array without using foreach

From Dev

How can I loop through a data matrix and compute on select rows?

From Dev

How can I loop through my JSON data using javascript?

Related Related

  1. 1

    How can I loop traverse a graph through const reference in D?

  2. 2

    How can I traverse through my result?

  3. 3

    How can I iterate through a function with for loop?

  4. 4

    How can I loop through twig data

  5. 5

    How can I loop through multiple arrays?

  6. 6

    How can I loop through an array

  7. 7

    How can i loop through These with A CASE statement?

  8. 8

    How can I iterate through a function with for loop?

  9. 9

    how can I make a loop through parsing

  10. 10

    How do I loop through bar graph elements in webdriver?

  11. 11

    How can I reference the Form Ext Object through a listener?

  12. 12

    Why can I bind rvalues to non const reference with a for loop in C++?

  13. 13

    How can I add edges to my graph in a for loop?

  14. 14

    How can I access element reference from *ngFor loop element?

  15. 15

    How can I loop through my array in reverse order?

  16. 16

    How can I loop through enum values for display in radio buttons?

  17. 17

    How can I loop through a set of strings in Javascript?

  18. 18

    How can I loop through a List<T> and grab each item?

  19. 19

    How can I loop through an array of JSON objects?

  20. 20

    How can I loop through values in my json file?

  21. 21

    How can I loop through two arrays at once?

  22. 22

    How can I loop through this array and get first elements?

  23. 23

    How can I loop through subgroups of an OrderedDict in ZPT?

  24. 24

    How can I loop through all <p> elements?

  25. 25

    How can I run through three separate arrays in the same for loop?

  26. 26

    How can I write a loop that cycles through my if statements?

  27. 27

    How can I loop through multidimensional array without using foreach

  28. 28

    How can I loop through a data matrix and compute on select rows?

  29. 29

    How can I loop through my JSON data using javascript?

HotTag

Archive