为提振:: bool_testable<>搬迁或删除? [英] Was boost::bool_testable<> relocated or removed?

查看:133
本文介绍了为提振:: bool_testable<>搬迁或删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想利用的boost :: bool_testable<> (从Boost.Operators)实施一类安全布尔成语,但最新版本图书馆(1.49,因为这帖子)的似乎并不拥有它了。

I'm trying to leverage boost::bool_testable<> (from Boost.Operators) to implement the safe bool idiom for a class, but the most recent version of the library (1.49 as of this post) doesn't seem to have it anymore.

哪儿去了?有没有一个更好的选择,现在,我只是错过了?

Where did it go? Is there a better alternative available now, and I've just missed it?

我不能使用C ++ 11,因此不能用语言扩展,使安全布尔不必要的。

I'm not able to use C++11 and therefore cannot use the language extensions that render safe bool unnecessary.

推荐答案

这是一个迟到的答案,但我只是很活跃堆栈溢出很短的时间,我刚发现你的问题。我Boost.Operators的维护者和我 bool_testable删除早在2003年12月它可能accidentially被释放。

It's a late answer, but I'm only active on Stack Overflow for a short time and I just found your question. I am the maintainer of Boost.Operators and I removed bool_testable back in December 2003 before it could accidentially be released.

山姆帕廷顿提出的这几个星期前,我把它添加到CVS仓库。它在一开始看起来前途无量,但很快问题在某些scenarious出现了。

Sam Partington proposed it a few weeks earlier and I added it to the CVS repository. It looked promising in the beginning, but soon problems showed up in certain scenarious.

的问题,IIRC,一类 T 派生的boost :: bool_testable&LT; T&GT; 曾与转换检测做。一类可转换为布尔,而不是 INT 应该产生的boost :: is_convertible&LT; T,INT&GT; ::值==虚假,而是,它成为暧昧与你结束了一个失败的编译

The main problem, IIRC, for a class T derived from boost::bool_testable<T> had to do with conversion detection. A class which is convertible to bool, but not to int, should yield boost::is_convertible<T,int>::value == false, but instead, it became ambiguous and you ended up with a compile failure.

此外,还有其他的问题,解决这些问题的一个通常意味着打破另一个。一个例子涉及哪些类型的用户想要显式转换为布尔的自己的运营商INT()

There were also other issues and solving one of them usually implied breaking another. One example involved types where the user wanted explicit conversion to bool and his own operator int().

所以,长话短说,我们从来没有想出如何使它足够强大。如有疑问,好处太小(安〜5行复制粘贴code的)与潜在问题相比,我决定发挥它的安全,所以我删除了。

So, long story short, we never figured out how to make it robust enough. In case of doubt, the benefit was too small (safe ~5 lines of copy-paste code) compared with the potential problems, that I decided to play it safe and hence I removed it.

它已被删除后,这个问题再也没有上来,人们终于开始无论是安全,布尔-成语code复制,粘贴到自己的班级,或(一段时间后),他们开始使用明确的布尔运算符(),因为它变得可用。

After it was removed, the issue never came up again and people eventually started to either copy-paste the Safe-Bool-Idiom code to their classes, or (some time later) they started to use explicit operator bool() as it became available.

这就是说,它是最好的,如果你只是手动复制线。我知道这不是一个优雅的解决方案,我不喜欢复制粘贴要么,但替代品的所有比这更糟糕。

That said, it's best if you just copy the lines manually. I know it's not an elegant solution and I don't like copy-paste either, but the alternatives were all worse than that.

这篇关于为提振:: bool_testable&LT;&GT;搬迁或删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆