官术网_书友最值得收藏!

Concrete monomorphic functions

What distinguishes an abstract algorithm from a concrete function? This is best shown by example. Let's write a function to multiply each of the elements in an array by 2:

    class array_of_ints {
int data[10] = {};
public:
int size() const { return 10; }
int& at(int i) { return data[i]; }
};

void double_each_element(array_of_ints& arr)
{
for (int i=0; i < arr.size(); ++i) {
arr.at(i) *= 2;
}
}

Our function double_each_element works only with objects of type array_of_int; passing in an object of a different type won't work (nor even compile). We refer to functions like this version of double_each_element as concrete or monomorphic functions. We call them concrete because they are insufficiently abstract for our purposes. Just imagine how painful it would be if the C++ standard library provided a concrete sort routine that worked only on one specific data type!

主站蜘蛛池模板: 忻城县| 伽师县| 白玉县| 连平县| 新沂市| 通河县| 吉木乃县| 双鸭山市| 贺兰县| 南丹县| 宁蒗| 苏州市| 大余县| 科技| 奉贤区| 华亭县| 广西| 新绛县| 蚌埠市| 句容市| 上虞市| 京山县| 北流市| 西昌市| 越西县| 江门市| 贵港市| 玉屏| 铁岭市| 博爱县| 虹口区| 秦皇岛市| 宁波市| 潍坊市| 邹城市| 通化县| 昌江| 洞口县| 卢氏县| 西安市| 城口县|