D
D
Dolarun2022-04-07 04:46:44
C++ / C#
Dolarun, 2022-04-07 04:46:44

Why are aliases for template parameters declared in the standard library at the beginning of the class?

The question is in the title. For readability?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2022-04-07
@Dolarun

This is done for several reasons.
First, so that the template parameter can be accessed in other templates. Here, you gave an example with _Сontainerin some iterator. You can imagine that there is some kind of algorithm (function) that takes an iterator and it will need to somehow use the container type (or create a temporary variable, or set the return value type, or somehow check that the container type has some properties).
In this case, the algorithm should receive this one back_insert_iteratorand a dozen other iterators. Therefore, it is impossible to take out the container type into a template parameter and specify it in the iterator type in the function parameter. You look in the source code for this very "_Container" - it will become clear how it is used.
Secondly, sometimes it is done for convenience. For in these templates, the parameters themselves can be hellishly piled up with templates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question