泛型编程中的Concept, Model和Policy
A crude explanation
Concept
A set of requirements on a type, e.g. a RandomAccessible concept requires the type implements:operator[] (int) in O(1) time.
Model
When a type meet a concept, it's a model of that concept.
Policy
A unit of behaviour, which can combine with other units of behaviour to build complex classes. For illustration:
template<class T, class StoragePolicy>
class array : public StoragePolicy {
public:
T& operator[](int i) { return data[i]; };
};
// policy 1
template <class T, int N>
class fixed_storage {
T data[N];
};
// policy 2
template<class T>
class dynamic_storage{
T* data;
public:
void push_back(const T& val) {
// code for dynamic array insertationk
}
};
usage of policy:
int main(){
array<int, fixed_storage<int, 10>> fixed_array;
array<int, dynamic_storage<int>> dynamic_array;
}
Reference
More
- Boost - Generic Programming Techniques
- Wiki: Policy-based design
- Wiki: Concept (generic programming)
- Andrei Alex's book: 《Modern C++ Design : Generic Programming and Design Patterns Applied》
泛型编程中的Concept, Model和Policy的更多相关文章
- CI中的控制器中要用model中的方法,是统一写在构造器方法中,还是在每一个方法中分别写
Q: CI中的控制器中要用model中的方法,是统一写在构造器方法中,还是在每一个方法中分别写 A: 建议统一写,CI框架会自动识别已经加载过的类,所以不用担心重复加载的问题 class C_User ...
- .NET中 DAL+IDAL+Model+BLL+Web是什么意思
在.NET中 DAL+IDAL+Model+BLL+Web是什么意思 http://hi.baidu.com/hexiaojian/item/8d0c1a8e648546d75e0ec1e7 其实三层 ...
- 推荐系统中的Graph Model
转自:http://www.cnblogs.com/wentingtu/archive/2012/05/28/2521166.html 推荐中对graph model的研究主要有两个方面,一个是如何构 ...
- 008.Adding a model to an ASP.NET Core MVC app --【在 asp.net core mvc 中添加一个model (模型)】
Adding a model to an ASP.NET Core MVC app在 asp.net core mvc 中添加一个model (模型)2017-3-30 8 分钟阅读时长 本文内容1. ...
- Spring框架中ModelAndView、Model、ModelMap区别
原文地址:http://www.cnblogs.com/google4y/p/3421017.html SPRING框架中ModelAndView.Model.ModelMap区别 注意:如果方法 ...
- SPRING框架中ModelAndView、Model、ModelMap区别及详细分析
转载内容:http://www.cnblogs.com/google4y/p/3421017.html 1. Model Model 是一个接口, 其实现类为ExtendedModelMap,继承了M ...
- keil中的memory model
这两天仿真遇到的怪事真的是一大堆. 还是读写Flash的代码.keil编译OK,但是仿真就是莫名其妙地挂掉出现一些乱七八糟的事情. 后面发现是keil 中的memory model勾选错了,勾选的是l ...
- Spring框架中ModelAndView、Model、ModelMap区别 (转)
原文地址:http://www.cnblogs.com/google4y/p/3421017.html SPRING框架中ModelAndView.Model.ModelMap区别 注意:如果方法 ...
- MVC中@Html.DisPlayFor(model=>model.newsName)和 @Model.newsName的区别
MVC中,在Controllers查询到数据,返回一个实体给View并显示,可以用@Html.DisPlayFor(model=>model.newsName)和 @Model.newsName ...
随机推荐
- 追加addclass和removeclass
//addclass Base.prototype.addclass=function(classname){ for(var i=0;i< ...
- CDZSC_2015寒假新人(1)——基础 d
Description These days, I am thinking about a question, how can I get a problem as easy as A+B? It i ...
- 认识Java里面的Thread
在一个特定的主线程执行的过程中,如果我们还需要在主线程的过程中插播一个线程,做其他动作.那么我们就可以利用Java的Thread类,创建一个新的线程. 一:线程简单实现的三种方式 (1)第一种创建线程 ...
- 【Heritrix基础教程之2】Heritrix基本内容介绍
1.版本说明 (1)最新版本:3.3.0 (2)最新release版本:3.2.0 (3)重要历史版本:1.14.4 3.1.0及之前的版本:http://sourceforge.net/projec ...
- eclipse tomcat内存设置
-Xms256M -Xmx512M -XX:PermSize=256m -XX:MaxPermSize=512m
- Elevator(hdoj 1008)
Problem Description The highest building in our city has only one elevator. A request list is made u ...
- 多个项目使用NET Core
.NET Core系列 :3 .使用多个项目 通过前面的两篇文章,我们已经知道如何创建新的项目,如何生成并运行我们的应用程序,也知道(大致) project.json 文件中的内容是什么意思.但大 ...
- 如何测试私有 Private/Internal 方法
在实际开发中,经常会遇到这样的情况. 一个共有的 Public 方法实现某一主要功能,但是由于该功能的实现非常复杂,需要很多的辅助类,辅助方法.由于代码封装性的需求,我们通常需要把这些辅助的类方法定义 ...
- LogLog
https://github.com/rsyslog https://github.com/beave/sagan http://www.securitywarriorconsulting.com/l ...
- Delphi控件大全:www.vclcomponents.com
torry的排版不行了,还好找到它.