-
Notifications
You must be signed in to change notification settings - Fork 340
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
Design of Matrix class #1089
Comments
Looks like there are some other template functions implemented in source files together with explicit template instantiation, e.g. vroom/src/structures/vroom/tw_route.cpp Lines 1441 to 1504 in 176f57a
What is the intention of this? |
Makes sense. As I understand it, this will allow the direct template instantiation in compilation units using the |
The other explicit template instantiation occurrences ( |
Exactly this. |
This I understand.
A common practice is to implement template functions in header files. This allows the compiler to instantiate the template as needed in translation units and avoids the need for explicit template instantiations. Potential drawbacks include increased compilation time and increased binary size. I did not make myself clear but I meant to ask whether there was any reason to have the implementation in source file (with explicit template instantiation) as opposed to have the implementation in header file. |
I kind of made it this way to keep some level of separation between definition in headers and actual implementation. I have no strong feeling about this though and there are other situations where we moved things to the headers for optimization purposes. Yet, the implementation for |
Done in #1091. |
Looks like the design of
Matrix
class could be improved. Here are some points:Matrix
is a template class, but is only instantiated foruint32_t
(in fact it'sUserCost
,UserDuration
andUserDistance
, but all boil down to the same type).vroom/src/structures/generic/matrix.cpp
Line 36 in 176f57a
UserCost
, which automatically works forUserDuration
andUserDistance
due to all three being an alias foruint32_t
. Adding explicit instantiation for the latter two types for clarity results in compiler error (duplicate explicit instantiation of ‘class vroom::Matrix<unsigned int>’
).I propose to leave
Matrix
as a template class but move the implementation entirely to the header file.The text was updated successfully, but these errors were encountered: