Quick Q: Why doesn't std::sort accept its comparator by reference? -- StackOverflow

Quick A: By design, because function objects are expected to be nonstateful values.

Recently on SO:

Why doesn't std::sort accept comparator by reference?

The standard on std::reference_wrapper explains that std::sort now accepts std::reference_wrapper, allowing one to pass a comparator by reference.

Is there a reason std::sort didn't accept the comparator by reference in the first place?

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.