
Daniel James wrote:
On 17 April 2012 15:37, Stewart, Robert <Robert.Stewart@sig.com> wrote:
I suppose the big question is, which implicit casts should considered suitable. IIUC your solution has the advantage of only banning certain implicit casts.
Right. By restricting the set of types that are supported to the exact types mentioned, there can be no implicit conversions to those types. Nevertheless, the primary specialization can permit implicit conversions for UDTs.
Even if I wanted to avoid SFINAE, I could probably write a type trait to detect them that doesn't rely on it.
By that I presume you mean that you would use a trait to dispatch to other functions/function templates that avoid the bool conversion problem, right?
I'm not sure if an implicit cast to a class' hash_function would always be considered safe. For example, someone might supply a lossy implicit conversion to std::string.
Implicit conversions cause all manner of problems. They are rarely a good idea, so I doubt you should worry about that. Besides, the function template can be specialized for such a class when the implicit conversion causes undesirable hashing.
You could also use std::numeric_limits<T>::is_specialized to detect a possibly larger set of types to which overloads in the details namespace could be applied.
That's an interesting idea regardless of this issue. But I'm not sure how much you can infer from a numeric_limits specialisation. My worry is that someone might specialise it for a class that gives the hash function problems, something like a big int perhaps.
The function template can be, and very likely should be, specialized for the big int type, so any issues can be rectified, though not prevented with that approach. _____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com ________________________________ IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.