[Translation] How to organize the source code for template technology

zhaozj2021-02-16  64

How to organize the source code for template technology

- Method of several different organizational source code in C template library

Author: Nemanja Trifunovic

Translation: weily

introduction

Often someone asking me, use the template technology to write the program difficult? Generally, I will give this reply: "

Using a template is simple, but

Template is difficult. "Just look at those template libraries commonly used in our usual write programs, such as STL, ATL, WTL, and Boost some libraries, you will understand what I mean. These template libraries are very good in this way. Example - "Simple Interface, Complex Implementation".

I know the MFC template container (Template Container), I started using the template. Until last year, I don't have to develop template yourself. When I eventually constructed some template classes, the first trouble I encountered is "Traditional" source code organization method for template technology, does not care. Then I spent a lot of time to study why this way I met the template, and I also considered how to solve this problem.

This article is for those who have understood how to use the template, but lack of experience in the development template. Here I only introduce the contents of the template class, and do not introduce the relevant part of the template function, because for these two situations, it is the same.

Problem Description

To demonstrate this problem, we will use the following example. Suppose we have a template, Array in Array.h (there is no relationship with Boost :: Array).