Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ typedef typename classname::template

Tags:

c++

templates

I am not able to parse the meaning of the following line of code:

typedef typename Allocator::template rebind<Mapped>::other mapped_type_allocator;

This is the code for allocator rebinding (line 63 of https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-api-4.5/a00756_source.html)

How is this different from the following?

typedef typename Allocator::rebind<Mapped>::other mapped_type_allocator;
like image 701
btan Avatar asked Oct 14 '16 05:10

btan


1 Answers

typedef typename Allocator::template rebind<Mapped>::other mapped_type_allocator;

This is a templated typedef - it establishes mapped_type_allocator as an alias for a template.


typedef typename Allocator::rebind<Mapped>::other mapped_type_allocator;

This is a typedef for a type. To compile OK, the Mapped would need to be defined/known.


The Allocator::rebind<typename X>::other (as a concept) is expected to define a template, not a type.

like image 100
Adrian Colomitchi Avatar answered Sep 29 '22 07:09

Adrian Colomitchi