Edit: this seems to address perfectly my question.
Regarding Which type trait would indicate that type is memcpy assignable? (tuple, pair)
The answer is that std::is_trivially_copyable
would be able to tell me if I can safely memcpy
around my object.
Now consider:
#include <iostream>
#include <type_traits>
struct A {
int x;
int y;
A(const A& other) : x(other.x), y(other.y){}
};
struct B {
int x;
int y;
B(const B& other) = default;
};
int main()
{
std::cout << std::boolalpha;
std::cout << std::is_trivially_copyable<A>::value << '\n'; //false
std::cout << std::is_trivially_copyable<B>::value << '\n'; //true
}
A
and B
are to all practical effect the same, however A
is detected as not trivially copyable.
So, which risk am I would be taking in memcpy
-ing such an object?
The use case: I would like to have a dynamic array (not vector
, and which I would make grow with realloc
) of cv::Point
in opencv library, which probably because of C++98 compatibility doesn't use default
to define the copy constructor.