Files
cbindgen/tests/expectations/euclid.cpp
T
Emilio Cobos Álvarez b2e224354b Use placement new for constructing in tagged unions' helper methods.
Using operator= is not quite sound in presence of destructors and operator
overloading.

It's perfectly fine to assume that the left-hand-side of an operator= expression
is valid memory, however we're using uninitialized memory here, that may not be
the case.

Use placement new to properly construct tagged unions. I don't need this with
any urgency, but it's the right thing to do in presence of complex types, and
the current code seems a bomb waiting to explode :)
2019-05-10 18:15:39 +02:00

102 lines
2.3 KiB
C++

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>
struct LayoutUnit;
struct UnknownUnit;
template<typename T, typename Unit>
struct TypedLength {
T _0;
};
template<typename T>
using Length = TypedLength<T, UnknownUnit>;
using LayoutLength = TypedLength<float, LayoutUnit>;
template<typename T, typename U>
struct TypedSideOffsets2D {
T top;
T right;
T bottom;
T left;
};
template<typename T>
using SideOffsets2D = TypedSideOffsets2D<T, UnknownUnit>;
using LayoutSideOffsets2D = TypedSideOffsets2D<float, LayoutUnit>;
template<typename T, typename U>
struct TypedSize2D {
T width;
T height;
};
template<typename T>
using Size2D = TypedSize2D<T, UnknownUnit>;
using LayoutSize2D = TypedSize2D<float, LayoutUnit>;
template<typename T, typename U>
struct TypedPoint2D {
T x;
T y;
};
template<typename T>
using Point2D = TypedPoint2D<T, UnknownUnit>;
using LayoutPoint2D = TypedPoint2D<float, LayoutUnit>;
template<typename T, typename U>
struct TypedRect {
TypedPoint2D<T, U> origin;
TypedSize2D<T, U> size;
};
template<typename T>
using Rect = TypedRect<T, UnknownUnit>;
using LayoutRect = TypedRect<float, LayoutUnit>;
template<typename T, typename Src, typename Dst>
struct TypedTransform2D {
T m11;
T m12;
T m21;
T m22;
T m31;
T m32;
};
extern "C" {
void root(TypedLength<float, UnknownUnit> length_a,
TypedLength<float, LayoutUnit> length_b,
Length<float> length_c,
LayoutLength length_d,
TypedSideOffsets2D<float, UnknownUnit> side_offsets_a,
TypedSideOffsets2D<float, LayoutUnit> side_offsets_b,
SideOffsets2D<float> side_offsets_c,
LayoutSideOffsets2D side_offsets_d,
TypedSize2D<float, UnknownUnit> size_a,
TypedSize2D<float, LayoutUnit> size_b,
Size2D<float> size_c,
LayoutSize2D size_d,
TypedPoint2D<float, UnknownUnit> point_a,
TypedPoint2D<float, LayoutUnit> point_b,
Point2D<float> point_c,
LayoutPoint2D point_d,
TypedRect<float, UnknownUnit> rect_a,
TypedRect<float, LayoutUnit> rect_b,
Rect<float> rect_c,
LayoutRect rect_d,
TypedTransform2D<float, UnknownUnit, LayoutUnit> transform_a,
TypedTransform2D<float, LayoutUnit, UnknownUnit> transform_b);
} // extern "C"