"MODERN C ++ Design" Loki library reading 4: hierarchygenerators.h read

zhaozj2021-02-16  37

LOKI library reading 4: hierarchygenerators.h read

Every line of code in this is understanding, using it, I have seen it, but I still don't understand how to use this. I also hope that someone can answer.

// the loki library

// Copyright (c) 2001 by Andrei Alexandrescu

// this code Accompanies The Book:

// Alexandrescu, Andrei. "Modern C Design: Generic Programming and Design

// Patterns Applied ". CopyRight (c) 2001. Addison-Wesley.

// permission to use, copy, modify, distribute and sell this software for any

// Purpose Is hereby granted without fee, provided that the Above copyright

// NOTICE APPEAR in All Copies and this Both That Copyright NOTICE AND THIS

// Permission Notice APPEAR in Supporting Documentation.

// the author or addison-welsey longman make no representation about the @ r

// suitability of this software for any purpose. It is provided "as IS"

// WITHOUT EXPRESS or Implied Warranty.

// Last Update: March 05, 2001

#ifndef hierarchygerators_inc_

#define hierarchygenerators_inc_

#include "typelist.h"

#include "typetraits.h"

#include "emptytype.h"

Namespace loki

{

// Class Template GenScatterHierarchy

// generates a scattered hierarchy starting from a typelist and a template

// invocation (Tlist is a Typelist, Model IS A Template of One Arg):

// genscatterhierarchy

// the generated class inherits all classes generated by instantiarating the

// template 'model' with the Types Contained in TLIST

// WQ Note: Multi-inheritance from all types in Typelist, which is an inclusive derived (Unit ), and the type is decoupled, so there is no rhombic defect.

If there is a type repeated in the list, or there is a Typelist (tree) to find trouble.

Template Class Unit>

Class genscatterhierarchy;

// WQ Note: It is not consistent with the predetermination, parameters, and implementation, to indicate the design intent. Template Class Unit>

Class GenScatterHierarchy , Unit> // WQ Note: Offset. In the Loki library, it is often seen that the offset is the leading role, and the template body is a special case of offsetting.

: Public GenScatterHierarchy

, Public GenScatterHierarchy

// WQ Note: If you use Typelist :: Head, Tail instead of T1 and T2 in this two lines.

{

PUBLIC:

Typedef Typelist TLIST;

Typedef genscatterhierarchy Leftbase;

Typedef genscatterhierarchy rightbase;

// WQ Note: Typelist's Head, Tail is similar.

Template Struct Rebind

{

Typedef Unit Result;

}; // WQ Note: It does not require T in Typelist. But according to other code, T must be in Typelist. Other parts of the LOKI library is to perform such a compile period check.

// WQ Note: Pay attention to the details of the "Detective class with the same name to cover the foundation version".

}

Template Class Unit>

Class GenScatterHierarchy: Public Unit

// WQ Note: This is the implementation of the template, but only the situation of traditional types.

{

TypedEf Unit Leftbase;

Template Struct Rebind

{

Typedef Unit Result;

}

}

Template