-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a design review, feedback requested before I proceed further. Trying out some use of enable_if to give `Vec3<T>` constructor and assignment from unknown types that "look like" 3-vectors -- they have a `operator[]` that returns a T, and their size is at least 3*sizeof(T). The main idea is that if an app has rolled its own 3-vector class, it can seamlessly construct a Vec3 from it, assign a Vec3 to it, or pass their type as a parameter that expects a Vec3. And if the app's custom 3-vector class employs an equivalent idiom, all those operations will work in the reverse direction. It also works for std::vector, std::array, and even "initializer lists", so all of this would work: // Your app's special snowflake custom 3-vector type. class YourCustomVec3 { ... }; // My library has an API call where I use Imath::Vec3 as a parameter // passing convention, because I don't know about your vector. void myfunc (const Vec3<float>& v) { ... } // All sorts of things people may think of as "a vector" YourCustomVec3 myvec(1, 2, 3); std::array<float,3> arr { 1, 2, 3 }; std::vector<float> stdvec { 1, 2, 3 }; myfunc(yourvec); // ok myfunc(arr); // yep myfunc(stdvec); // hunky-dory myfunc({ 1.0, 2.0, 3.0 }); // yeah, even that This is only prototyped for Vec3 for now, but if you all like this idea, then I will complete the work to do this for the other vector and matrix classes. Signed-off-by: Larry Gritz <[email protected]>
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters