Zcoin implementation bug enabled attacker to create 548, 000 Zcoins

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 9 04:07:54 PST 2017


On Tuesday, 7 March 2017 at 17:45:13 UTC, Atila Neves wrote:
> write code. Something like "Do you know how to use 
> std::enable_if without looking at cppreference.com? No? Fail." 
> (I'd fail, I _always_ have to look up how to use enable_if. 
> Then again, it _is_ a horrible hacky hack of a hack based on 
> the hack that is SNIFAE).

"std::enable_if" is a hack, but I don't think the underlying 
principle of SFINAE is a hack as such, although it isn't 
principled in C++... SFINAE basically allows deduction and 
pattern matching at some level, which is what turned it into a 
useful programming mechanism. And those can be desirable features.

Of course the syntax isn't great for the casual reader, e.g.:

"template<T, typename std:enable_if_t<T == MyType, int> == 0> ..."

But the crux to making C++ code readable is to use a smaller set 
of general formulations, make those idioms and avoid all the 
alternative ways that are less general.

void_t is kinda neat:

"template<typename T, typename = void_t<>>struct mystuff ..."
"template<typename T> struct mystuff<T, void_t<A> > ..."
"template<typename T> struct mystuff<T, void_t<B> > ..."




More information about the Digitalmars-d mailing list