Closed vmatare closed 8 years ago
I'm not much into const
issues and certainly not a C++ expert. I can only comment on what happens. The results of these methods depend on *this
pointing at a term handle. The term handle is not changed. What it refers to can be modified, causing these functions to return different values, despite the fact that *this
has not changed. So, roughly I'd say this is the same as *this
containing a pointer, where the pointer is never changed, but what is reachable behind it does. Methods like name()
do not change anything. The various unification primitives do.
Sounds like using const
is fine? If nobody comes with a counter argument I'll merge this.
To clarify, I was merely pointing out that even the unification operators could technically be marked const, though this pull request does not do that, for the reason stated above.
Ok. I can't see much wrong with it. I merged it in the devel version. Thanks!
Many methods like
PlTerm::name()
that don't actually modify*this
weren't markedconst
, which made handlingconst PlTerm
(and others) rather unwieldy.This patch addresses [https://github.com/SWI-Prolog/issues/issues/39]. It should allow proper usage of
const
PlTerms without breaking existing code. The supplied test code compiles and runs with it. Still, I'd recommend getting at least one other person's (preferrably a cpp interface user's) opinion on this. Technically, even the unificationoperator =(...)
could be markedconst
since it doesn't modify any class attributes, but I'd find that misleading in that it makes the abstraction more leaky. Not sure what theconst
policy should be on methods that modify the contents of pointer-type attributes.