Standard C++ Library Class Reference
Warnings
Member function templates are used in all containers provided by the Standard Template Library. An example
of this feature is the constructor for list<T, Allocator> that takes two templated iterators:
template <class InputIterator>
list (InputIterator, InputIterator, const Allocator& = Allocator());
list also has an insert function of this type. These functions, when not restricted by compiler limitations, allow
you to use any type of input iterator as arguments. For compilers that do not support this feature, we provide
substitute functions that allow you to use an iterator obtained from the same type of container as the one you
are constructing (or calling a member function on), or you can use a pointer to the type of element you have in
the container.
For example, if your compiler does not support member function templates you can construct a list in the
following two ways:
int intarray[10];
list<int> first_list(intarray,intarray + 10);
list<int> second_list(first_list.begin(),first_list.end());
But not this way:
list<long> long_list(first_list.begin(),first_list.end());
since the long_list and first_list are not the same type.
Additionally, list provides a merge function of this type.
template <class Compare> void merge (list<T, Allocator>&,
Compare);
This function allows you to specify a compare function object to be used in merging two lists. In this case, we
were unable to provide a substitute function in addition to the merge that uses the operator< as the default.
Thus, if your compiler does not support member function templates, all list mergers will use operator<.
Also, many compilers do not support default template arguments. If your compiler is one of these, you need to
always supply the Allocator template argument. For instance, you'll have to write:
list<int, allocator>
instead of:
list<int>
See Also
allocator, Containers, Iterators