amandini n00b
Joined: 01 Jul 2020 Posts: 33
|
Posted: Wed Nov 27, 2024 8:46 pm Post subject: |
|
|
Hu wrote: | For the sake of minimizing user confusion and subsequent support questions, my preference is that the template do the best validation that it easily can, through a combination of type_traits checks and static_assert statements on those traits. For this case, I would suggest adding static_assert(std::is_trivially_copyable<_Scalar>::value, "_Scalar values must be trivially copyable to use memcpy"); adjacent to that std::memcpy. A block comment could elaborate on how the user can avoid that path for values that are known not to be trivially copyable, such as by setting RequireInitialization=1 in the Eigen::NumTraits specialization (assuming that suffices to redirect the logic to the std::copy path; I am inferring that from your prior post).
If the library requires C++20 or later, it could use requires checks instead of static_assert. Either way, mistakes give the user a clear compile-time error, independent of compiler warning options. |
If I recall correctly, the upcoming Eigen 3.5 release will be C++14 so it is still a long way from C++20 and requires checks.
In any case, will forward this discussion to the developers. |
|