It is common practice to declarate using/typedef of current type inside a template class:
template <typename T1, typename T2 = std::vector<T1>, typename Allocator>
class my_class {
//...
public:
using my_class_t = my_class<T1, T2, Allocator>; //1
my_class_t operator()(); //2
//...
}
I've noticed on my own that it is very comfortable solution to write that using(1) to prevent re-writing complicated type every time one need to - e.g. 2 shows that it can be done easier a lot. My questions:
type, my_class_t, ...)?I'm not aware of any convention providing a name of a class inside the class itself. Since anybody external to the class definition would need to spell out the type somehow before being able to access the nested the nested name it seems not necessary for external users.
For the purpose of the class definition itself it may be useful. There exists a short form to access the instantiation within the class template definition or within member definitions: you can just use the name of the template. That is, your using alias could have been written as
using my_class_t = my_class;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With