I'm dealing with a lot of coordinate data, think predefined library types
struct Point3d { double x,y,z; };
and the like from Eigen and OpenCV.
Now, the coordinates of each point are expressed in some frame of reference. I'd like the type system to track the frame in which each point is expressed. Something along the lines of
enum Frames { frame1, frame2 };
using Point_1 = TagWrapper<Point3d, frame1>;
using Point_2 = TagWrapper<Point3d, frame2>;
Point3d untagged_pt = ...;
Point_1 pt1 = ...;
Point_2 pt2 = ...;
Transform<frame1, frame2> tf_1_to_2 = ...; // from frame1 to frame2
// Compile time error, pt1 and pt2 are in different frames
auto pt3 = pt1 + pt2;
// Ok!, and typeof(pt4) == Point_2
auto pt4 = (tf_1_to_2 * pt1) + pt2;
// Compile time error, pt2 is not in frame1
auto pt5 = tf_1_to_2 * pt2;
// Ok!, and typeof(pt5) == Point_1
auto pt5 = untagged_pt + pt1;
Preferably I could wrap any type with any "tag" to make it a tagged type. Then all similarly tagged types behave as their untagged types when used with each other, but mixing objects with different tags should be a compile time error. I suppose it would also make sense that the result of operations between an untagged and tagged type becomes tagged.
This is similar to units, but I'd like to turn anything into multiple kinds of mutually exclusive "units". So a TagWrapper<Person, type1>
has the interface of Person
, but won't interact with a TagWrapper<Person, type2>
, for example.