- Mastering the C++17 STL
- Arthur O'Dwyer
- 147字
- 2021-07-08 10:20:19
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!
推薦閱讀
- scikit-learn Cookbook
- 無代碼編程:用云表搭建企業(yè)數(shù)字化管理平臺
- 基于Java技術(shù)的Web應(yīng)用開發(fā)
- 表哥的Access入門:以Excel視角快速學(xué)習(xí)數(shù)據(jù)庫開發(fā)(第2版)
- JAVA程序設(shè)計實驗教程
- HTML5與CSS3基礎(chǔ)教程(第8版)
- SQL Server數(shù)據(jù)庫管理與開發(fā)兵書
- Learning AWS
- INSTANT Silverlight 5 Animation
- 時空數(shù)據(jù)建模及其應(yīng)用
- OpenStack Networking Essentials
- IBM Cognos TM1 Developer's Certification guide
- 從零開始學(xué)Selenium自動化測試:基于Python:視頻教學(xué)版
- 你必須知道的.NET(第2版)
- Raspberry Pi Robotic Projects