Open mnaydenov opened 1 year ago
Consider
#feature on interface self #include <iostream> interface IPrint { void print() const { std::cout<< "none\n"; } }; impl double : IPrint { void print() const { std::cout<< self<< "\n"; } }; template<typename T : IPrint> void func(T& obj) { obj.print(); } template void func<double>(double&);
The above will fail to compile with
'print' is not a member of type double obj.print();
Which is the standard template error, essentially bypassing the interface checks.
Same is true when one tries to get the address of an instantiation
auto addr = &func<double>;
Workaround Either call the function: func(x) or decltype the call: using T = decltype(func(x));
func(x)
decltype
using T = decltype(func(x));
Consider
The above will fail to compile with
Which is the standard template error, essentially bypassing the interface checks.
Same is true when one tries to get the address of an instantiation
Workaround Either call the function:
func(x)
ordecltype
the call:using T = decltype(func(x));