On 28 Feb 2016 at 2:06, Karim Tarabishy wrote:
It's not bad. But you can do better, and *much* better if you use a C++ 1z (17) compiler.
So the better error part is related to using a better compiler? this is not related to how I write my code or it is? It is just I did not pass on an elegant compiler error requirement before and I wanted to know if this is something related to the way I write the template function or just using a better compiler?
You can do better with just C++ 11/14. A simple solution is a static_assert with useful message, but I'd like to hope candidates can do better than that.
"This should fail elegantly and usefully ..."
Think what is actually useful to the end user of the function who has supplied it with a string like input. For example, what if the supplied input is a wchar_t string? What sort of mechanism would allow easy extension and customisation of the types of strings hashable, and what kind of compiler error message would fit in with that?
The "prove" is in bold for a reason: I want to see proof
So I had generated the assembly before and found that there is no assembly code for the function when it is called in a constexpr context, on the other hand it is inlined and code exist when it is called in non constexpr context. So the proof is just uploading the assembly code?
The test being performed is to see if you can prove something categorically or not in a way amenable to automated unit testing. So think "how can I get a computer to prove this" and I'll be pleased. Niall -- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/