If you look at related languages, like C++, where member function templates
cannot be declared virtual, and Rust, where the object safety rules forbid
traits with generic parameters from being made into trait objects, you'll see
that this is a common problem, and that the near term solution is
Sorry to necro... but... Is there a replacement for generic methods as nim
currently stands? I'm currently using a tuple-of-procs approach but it would be
nice to have a better alternative.
Well yes, the problem is that we don't attach methods to a type so when you
write `G[T]` we cannot instantiate every method that "belongs to" `G`. And
methods we don't generate cannot participate in the dispatching process.
Now that I've written that, maybe we can instantiate generics during
> AFAIK removal of generic methods is so that under-the-hood we can switch the
> methods implementation to a vtable
But shouldn't a vtable be able to handle generics that are attached to the base
just fine? For instance, the `Test` class has a vtable with a single slot for
`call`. An
It's delayed not cancelled.
> concepts were deemed to experimental yet to build another key feature on top
Uh that's sad, it would have been nice to have static and runtime polymorphism
coexist nicely within the same mechanism
AFAIK removal of generic methods is so that under-the-hood we can switch the
methods implementation to a vtable (compared to the current dispatch tree) but
we do need a blog post explaining the way forward, i.e. there will be a
replacement.
Regarding generic macros, you cannot use `macro
I'm also a happy user of generic methods. I had originally started with
tuples-of-procs and then moved code over to method.
In theory, yes, macros could give us methods. However, after looking at the
various macro-powered-methods projects, I don't think any of them support
generics. I'm not
> All my relevant projects rely on generics with methods.
Well that's bad, we need to find a solution. In my mind I `method` is better
replaced altogether with a `class` macro that produces a traditional VTable.
Only generic **methods** are deprecated. Generic procs (types, etc.) are not
affected by this.
Yes, generic methods are deprecated:
[https://github.com/nim-lang/Nim/blob/devel/changelogs/changelog_0_20_0.md#changes-affecting-backwards-compatibility](https://github.com/nim-lang/Nim/blob/devel/changelogs/changelog_0_20_0.md#changes-affecting-backwards-compatibility)
I haven't upgraded yet (will do after I ship this next project), Have you
noticed this warning with Generic Procedures?
I just noticed that something as simple as
type
Test[T] = ref object of RootObj
method call[T](t: Test[T]) {.base.} = discard
Run
now generates a warning `generic methods are deprecated`.
All my relevant projects rely on generics with methods
13 matches
Mail list logo