Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy all array_view members in copy constructor #3811

Merged
merged 3 commits into from Nov 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/numpy_cpp.h
Expand Up @@ -367,17 +367,19 @@ class array_view : public detail::array_view_accessors<array_view, T, ND>
}
}

array_view(const array_view &other, bool contiguous = false) : m_arr(NULL), m_data(NULL)
array_view(const array_view &other) : m_arr(NULL), m_data(NULL)
{
if (!set((PyObject *)other.m_arr)) {
throw py::exception();
}
m_arr = other.m_arr;
Py_XINCREF(m_arr);
m_data = other.m_data;
m_shape = other.m_shape;
m_strides = other.m_strides;
}

array_view(PyArrayObject *arr, char *data, npy_intp *shape, npy_intp *strides)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this ctor also need to specify the member variables?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been awhile since I did heavy C++, but couldn't the copy ctor call the other ctor below for good code reuse?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling ctor's from other ctor's isn't supported since a ctor is special (sets up vtables & stuff). it's perhaps a good idea to call a helper, but that's arguably no better since it would still reference all the actual names of members.

whatever the case about this, travis isn't happy (in ways that really confuse me).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I could have sworn I was able to do something like this using gcc, but maybe I am thinking of subclassing?

In any case, it appears that C++11 added "delegating constructors": http://www-01.ibm.com/support/knowledgecenter/SSGH3R_11.1.0/com.ibm.xlcpp111.aix.doc/language_ref/delegating_ctors.html

Don't know what the compiler support is, but it is nice to know it has a name.

{
m_arr = arr;
Py_INCREF(arr);
Py_XINCREF(arr);
m_data = data;
m_shape = shape;
m_strides = strides;
Expand Down