From d88b2575a1b774a79fd36ae2cfb93027c38243aa Mon Sep 17 00:00:00 2001 From: Davis King Date: Mon, 20 Jan 2020 07:57:33 -0500 Subject: [PATCH] Make copying non-const cuda_data_ptrs to const ones nicer. --- dlib/cuda/cuda_data_ptr.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dlib/cuda/cuda_data_ptr.h b/dlib/cuda/cuda_data_ptr.h index ab0be5b62..048ccef44 100644 --- a/dlib/cuda/cuda_data_ptr.h +++ b/dlib/cuda/cuda_data_ptr.h @@ -9,6 +9,7 @@ #include #include +#include namespace dlib { @@ -203,6 +204,16 @@ namespace dlib pdata = cuda_data_void_ptr(n*sizeof(T)); } + cuda_data_ptr( + const cuda_data_ptr::type> &other + ) : num(other.num), pdata(other.pdata) {} + /*! + ensures + - *this is a copy of other. This version of the copy constructor allows + assigning non-const pointers to const ones. For instance, converting from + cuda_data_ptr to cuda_data_ptr. + !*/ + T* data() { return (T*)pdata.data(); } const T* data() const { return (T*)pdata.data(); } @@ -237,6 +248,8 @@ namespace dlib friend cuda_data_ptr static_pointer_cast(const cuda_data_void_ptr &ptr); template friend cuda_data_ptr static_pointer_cast(const cuda_data_void_ptr &ptr, size_t num); + template + friend class cuda_data_ptr; size_t num = 0; cuda_data_void_ptr pdata;