Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a safe bool idiom helper in boost? [closed]

25% of programmers work time is spended by checking if the required code already exist.

I'm searching for a base class for implementing the safe bool idiom.

like image 594
Mythli Avatar asked Jul 30 '11 14:07

Mythli


1 Answers

bool_testable<> in Boost.Operators looks promising.

The reference mentions that:

bool_testable provides the antithesis of operator bool, such that the expression if (!p) is valid, whilst also making operator bool safer by preventing accidental conversions to integer types. ... bool_testable<> prevents these accidental conversions by declaring a private conversion operator to signed char, and not defining the body.

like image 137
UncleBens Avatar answered Sep 29 '22 11:09

UncleBens