From 568c557dde1dbd078a5b4c5b55a95402fcd6c936 Mon Sep 17 00:00:00 2001 From: david33101 <87750900+david33101@users.noreply.github.com> Date: Wed, 21 Jul 2021 15:31:45 +0800 Subject: [PATCH] Update ex13_31.h Function swap(HasPtr&, HasPtr&) is actually never used. The notice is printed because '=' is called. This happens maybe because 'sort' doesn't call swap(HasPtr&, HasPtr&) at all in this situation. --- ch13/ex13_31.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ch13/ex13_31.h b/ch13/ex13_31.h index 1d21d6da..7bfabb79 100644 --- a/ch13/ex13_31.h +++ b/ch13/ex13_31.h @@ -50,6 +50,9 @@ void swap(HasPtr& lhs, HasPtr& rhs) { lhs.swap(rhs); } +//Function swap(HasPtr&, HasPtr&) is actually never used. The notice is printed because '=' is called, and 'sort' doesn't call swap(HasPtr&, HasPtr&) at all. +//I saw a comment that might be the reason: +//swap(HasPtr&, HasPtr&) is used in quicksort, but 'sort' won't use quicksort when there are not enough elements in the container(insertionsort is used instead). bool operator<(const HasPtr& lhs, const HasPtr& rhs) {