11

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;
btan
  • 421
  • 3
  • 9

2 Answers2

8
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.

Adrian Colomitchi
  • 3,974
  • 1
  • 14
  • 23
8

Here I show the grouping of this declaration on separate lines:

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

The keywords typename and template have spaces after them which may have confused you. For the reason those two keywords were used, see Where and why do I have to put the "template" and "typename" keywords? .

Community
  • 1
  • 1
M.M
  • 138,810
  • 21
  • 208
  • 365