My goal is to create an API interface that looks like that this:
struct myAB{ int a,b; };
void function(myAB ab) {}
...
function({.a = 1, .b = 3});
The above works just fine. But if I want struct AB to have a templated type, CTAD fails.
template <class B>
struct myAB2{ int a; B b; };
template<typename B> myAB2(int, B) -> myAB2<B>;
template<typename B>
void function2(myAB2<B> ab) {}
...
myAB2 ab = {.a = 1, .b = 3}; //works just fine with CTAD
function2(ab); //fine as expected
function2(myAB2{.a = 1, .b = 3}); //works just fine with CTAD
function2({.a = 1, .b = 3}); //fails to compile, can't deduce type 'B'
Why does CTAD fail in the last case? Is there anything I can do to get it to succeed?