Chapter 6. Wrapped Types

In this chapter, we will explore D's rich abstraction capabilities to wrap, extend, or constrain other types. We'll learn about:

  • Creating a struct with reference semantics
  • Simulating inheritance with structs
  • Creating a ranged integer
  • Creating an opaque handle type
  • Creating a subtyped string for i18n
  • Forwarding methods with opDispatch
  • Creating a tagged dynamic type
  • Creating a structure with two views into the same data
  • Simulating multiple inheritance with mixin templates

Introduction

D's struct has a wealth of possibilities. It is defined by the D spec as a way to "paint a data structure over hardware or an external type", and thus gives us various modeling tools that come without runtime or memory cost. We've already used or seen some of the techniques from this chapter earlier in the book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.30.19