![](https://csdnimg.cn/release/download_crawler_static/87323989/bg5.jpg)
2. less_than_comparable<T>:要求提供<,可自动实现>、<=、>=
3. addable<T>:要求提供+=,可自动实现+
4. subtractable<T>:要求提供-=,可自动实现-
5. incrementable<T>:要求提供前置++,可自动实现后置++
6. decrementable<T>:要求提供前置--,可自动实现后置--
7. equivalent<T>:要求提供<,可自动实现==,等价语义
8. totally_ordered:全序概念,组合了 equality_comparable 和 less_than_comparable
9. additive:可加减概念,组合了 addable 和 subtractable
10. multiplicative:可乘除概念,组合了 multipliable 和 diviable
11. arithmetic:算术运算概念,组合了 additive 和 multiplicative
12. unit_stoppable:可步进概念,组合了 incrementable 和 decrementable
13. public dereferenceable<T, P, (B)>:解引用操作符,要求提供 operator*,可自
动实现 operator->。P 为 operator->返回类型,一般为 T*
14. public indexable<T, I, R, (B)>:下标操作符,I 为下标类型,要求能够与类型 T
做加法操作,通常为 int;R 是 operator[]的返回值类型,通常是一个类型的
引用。要求提供 operator+(T, I),将自动实现 operator[]
1. 如果只关心类的等价语义,那么就用 equivalent,如果想要精确的比较两个对象的值,
就是用 equality_comprable。相等 equivalent 基于"=="实现,而 equality_comprable 基于
"<"的"!(x<y)&&!(x>y)"实现。
2. 应该总对异常类是用虚继承
3. struct my_exception :
virtual std::exception, // 兼容 C++标准异常
virtual boost::exception
{};
typedef boost::error_info<struct tag_err_no, int> err_no;
typedef boost::error_info<struct tag_err_str, string> err_str;
#include <boost/exception/all.hpp>
try { throw my_exception() << err_no(10); }
catch(my_exception& e)
{
cout << *get_error_info<err_no>(e) << endl;
cout << e.what() << endl;
e << err_str("向异常追加信息,还可再次抛出");
cout << *get_error_info<err_str>(e) << endl;
}
4. 从 exception 派生的异常定义非常简单,没有实现代码,可以很容易建立起一个适合
自己程序的、惊喜完整的异常类体系。只要都是用虚继承,类体系可以任意复杂。