I tried finding this myself, but its difficult to describe so I haven't been able to find the answer, although I'm sure its simple... I'm try to learn Intel's threaded building blocks, and as part of the tutorial they have shown the following code:
voidoperator () (const blocked_range <size_t>& r) { // function here}
all this is within a class declaration. I would have included the whole thing but I'm using android and the pdf viewer doesn't let me select text.. in any case I'm not after what it means, just what that particular syntax is doing. is it declaring operator? I have read up and used templates before, but I've just never seen this so I'm stumped...
Declaring methods as const is the way to tell the compiler which methods are safe to call on const object instances. These methods are compiler enforced to not alter the state of the object.
Assuming that this operator overload is a part of "SomeClass"
then the second "const" is saying that this operator can be called on a const instance of type SomeClass.
i.e. the following will work:
1 2 3 4 5 6 7 8 9
int main()
{
blocked_range<size_t> blocked_range_instance;
const SomeClass someClassConstInstance;
someClassConstInstance(blocked_range_instance); //OK. Will not produce compiler error
return 0;
}
If the second const were not there, then the above code would produce a compiler error because you'd be trying to invoke a non-const method of a const object instance.