These are chat archives for symengine/symengine

13th
Nov 2015
Ondřej Čertík
@certik
Nov 13 2015 16:19
@rwst that's true. Besides arithmetic operations and a few other methods, I don't think there is too much to wrap, is it?
@bluescarni what are the rules that you follow with regards to lifetime of references, if you use value semantics? If you access the reference e.g. using the get_piranha_polynomial method above, what are the rules that you follow?
Ralf Stephan
@rwst
Nov 13 2015 16:38
@certik Just FYI, I decided not to use smart pointers at all for the moment. You know, premature optimization...
Francesco Biscani
@bluescarni
Nov 13 2015 21:12
@certik I think that usually I just get the reference from within a function and use it locally. Unless you destroy the object that gave you the reference (which does not seem to be the case usually), there will be no issue.
Maybe it has to do with my coding pattern, I am not claiming that in the general case it's bulletproof
Usually I use getters with references to avoid a potentially expensive copy. So for instance, if I need to access the symbol set of a polynomial inside a method/function I do something like this:
void foo(const polynomial &p)
{
    const auto &s = p.get_symbol_set();
   ...
}
so as long as you are using s only locally, there will be no issue
I agree that if you had to return a reference to s as output of foo() you could have problems, but it seems like in practice I rarely need to do something like that