How to specify the template parameters of a template member of a template class?

Consider the following:

1
2
3
4
5
6
7
8
9
10
template<typename T> class Blob
{
public:
	template<typename It>
	Blob(It b, It e) : data(std::make_shared<std::vector<T>>(b,e)) {}


private:
	std::shared_ptr<std::vector<T>> data;
};


What if It cannot be deduced from the constructors arguments? How do you specify it?

1
2
using T = std::vector<int>::iterator;
Blob<int> blob<T>(v.begin(), v.end());


??
this does not compile!
I know the first code compiles.

my question is the following: assume the template parameter It of the constructor wasn't deduced, how could one specify the ctor template??


what does not compile is

1
2
using T = std::vector<int>::iterator;
Blob<int> blob<T>(v.begin(), v.end());


I know in this case the template of the ctor is deduced and there is no problem. My question is ASSUME It WAS NOT deduced, then HOW can we specify it?

If the question is "how do I explicitly specify a constructor's template arguments?" the unfortunate answer is "you can't".
[temp.arg.explicit] has this note:
[Note 4: Because the explicit template argument list follows the function template name, and because constructor templates ([class.ctor]) are named without using a function name ([class.qual]), there is no way to provide an explicit template argument list for these function templates.
— end note]

https://eel.is/c++draft/temp#arg.explicit-8
Last edited on
that's what I was fearing!!

Thank you!!
Topic archived. No new replies allowed.