Skip to content

How can I pass a type to a generic function without adding const? #2615

@vkensou

Description

@vkensou

Hi, I’m trying to pass a type into a generic function and preserve the type exactly as it is.

Here is a simplified example:

def gen_func(t: type<auto(T1)>) {
    print("type: {typeinfo fulltypename(type<T1>)}\n")
}

gen_func(type<int>)  // prints: type: int const
                     // expected: type: int

gen_func(type<int const>)   // prints: type: int const
                            // this matches my expectation

When I call gen_func(type<int>), T1 seems to become int const.
However, I would like it to remain int.

Is there a way to pass the type into the generic function exactly as provided, without automatically adding const?

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