I want a helper function to instantiate a class for me. Currently it cannot compile in clang (though it compiles work in gcc), but I need it to work in clang as well. Currently I'm using clang version 6.0.0-1ubuntu2
.
I'm not sure why it's failing, since gcc is able to detect the type. I tried doing stuff from this post and playing around with it for a while but I keep running into a wall. MCVE available, or you can try it on coliru here:
#include <vector>
using namespace std;
template <typename T, template <typename> typename Container>
struct SomeClass {
SomeClass(const Container<T>& c) {
}
};
template <typename T, template <typename> typename C>
inline auto make_some_class(const C<T>& container) {
return SomeClass<T, C>(container);
}
int main() {
vector<int> ints;
auto stuff = make_some_class(ints);
}
main.cpp:19:18: error: no matching function for call to 'make_some_class'
auto stuff = make_some_class(ints); ^~~~~~~~~~~~~~~
main.cpp:12:13: note: candidate template ignored: substitution failure [with T = int]: template template argument has different template parameters than its corresponding template template parameter
inline auto make_some_class(const C<T>& container) { ^
1 error generated.
std::vector
has two template parameters, not one, and will not matchtemplate<typename> typename Container
in the first place. – Sam Varshavchik-frelaxed-template-template-args
. – Hiroki