It's great that you provide operator overloads, but it's also nice to have names - The Old New Thing

Open link in next tab

It's great that you provide operator overloads, but it's also nice to have names - The Old New Thing

https://devblogs.microsoft.com/oldnewthing/20230605-00/?p=108289

Avoiding the need to invoke the operator explicitly as a specialized template, among other things.

It's great that you provide operator overloads, but it's also nice to have names - The Old New Thing
See all comments

I agree we should use operator overloading only when it really fits the use case. Especially the function call operator is easily misused.

I don’t completely agree with Raymond Chen here though. Firstly I don’t think providing both an explicit Load() function and the function call operator is the solution. Just keep things simple and obvious: provide Load() and remove the function call operator.

Secondly, why is StorageLoader even a class (or actually a struct here, but we know that’s the same thing in C++)? Unless Raymond is leaving out something essential, there is no state. Just make a function:

template<typename DataType>
LoadFromStorage(StorageOptions<DataType> const* options) {
    // ...
}

This solves all the problems: you can simply call it, even without operator overloading (because it's already a function), and doesn't make it awkward to specify the data type we need. We're writing C++ here, not Java where everything has to be a class even if it doesn't have any reason to be.