Skip to content

const conversion with labels #469

@jmh530

Description

@jmh530

There seems to be some weird behavior when you have a function that takes a slice with a const(T)* iterator and try to handle cases with labels. The errors I get as it is is that some of these match multiple functions for reasons that don't quite make sense. I know there's some part of the mir_slice code that converts things to const, but I've never really dug into it to understand how it works.

The code below doesn't have errors when you replace the const(T)* with T*. Alternately, if you replace the int*s with const(int)*s, then the errors go away.

/+dub.sdl:
dependency "mir-algorithm" version="*"
+/


import mir.ndslice.slice;
import mir.ndslice.allocation;
import std.stdio: writeln;


void foo(T)(Slice!(const(T)*, 2u, Contiguous) a)
{
    writeln(typeid(typeof(a)));
    writeln("here0");
}

void foo(T)(Slice!(const(T)*, 2u, Contiguous, int*) a)
{
    writeln(typeid(typeof(a)));
    writeln("here1");
}

void foo(T)(Slice!(const(T)*, 2u, Contiguous, int*, int*) a)
{
    writeln(typeid(typeof(a)));
    writeln("here2");
}

void main()
{
    auto X = slice!double(3, 3);
    auto X1 = slice!(double, int)(3, 3);
    auto X2 = slice!(double, int, int)(3, 3);

    writeln(typeid(typeof(X)));
    foo(X);
    writeln(typeid(typeof(X1)));
    foo(X1); //error
    writeln(typeid(typeof(X2)));
    foo(X2); //error

    writeln("done");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions