Commit 1a868800 authored by Davis King's avatar Davis King

simplified code a little

parent dac02110
...@@ -29,19 +29,8 @@ namespace dlib ...@@ -29,19 +29,8 @@ namespace dlib
cublas_context(const cublas_context&) = delete; cublas_context(const cublas_context&) = delete;
cublas_context& operator=(const cublas_context&) = delete; cublas_context& operator=(const cublas_context&) = delete;
// but is movable // but is movable
cublas_context(cublas_context&& item) cublas_context(cublas_context&& item) : cublas_context() { swap(item); }
{ cublas_context& operator=(cublas_context&& item) { swap(item); return *this; }
handle = item.handle;
item.handle = nullptr;
}
cublas_context& operator=(cublas_context&& item)
{
if (this == &item)
return *this;
handle = item.handle;
item.handle = nullptr;
return *this;
}
cublas_context(); cublas_context();
~cublas_context(); ~cublas_context();
...@@ -50,6 +39,7 @@ namespace dlib ...@@ -50,6 +39,7 @@ namespace dlib
) const { return handle; } ) const { return handle; }
private: private:
void swap(cublas_context& item) { std::swap(handle, item.handle); }
void* handle; void* handle;
}; };
......
...@@ -25,19 +25,8 @@ namespace dlib ...@@ -25,19 +25,8 @@ namespace dlib
cudnn_context(const cudnn_context&) = delete; cudnn_context(const cudnn_context&) = delete;
cudnn_context& operator=(const cudnn_context&) = delete; cudnn_context& operator=(const cudnn_context&) = delete;
// but is movable // but is movable
cudnn_context(cudnn_context&& item) cudnn_context(cudnn_context&& item) : cudnn_context() { swap(item); }
{ cudnn_context& operator=(cudnn_context&& item) { swap(item); return *this; }
handle = item.handle;
item.handle = nullptr;
}
cudnn_context& operator=(cudnn_context&& item)
{
if (this == &item)
return *this;
handle = item.handle;
item.handle = nullptr;
return *this;
}
cudnn_context(); cudnn_context();
~cudnn_context(); ~cudnn_context();
...@@ -46,6 +35,7 @@ namespace dlib ...@@ -46,6 +35,7 @@ namespace dlib
) const { return handle; } ) const { return handle; }
private: private:
void swap(cudnn_context& item) { std::swap(handle, item.handle); }
void* handle; void* handle;
}; };
...@@ -64,19 +54,8 @@ namespace dlib ...@@ -64,19 +54,8 @@ namespace dlib
tensor_descriptor(const tensor_descriptor&) = delete; tensor_descriptor(const tensor_descriptor&) = delete;
tensor_descriptor& operator=(const tensor_descriptor&) = delete; tensor_descriptor& operator=(const tensor_descriptor&) = delete;
// but is movable // but is movable
tensor_descriptor(tensor_descriptor&& item) tensor_descriptor(tensor_descriptor&& item) : tensor_descriptor() { swap(item); }
{ tensor_descriptor& operator=(tensor_descriptor&& item) { swap(item); return *this; }
handle = item.handle;
item.handle = nullptr;
}
tensor_descriptor& operator=(tensor_descriptor&& item)
{
if (this == &item)
return *this;
handle = item.handle;
item.handle = nullptr;
return *this;
}
tensor_descriptor(); tensor_descriptor();
~tensor_descriptor(); ~tensor_descriptor();
...@@ -100,6 +79,8 @@ namespace dlib ...@@ -100,6 +79,8 @@ namespace dlib
private: private:
void swap(tensor_descriptor& item) { std::swap(handle, item.handle); }
void* handle; void* handle;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment