
On 7/17/05 1:57 AM, "Jonathan Turkanis" <technews@kangaroologic.com> wrote:
Daryle Walker wrote:
I'm writing a class template where the template parameter is a type that should represent real numbers. It started choking when using boost::rational when I needed Boolean conversion, [...]
Before anyone says that's proper, realize that boost::rational DOES have "operator not()" defined! This is a surprise to the typical C++ programmer. Either both should be defined, or neither. I think that boost::rational should add a Boolean conversion. (It's a quick fix, and it is critical, so it should be done for this release.)
Off the top of my head, I can't think why it shouldn't be added. However, there might be a good reason I can't think of, and adding the operator could conceivably break existing code, so I don't think it's appropriate to stick it in a few days before release.
Boolean conversions are currently banned, so they couldn't be in existing code. The worry is expressions where a conversion would be higher priority that whatever operation is currently used. The only operations I can think of in that category are other conversions, but a new Boolean conversion can't cause problems because C++ allows at most one user-conversion (i.e. the new operation is of lower priority). If we use a member-pointer and keep the type & values used private, then no one can name the type to grab it directly. The class template already defines equality operators, so we don't have to worry about the member-pointer conversion adding inappropriate operators, especially if we make each version of boost::rational maintain separate Boolean types.
I'll add it to the list of feature requests for 1.34.
I put it in our SourceForge bug tracker as Request ID #1239906, so we won't forget.
In the mean time, maybe you can use != 0 or !!
I have "x != T()" right now, but I want to keep the code clean. Especially since I specified Boolean conversion as a requirement. (I didn't know about boost::rational's deficiency at first.) -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com