Added support for down_cast() and made changes in the codebase#1124
Added support for down_cast() and made changes in the codebase#1124certik merged 8 commits intosymengine:masterfrom
Conversation
|
@isuruf Ping. |
|
I think all we need is something like +template <typename To, typename From>
+inline To& down_cast(From &f)
+{
+ SYMENGINE_ASSERT(dynamic_cast<To*>(&f) != NULL);
+ return *static_cast<To*>(&f);
+}EDIT: Ignore above |
|
@certik, |
|
@isuruf why not? Does any compile produce a warning on that code? |
|
@ShikharJ I think so. I think that's also the only casting we do, don't we? |
|
@certik I am not really comfortable with |
|
Don't modify Teuchos. That library we just use as-is, and we assume it is correct. If it has bugs, then we'll report them upstream and they'll get fixed. We use Also do not modify the So I would suggest to only replace |
|
@certik Should I also make the changes when the argument is of a template type? Like the following case: |
|
@ShikharJ I thinks so --- is there a reason not to? |
|
@certik The |
|
@ShikharJ I think |
Follow-up Corrections Follow-up Corrections(1) Preliminary Code Coverage Using down_cast()
|
@isuruf @certik |
certik
left a comment
There was a problem hiding this comment.
I think this looks very good. +1 to merge if tests pass. I left just a minor comment.
| #endif | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Remove this line. The Teuchos library should not be modified.
symengine/symengine_casts.h
Outdated
| inline To down_cast(From *f) // only accept pointers. | ||
| inline To down_cast(From *f) | ||
| { | ||
| // Only accept pointers. |
There was a problem hiding this comment.
@isuruf I must've accidentally made the change. I'll correct it (anyways the build needs to be re-run as Travis had an issue with OSX related jobs previously).
|
@isuruf A final review? |
|
I think that this is good. Thanks @ShikharJ ! |
This is a follow up for PR #746 by Abhimanyu Siwach.
down_cast() has been used in place of static_cast() strictly in places where the arguments were of the type Basic or any of its derived classes.
Please suggest any changes if required.