泛型编程

来源:互联网 发布:武汉淘宝商学院学费 编辑:程序博客网 时间:2024/06/06 17:06

泛型思维在C++上主要以templates及其相关特性表现出来。如STL,boost。

所谓泛型,具有在多种数据类型上都可操作的含义。

定义抽象的concepts,并根据抽象的concepts来撰写算法和数据结构,是泛型编程的本质。

代码与所处理的对象类型彼此独立;因此,将有泛型算法,泛型对象等等;conceptmodel,refinement泛型思想的关键。

  • types即concept。如Forwarditerator,Unary Function,Forward Container等等
  • modeling是一个type和一组types的关系。如char *是Input iterator的一个model。
  • refinement是两组types直接的关系。如Forward iterator和Input iterator之间的关系
  • 多个model之间没有任何关系,即使它们属于相关联的concepts。
  • inheritance是两个type之间的关系。





原创粉丝点击