Bengt Gustafsson
2018-11-02 11:31:59 UTC
My naive understanding was that a class template with constructors should
be callable as if it was a function, returning an object of an appropriate
type.
This works but excludes the situation where you in the function case would
have to provide a subset of template parameter values yourself. For class
templates you have to provide all or none.
Here is an example:
template<typename T, typename R> void Foo(R r)
{
}
template<typename T, typename R> class Bar {
public:
Bar(R r) {}
};
int main()
{
Foo<int>(3.14); // Works
Bar<int>(3.14); // Error
}
The Bar construction line does not compile on any of the main compilers,
which I think it should, just as Foo call does.
What is the good reason for not making this consistent?
(Godbolt: https://godbolt.org/z/b_L7bE)
be callable as if it was a function, returning an object of an appropriate
type.
This works but excludes the situation where you in the function case would
have to provide a subset of template parameter values yourself. For class
templates you have to provide all or none.
Here is an example:
template<typename T, typename R> void Foo(R r)
{
}
template<typename T, typename R> class Bar {
public:
Bar(R r) {}
};
int main()
{
Foo<int>(3.14); // Works
Bar<int>(3.14); // Error
}
The Bar construction line does not compile on any of the main compilers,
which I think it should, just as Foo call does.
What is the good reason for not making this consistent?
(Godbolt: https://godbolt.org/z/b_L7bE)
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/945c77c8-18e4-40fe-8880-83346219bec4%40isocpp.org.
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/945c77c8-18e4-40fe-8880-83346219bec4%40isocpp.org.