[compute] 19/46: Fix vector when used with custom allocator

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Dec 21 18:28:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository compute.

commit afd09bcd7dbe12cd057a71dbb154b8bc9d8bbbe1
Author: Jakub Szuppe <j.szuppe at gmail.com>
Date:   Mon Oct 5 13:27:18 2015 +0200

    Fix vector when used with custom allocator
---
 include/boost/compute/container/vector.hpp | 37 +++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/include/boost/compute/container/vector.hpp b/include/boost/compute/container/vector.hpp
index 9110501..47d649a 100644
--- a/include/boost/compute/container/vector.hpp
+++ b/include/boost/compute/container/vector.hpp
@@ -188,14 +188,29 @@ public:
     }
 
     /// Creates a new vector and copies the values from \p other.
-    vector(const vector<T> &other)
+    vector(const vector &other,
+           command_queue &queue = system::default_queue())
         : m_size(other.m_size),
           m_allocator(other.m_allocator)
     {
         m_data = m_allocator.allocate((std::max)(m_size, _minimum_capacity()));
 
         if(!other.empty()){
-            command_queue queue = default_queue();
+            ::boost::compute::copy(other.begin(), other.end(), begin(), queue);
+            queue.finish();
+        }
+    }
+
+    /// Creates a new vector and copies the values from \p other.
+    template<class OtherAlloc>
+    vector(const vector<T, OtherAlloc> &other,
+           command_queue &queue = system::default_queue())
+        : m_size(other.size()),
+          m_allocator(queue.get_context())
+    {
+        m_data = m_allocator.allocate((std::max)(m_size, _minimum_capacity()));
+
+        if(!other.empty()){
             ::boost::compute::copy(other.begin(), other.end(), begin(), queue);
             queue.finish();
         }
@@ -225,7 +240,7 @@ public:
     }
     #endif // BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
 
-    vector<T>& operator=(const vector<T> &other)
+    vector& operator=(const vector &other)
     {
         if(this != &other){
             command_queue queue = default_queue();
@@ -238,7 +253,7 @@ public:
     }
 
     template<class OtherAlloc>
-    vector<T>& operator=(const std::vector<T, OtherAlloc> &vector)
+    vector& operator=(const std::vector<T, OtherAlloc> &vector)
     {
         command_queue queue = default_queue();
         resize(vector.size(), queue);
@@ -249,7 +264,7 @@ public:
 
     #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
     /// Move-constructs a new vector from \p other.
-    vector(vector<T>&& other)
+    vector(vector&& other)
         : m_data(std::move(other.m_data)),
           m_size(other.m_size),
           m_allocator(std::move(other.m_allocator))
@@ -258,7 +273,7 @@ public:
     }
 
     /// Move-assigns the data from \p other to \c *this.
-    vector<T>& operator=(vector<T>&& other)
+    vector& operator=(vector&& other)
     {
         if(m_size){
             m_allocator.deallocate(m_data, m_size);
@@ -549,7 +564,7 @@ public:
             ::boost::compute::copy_n(&value, 1, position, queue);
         }
         else {
-            ::boost::compute::vector<T> tmp(position, end(), queue);
+            ::boost::compute::vector<T, Alloc> tmp(position, end(), queue);
             resize(m_size + 1, queue);
             position = begin() + position.get_index();
             ::boost::compute::copy_n(&value, 1, position, queue);
@@ -572,7 +587,7 @@ public:
                 const T &value,
                 command_queue &queue)
     {
-        ::boost::compute::vector<T> tmp(position, end(), queue);
+        ::boost::compute::vector<T, Alloc> tmp(position, end(), queue);
         resize(size() + count, queue);
 
         position = begin() + position.get_index();
@@ -601,7 +616,7 @@ public:
                 InputIterator last,
                 command_queue &queue)
     {
-        ::boost::compute::vector<T> tmp(position, end(), queue);
+        ::boost::compute::vector<T, Alloc> tmp(position, end(), queue);
 
         size_type count = detail::iterator_range_size(first, last);
         resize(size() + count, queue);
@@ -642,7 +657,7 @@ public:
     iterator erase(iterator first, iterator last, command_queue &queue)
     {
         if(last != end()){
-            ::boost::compute::vector<T> tmp(last, end(), queue);
+            ::boost::compute::vector<T, Alloc> tmp(last, end(), queue);
             ::boost::compute::copy(tmp.begin(), tmp.end(), first, queue);
         }
 
@@ -661,7 +676,7 @@ public:
     }
 
     /// Swaps the contents of \c *this with \p other.
-    void swap(vector<T> &other)
+    void swap(vector &other)
     {
         std::swap(m_data, other.m_data);
         std::swap(m_size, other.m_size);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/compute.git



More information about the debian-science-commits mailing list