Wide <Programming>: DISCRIMINATED UNIONS (1)

zhaozj2021-02-16  67

Wide : DISCRIMINATED Unions (1) Andrei AlexandRescu

Believe me: No matter how thick look, if you want is about programming articles, you count to place it. What is discussed herein does not identify a union, and this generic programming part discusses the type of identifiable data. Identification of combination from conceptual synonym: dismantage combination, variable type (variant type), algebraic type, no matter how you call them, identifies United As data abstraction in various It is very useful in applications. Many languages ​​(most of the functional language) is very dependent on the data structure. Maybe you will be used in C in the near future, because ... but what is identifiable, what can I do for you? You will soon find the answer or even more unexpected surprises, but first, you should ask you to make up your article.

A template class called AdhocVisitor is defined for a Template class called AdhocVisitor. This template class does not change the functionality of access to the original level of access to a class level. AdhocVisitor is very simple, assuming you this instantiate: typedef adhocvisitor :: type> docelementVisitor; then, AdhocVisitor's code can guarantee the correct access: When you call docelementvisitor :: StartVisit, correct The overload function VIIT (Textarea *), Visit (VectorGraphics *), or Visit (bitmap *) is automatically called. AdhocVisitor performs parameter type interpretation mechanisms in nature, like the IF-ELSE chain, that is, the code effect is similar to:

If (TextArea * pTextArea = dynamic_cast