-4

insert() for a set takes the parameters: (set::iterator, int) The iterator parameter is optional to enter, and so I assume it must have a default value in its implementation.

Now, aren't parameters with default value supposed to be at the end? shouldn't the insert function be called like: insert(int, set::iterator) or insert(int)?

Or does the implementation use function overloading? If so, why not just use default parameters for this?

Aayush Mahajan
  • 3,856
  • 6
  • 25
  • 32

1 Answers1

3

It is not a default parameter, there are simply multiple function overloads.

std::pair<iterator,bool> insert( const value_type& value );

template< class P >
std::pair<iterator,bool> insert( P&& value );

std::pair<iterator,bool> insert( value_type&& value );

iterator insert( iterator hint, const value_type& value );

iterator insert( const_iterator hint, const value_type& value );

template< class P >
iterator insert( const_iterator hint, P&& value );

iterator insert( const_iterator hint, value_type&& value );

template< class InputIt >
void insert( InputIt first, InputIt last );

void insert( std::initializer_list<value_type> ilist );

insert_return_type insert(node_type&& nh);

iterator insert(const_iterator hint, node_type&& nh);
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218