-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add some perfect forwarding in the Kernel #7373
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to replace the copy in Cartesian_converter with a move, that's good. Getting rid of the move should be possible (instead of directly calling the converter on a double, use an object that has a conversion operator to the exact FT and lazily calls the converter in this operator), but probably not worth it.
6d30744
to
98c4e64
Compare
e1947f4
to
72624bb
Compare
One perfect forwarding is enough.
Successfully tested in CGAL-5.6-Ic-241. 2D version can be added too now. |
Just a proof of concept hack --- a/Cartesian_kernel/include/CGAL/Cartesian_converter.h
+++ b/Cartesian_kernel/include/CGAL/Cartesian_converter.h
@@ -83,6 +83,15 @@ struct Converting_visitor : boost::static_visitor<> {
} // namespace internal
+template<class T2, class C, class T1> struct Marc {
+ CGAL_NO_UNIQUE_ADDRESS C c;
+ T1 const* in;
+ operator T2() const { return c(*in); }
+};
+template<class T2, class C, class T1> Marc<T2,C,T1> marc(C const&c, T1 const&x) {
+ return { c, &x };
+}
+
template < class K1, class K2,
class Converter /*= typename internal::Default_converter<K1, K2>::Type*/>
class Cartesian_converter : public Enum_converter
@@ -292,7 +301,8 @@ public:
operator()(const typename K1::Point_3 &a) const
{
typedef typename K2::Point_3 Point_3;
- return Point_3(c(a.x()), c(a.y()), c(a.z()));
+ typedef typename K2::FT FT;
+ return Point_3(marc<FT>(c, a.x()), marc<FT>(c, a.y()), marc<FT>(c, a.z()));
}
typename K2::Weighted_point_3 When using Cartesian_converter on Point_3 from double to mpq_class, this removes some allocations. I expect it should also help with Gmpq, but not with boost types (I think they don't allocate on move). (NewKernel_d uses a transform_iterator on the coordinates, for a similar effect) |
😢 |
|
... and `CGAL::cpp20::type_identity`.
Compilation errors in CGAL-6.0-Ic-229 |
Compilation error 6.0-Ic-232 VC2017 |
The error is gone in CGAL-6.0-Ic-233 |
Does it mean "fully tested"/"merge-able", or something else? |
It means that MSVC 2017 no longer crashes. It will be tested again tonight. |
Successfully tested in CGAL-6.0-Ic-235 |
VectorC2(const FT &x, const FT &y) | ||
: base(CGAL::make_array(x, y)) {} | ||
: base{x, y} {} | ||
|
||
VectorC2(FT&& x, FT&& y) | ||
: base{std::move(x), std::move(y)} {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC we use 2 overloads instead of perfect forwarding + make_array because make_array doesn't work well enough?
No description provided.