Yes I agree with you. Thank you for your comments! I need to be able to define a restriction list (closed set of types) either by using/extending existing syntax or coming up with something brand new, preferably the former. I was looking at Constraints (https://en.cppreference.com/w/cpp/language/constraints) but I don't have anything concrete using that yet.

On Thu, Jun 13, 2019 at 9:34 AM Matthew Woehlke <mwoehlke.floss@gmail.com> wrote:
On 27/04/2019 09.46, Ritwik Das via Std-Discussion wrote:
> I am not sure I understand what you mean by “class type is complete”.

Practically speaking, "before the '}' of the class definition". IOW, the
set of instantiations must be specified *inside* of the class
definition, and becomes fixed upon the '}' of the class definition.

I think what you really want isn't a virtual template, but a way to
define an overload set which takes one or more type-variable parameters
which "act like" template type parameters for the purpose of the
definition, but where the overload set is otherwise just a set of
non-template functions.

IOW, you want this (strawman syntax):

  <template restrict typename A, restrict typename B
   : for A -> {int, float}
   : for B -> {int, float}>
  void foo(A a, B b)
  {
    ...
  }

...to be equivalent to this:

  void foo(int a, int b)
  {
    ...
  }
  void foo(float a, int b)
  {
    ...
  }
  void foo(int a, float b)
  {
    ...
  }
  void foo(float a, float b)
  {
    ...
  }

This should also allow me to write e.g.:

  <template restrict typename T : for T -> {...}>
  virtual void foo(T) = 0;

This lets me give a single definition, like a template would, but I'm
not actually writing a template. It's just shorthand for a set of
overloads with "similar" definitions (where "similar" is defined as the
definitions being equivalent to template instantiations).

I think this could actually be useful, and may be worth pursuing.

--
Matthew


--

Ritwik Das