Better HN
topnewbestaskshowjobs
Log inSign up

baobab

1 karma · joined May 17, 2012 (14y ago) · 2 submissions

New York, NY
Submissions

comment 13y ago · link · parent

With explicit conversion operators you can fix this: "if (-0.5 <= x <= 0.5) return 0;" for x that are not built-in types. You would need to create your own Bool type, something like defined below, and overload <= operators for x type, returning Bool. This way you will get compile time error.

class Bool { bool value; public: Bool(bool v) : value(v) {} explicit operator bool () { return value; } };

comment 14y ago · link · parent

I couldn't bear looking at how bloated C++ implementation is, so I implemented it in C++11 based on boost.fiber library: https://gist.github.com/4015306. Now it looks very similar to Go language code.