Please follow these guidelines when submitting patches.
Use 4 spaces. Format if as follows:
Never use raw C++ pointers and never use the raw new and delete. Always use the smart pointers provided by symengine_rcp.h (depending on WITH_SYMENGINE_RCP, those are either Teuchos::RCP, or our own, faster implementation), i.e. Ptr and RCP (and do not use the .get() method, only the .ptr() method). In Debug mode, the pointers are 100% safe, i.e. no matter how you use them the code will not segfault, but instead raise a nice exception if a pointer becomes dangling or null. In Release mode, the Ptr is as fast as a raw pointer and RCP is a lot faster, but no checks are done (so the code can segfault).
In the .cpp files you can declare:
and then just use RCP or Ptr.
In the .h header files use the full name like SymEngine::RCP or SymEngine::Ptr.
Initialize as follows:
Never call the naked new, nor use the naked rcp. If available, use the factory functions, e.g. in this case symbol() as follows:
This does the same thing (internally it calls make_rcp), but it is easier to use.
The RCP pointer is released automatically. You never call the naked delete.
Use C++ references for objects that you are not passing around. If the object is not modified, use const A &a:
If it is modified, use A &a (see the first argument):
If the objects are passed around, you have to use RCP. You also need to use RCP whenever you call some function that uses RCP.
Declare functions with two input arguments (and one return value) as follows:
Functions with one input and two output arguments are declared:
and used as follows:
SymEngine objects are always immutable, so you always declare them as const. And RCP is only used with SymEngine's objects, so you always use const RCP<const Integer> &i. But if the Integer was somehow mutable (it's not in SymEngine), you would use const RCP<Integer> &i.
For returning objects from functions, simply declare the return type as RCP<const Basic> as shown above.
You can use dynamic cast as follows:
Never use "implicit imports": using namespace std;.
In cpp files, either use the full name of the symbol (e.g. SymEngine::RCP), or use "explicit import" as follows: using SymEngine::RCP;.
In header files, always use the full name (never import symbols there).