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

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!

主站蜘蛛池模板: 新野县| 芦溪县| 梅州市| 宜宾县| 达日县| 辽宁省| 锡林郭勒盟| 盐边县| 阿克陶县| 肇源县| 延川县| 固原市| 巴马| 建平县| 永清县| 伊宁市| 武冈市| 闻喜县| 英吉沙县| 千阳县| 延长县| 永修县| 临潭县| 冕宁县| 保康县| 鹰潭市| 元氏县| 柳江县| 新巴尔虎左旗| 平陆县| 独山县| 云和县| 黄冈市| 莎车县| 聊城市| 叶城县| 丰县| 六盘水市| 辽宁省| 沂水县| 长武县|