Skip to content
Snippets Groups Projects
Commit f5412af5 authored by patavirt's avatar patavirt
Browse files

src: move 'borrow' constructor to private

parent a65ec4d4
No related branches found
No related tags found
No related merge requests found
......@@ -85,7 +85,7 @@ private:
Complex *data = const_cast<Complex *>(z.data());
size_t size = z.size();
return std::move(Vector<Complex>(data, size));
return Vector<Complex>::borrow(data, size);
}
public:
......
......@@ -12,6 +12,12 @@
namespace array {
/**
* Simple vector class capable of handling "borrowed" data.
*
* This is only needed for CppAD compatibility, to avoid copying data.
* Otherwise, we could just use std::vector.
*/
template <class Scalar>
class Vector
{
......@@ -42,6 +48,10 @@ private:
size_ = storage_.size();
}
Vector(Scalar *data, size_t size)
: storage_(), data_(data), size_(size)
{}
public:
Vector()
: storage_(), data_(storage_.data()), size_(storage_.size())
......@@ -73,9 +83,11 @@ public:
other.size_ = other.storage_.size();
}
Vector(Scalar *data, size_t size)
: storage_(), data_(data), size_(size)
{}
static Vector borrow(Scalar *data, size_t size)
{
return Vector(data, size);
}
Vector& operator=(const Vector& other)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment