Skip to content

The Complexities of Templated Member Functions #27

Description

@jszaday

In C++, virtual templated (member) functions are prohibited, meaning templated member functions cannot be overridden nor override non-templated functions. This is a nuanced issue, and one that is not on the standards committee's agenda (nor is it expected to be in the immediate future).

It is a "minor" issue in the context of HPC, but an important one for general usability. So, let us consider this:

class foo {
	def bar<T>(t: T);
}

class baz {
	override def bar<T>(t: T);
}

This is impossible in C++! How could we handle it? Well... we could code gen explicit specializations for all the different intersecting possibilities of these, but that seems complicated. Swift handles this surprisingly deftly, how?

While we could mimic Swift on that front... it does not, however, support explicit specialization... so we can (potentially) handle this where it cannot?

class foo {
	def bar(i: int) { ... };
	def bar(i: uint) { ... };
}

class baz extends foo {
	// what if T is int or uint?
	def bar<T>(t: T) { ... };
	// possible solution: explicit override
	// (type! indicates specialize with type)
	// lack of body implies use default impl
	override def bar<int!>(i: int);
	override def bar<uint!>(i: uint);
}

Regardless, this is complicated to say the least.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions