Quellcode durchsuchen

core: do not use std::swap()

Daniele Bartolini vor 7 Jahren
Ursprung
Commit
5947a1de48

+ 1 - 2
src/core/containers/hash_map.h

@@ -8,7 +8,6 @@
 #pragma once
 
 #include "core/containers/types.h"
-#include <algorithm> // std::swap
 #include <string.h>  // memcpy
 
 namespace crown
@@ -123,7 +122,7 @@ namespace hash_map_internal
 				if (is_deleted(m._index[hash_i].index))
 					goto INSERT_AND_RETURN;
 
-				std::swap(hash, m._index[hash_i].hash);
+				exchange(hash, m._index[hash_i].hash);
 				m._index[hash_i].index = 0x0123abcd;
 				swap(new_item, m._data[hash_i]);
 

+ 2 - 3
src/core/containers/hash_set.h

@@ -6,8 +6,7 @@
 #pragma once
 
 #include "core/containers/types.h"
-#include <algorithm> // std::swap
-#include <string.h>  // memcpy
+#include <string.h> // memcpy
 
 namespace crown
 {
@@ -117,7 +116,7 @@ namespace hash_set_internal
 				if (is_deleted(m._index[hash_i].index))
 					goto INSERT_AND_RETURN;
 
-				std::swap(hash, m._index[hash_i].hash);
+				exchange(hash, m._index[hash_i].hash);
 				m._index[hash_i].index = 0x0123abcd;
 				// swap
 				{

+ 1 - 0
src/core/filesystem/file_monitor_linux.cpp

@@ -17,6 +17,7 @@
 #include <errno.h>
 #include <limits.h> // NAME_MAX
 #include <sys/inotify.h>
+#include <sys/select.h>
 #include <unistd.h> // read
 
 namespace crown

+ 8 - 0
src/core/types.h

@@ -34,6 +34,14 @@ typedef float    f32;
 typedef double   f64;
 /// @}
 
+template <typename T>
+inline void exchange(T& a, T& b)
+{
+	T c = a;
+	a = b;
+	b = c;
+}
+
 } // namespace crown
 
 #if defined(_MSC_VER)

+ 1 - 0
src/core/unit_tests.cpp

@@ -33,6 +33,7 @@
 #include "core/strings/string.h"
 #include "core/strings/string_id.h"
 #include "core/thread/thread.h"
+#include <stdlib.h> // EXIT_SUCCESS, EXIT_FAILURE
 
 #define ENSURE(condition)                                \
 	do                                                   \