Why can the std::sort receive a function object as one of its parameters?

Advertisement

  • The std::sort function is a template. The programmer is free to enter the sorting algorithm in a function object as an argument.
  • Actually, std::sort takes only one argument, which is the container to be sorted.
  • std::sort operates on a template container. The compiler does not know how to relationally compare the values it contains, so a function must be provided to do the comparison.
  • std::sort will use the parameter function as an error handler. The function will be called if an error occurs.
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Leave a Comment


Share via
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Send this to a friend