Reputation: 13924
I know the usage of a typedef
, but I do not understand when and how to use this_type
?
template<typename T>
class Foo
{
public:
typedef Foo<T> this_type;
// ...
};
An example of its usage or a link would be very helpful as well.
Upvotes: 1
Views: 171
Reputation: 30606
It would have a very narrow use case, possibly only for clarity and consistency over a code base; this_type
may be a better description than Foo<T>
in code that may otherwise lack context (for whatever reason). As such, it looks more like a personal or company style over any particular technical requirement. It is worth mentioning though that the name Foo
is already applicable.
Another case may be to be clear on the distinction between Foo<T>
and some Foo<U>
- but again, the use would be limited (e.g. converting constructors).
Upvotes: 1