www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18917] New: Default Value for Function-Type Template


          Issue ID: 18917
           Summary: Default Value for Function-Type Template
                    Value-Parameter Causes Conflicts in Instantiation
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: madric gmail.com

Consider the following code snippet of a template class that has 3 paramters,
the 3rd of which is a value-parameter with a function type and has a default

final class BTree(
    KeyT = ValueT,
    const(KeyT) function(ValueT) nothrow pure  nogc KeyF =
        function KeyT(ValueT a) { return a; }) {

  KeyT getKey(ValueT val) {
    return KeyF(val);

When instantiating these templates, the first instantiation sets the value for
the function value-parameter, and subsequent instantiations fail due to
mismatching type.

void main()
    auto btree1 = new BTree!(char);
    auto btree2 = new BTree!(int);  // The error is on this line.

The error is:
onlineapp.d(17): Error: template instance `BTree!int` does not match template
declaration `BTree(ValueT, KeyT = ValueT, const(char) function(char) pure
nothrow  nogc KeyF = function KeyT(ValueT a)
return a;

I believe that `BTree!(char)` and `BTree!(int)` should be recognized as
different types at compile-time that have separate and distinct default values
for the 3rd template-parameter.

May 30 2018