[webkit-dev] Do we have a style preference about const member functions?

Maciej Stachowiak mjs at apple.com
Fri Jun 3 09:28:22 PDT 2011


On Jun 3, 2011, at 7:50 AM, Darin Adler wrote:

> On Jun 2, 2011, at 1:32 AM, Ryosuke Niwa wrote:
> 
>> All functions passed to enclosingNodeOfType in htmlediting.cpp are such clients:
>> 
>> Node* enclosingNodeOfType(const Position& p, bool (*nodeIsOfType)(const Node*), EditingBoundaryCrossingRule rule)
>> 
>> It takes a boolean function that takes const pointer to a DOM node.  It is critical that nodeIsOfType does not modify DOM
> 
> This points to a place where const does not work well. Having the single node pointer that is the argument to the function be const does not express “must not modify DOM”.
> 
> If there was some way to express “must not modify DOM” that would be great, but that just expresses “must not modify this DOM node”.
> 
> It happens that the predicate takes a node argument. You could imagine a similar function that takes a Range. You can see that that’s an even clearer. There’s no way to pass a range to a function and also say “must not modify DOM”. I don’t think const is a good way to express this.

Are you referring to the fact that from a const Node* can be used to get non-const pointers to the Node's neighbors in the DOM, or something else?

Regards,
Maciej



More information about the webkit-dev mailing list