www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - IFTI with template alias fails in D, works in C++

main.d:
----------
struct A(T, int D) {
  this(string ignore){}
}

alias B(T)=A!(T, 1);

void fun1(T)(A!(T,1) a) { }
void fun2(T)(B!T a) { }

unittest{
  auto a=A!(double,1)("a");
  assert(is(typeof(a) == B!double));
  fun1(a);//ok

  fun2!double(a);//ok

  // no IFTI here:
  //fun2(a);//not ok:
  //fun2 cannot deduce function from argument types !()(A!(double, 1)),
candidates are...
}
----------


C++ works fine here:


main.cc:
----------
template<class T, int D>
class A {
};

template <class T>
using B = A<T, 1>;

template <class T>
void fun(B<T> a) { }

void test(){
  A<double,1>a;
  fun(a);
}
----------

I can use a workaround but it makes the code uglier. What's the recommended
way around this?
Could we support this as in C++?
Aug 12 2015