Buy Ebook C++ Templates: The Complete Guide Second Edition David Vandevoorde & Nicolai M. Josuttis & Douglas Gregor Cheap Price

Download as pdf or txt
Download as pdf or txt
You are on page 1of 52

Download the full version of the textbook now at textbookfull.

com

C++ templates: the complete guide Second


Edition David Vandevoorde & Nicolai M.
Josuttis & Douglas Gregor

https://textbookfull.com/product/c-templates-the-
complete-guide-second-edition-david-vandevoorde-
nicolai-m-josuttis-douglas-gregor/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

C 17 The Complete Guide Nicolai M. Josuttis

https://textbookfull.com/product/c-17-the-complete-guide-nicolai-m-
josuttis/

textbookfull.com

C Move Semantics The Complete Guide Nicolai M. Josuttis

https://textbookfull.com/product/c-move-semantics-the-complete-guide-
nicolai-m-josuttis/

textbookfull.com

Primary Mathematics Textbook 2B Jennifer Hoerst

https://textbookfull.com/product/primary-mathematics-
textbook-2b-jennifer-hoerst/

textbookfull.com

Class and Community in Provincial Ireland, 1851–1914 Brian


Casey

https://textbookfull.com/product/class-and-community-in-provincial-
ireland-1851-1914-brian-casey/

textbookfull.com
Cold Hearted (Tooth & Claw #1) 1st Edition Heather Guerre

https://textbookfull.com/product/cold-hearted-tooth-claw-1-1st-
edition-heather-guerre/

textbookfull.com

Learn Rails 6: Accelerated Web Development with Ruby on


Rails Adam Notodikromo

https://textbookfull.com/product/learn-rails-6-accelerated-web-
development-with-ruby-on-rails-adam-notodikromo/

textbookfull.com

Scienceblind Why Our Intuitive Theories About the World


Are So Often Wrong 1st Edition Andrew Shtulman

https://textbookfull.com/product/scienceblind-why-our-intuitive-
theories-about-the-world-are-so-often-wrong-1st-edition-andrew-
shtulman/
textbookfull.com

Eloise and the Werewolves Mecklenburg Monsters 1st Edition


Jove Chambers

https://textbookfull.com/product/eloise-and-the-werewolves-
mecklenburg-monsters-1st-edition-jove-chambers/

textbookfull.com

Maurice Blanchot and Fragmentary Writing A Change of Epoch


1st Edition Leslie Hill

https://textbookfull.com/product/maurice-blanchot-and-fragmentary-
writing-a-change-of-epoch-1st-edition-leslie-hill/

textbookfull.com
Arabs a 3 000 year history of peoples tribes and empires
Mackintosh-Smith

https://textbookfull.com/product/arabs-a-3-000-year-history-of-
peoples-tribes-and-empires-mackintosh-smith/

textbookfull.com
C++ Templates
The Complete Guide
Second Edition

David Vandevoorde
Nicolai M. Josuttis
Douglas Gregor

Boston • Columbus • Indianapolis • New York • San Francisco •


Amsterdam • Cape Town Dubai • London • Madrid • Milan • Munich
• Paris • Montreal • Toronto • Delhi • Mexico City São Paulo • Sydney
• Hong Kong • Seoul • Singapore • Taipei • Tokyo
Many of the designations used by manufacturers and sellers to
distinguish their products are claimed as trademarks. Where those
designations appear in this book, and the publisher was aware of a
trademark claim, the designations have been printed with initial
capital letters or in all capitals.
The authors and publisher have taken care in the preparation of this
book, but make no expressed or implied warranty of any kind and
assume no responsibility for errors or omissions. No liability is
assumed for incidental or consequential damages in connection with
or arising out of the use of the information or programs contained
herein.
For information about buying this title in bulk quantities, or for
special sales opportunities (which may include electronic versions;
custom cover designs; and content particular to your business,
training goals, marketing focus, or branding interests), please
contact our corporate sales department at
[email protected] or (800) 382-3419.
For government sales inquiries, please contact
[email protected].
For questions about sales outside the U.S., please contact
[email protected].
Visit us on the Web: informit.com/aw
Library of Congress Catalog Number: 2017946531
Copyright © 2018 Pearson Education, Inc.
This book was typeset by Nicolai M. Josuttis using the LATEX
document processing system. All rights reserved. Printed in the
United States of America. This publication is protected by copyright,
and permission must be obtained from the publisher prior to any
prohibited reproduction, storage in a retrieval system, or
transmission in any form or by any means, electronic, mechanical,
photocopying, recording, or likewise. For information regarding
permissions, request forms and the appropriate contacts within the
Pearson Education Global Rights & Permissions Department, please
visit www.pearsoned.com/permissions/.
ISBN-13: 978-0-321-71412-1
ISBN-10: 0-321-71412-1
1 17
To Alessandra & Cassandra
—David

To those who care for people and mankind


—Nico

To Amy, Tessa & Molly


—Doug
Contents

Preface
Acknowledgments for the Second Edition
Acknowledgments for the First Edition
About This Book
What You Should Know Before Reading This Book
Overall Structure of the Book
How to Read This Book
Some Remarks About Programming Style
The C++11, C++14, and C++17 Standards
Example Code and Additional Information
Feedback

Part I: The Basics

1 Function Templates
1.1 A First Look at Function Templates
1.1.1 Defining the Template
1.1.2 Using the Template
1.1.3 Two-Phase Translation
1.2 Template Argument Deduction
1.3 Multiple Template Parameters
1.3.1 Template Parameters for Return Types
1.3.2 Deducing the Return Type
1.3.3 Return Type as Common Type
1.4 Default Template Arguments
1.5 Overloading Function Templates
1.6 But, Shouldn’t We …?
1.6.1 Pass by Value or by Reference?
1.6.2 Why Not inline?
1.6.3 Why Not constexpr?
1.7 Summary

2 Class Templates
2.1 Implementation of Class Template Stack
2.1.1 Declaration of Class Templates
2.1.2 Implementation of Member Functions
2.2 Use of Class Template Stack
2.3 Partial Usage of Class Templates
2.3.1 Concepts
2.4 Friends
2.5 Specializations of Class Templates
2.6 Partial Specialization
2.7 Default Class Template Arguments
2.8 Type Aliases
2.9 Class Template Argument Deduction
2.10 Templatized Aggregates
2.11 Summary

3 Nontype Template Parameters


3.1 Nontype Class Template Parameters
3.2 Nontype Function Template Parameters
3.3 Restrictions for Nontype Template Parameters
3.4 Template Parameter Type auto
3.5 Summary

4 Variadic Templates
4.1 Variadic Templates
4.1.1 Variadic Templates by Example
4.1.2 Overloading Variadic and Nonvariadic Templates
4.1.3 Operator sizeof…
4.2 Fold Expressions
4.3 Application of Variadic Templates
4.4 Variadic Class Templates and Variadic Expressions
4.4.1 Variadic Expressions
4.4.2 Variadic Indices
4.4.3 Variadic Class Templates
4.4.4 Variadic Deduction Guides
4.4.5 Variadic Base Classes and using
4.5 Summary

5 Tricky Basics
5.1 Keyword typename
5.2 Zero Initialization
5.3 Using this->
5.4 Templates for Raw Arrays and String Literals
5.5 Member Templates
5.5.1 The .template Construct
5.5.2 Generic Lambdas and Member Templates
5.6 Variable Templates
5.7 Template Template Parameters
5.8 Summary

6 Move Semantics and enable_if<>


6.1 Perfect Forwarding
6.2 Special Member Function Templates
6.3 Disable Templates with enable_if<>
6.4 Using enable_if<>
6.5 Using Concepts to Simplify enable_if<> Expressions
6.6 Summary
7 By Value or by Reference?
7.1 Passing by Value
7.2 Passing by Reference
7.2.1 Passing by Constant Reference
7.2.2 Passing by Nonconstant Reference
7.2.3 Passing by Forwarding Reference
7.3 Using std::ref() and std::cref()
7.4 Dealing with String Literals and Raw Arrays
7.4.1 Special Implementations for String Literals and Raw
Arrays
7.5 Dealing with Return Values
7.6 Recommended Template Parameter Declarations
7.7 Summary

8 Compile-Time Programming
8.1 Template Metaprogramming
8.2 Computing with constexpr
8.3 Execution Path Selection with Partial Specialization
8.4 SFINAE (Substitution Failure Is Not An Error)
8.4.1 Expression SFINAE with decltype
8.5 Compile-Time if
8.6 Summary

9 Using Templates in Practice


9.1 The Inclusion Model
9.1.1 Linker Errors
9.1.2 Templates in Header Files
9.2 Templates and inline
9.3 Precompiled Headers
9.4 Decoding the Error Novel
9.5 Afternotes
9.6 Summary
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
10 Basic Template Terminology
10.1 “Class Template” or “Template Class”?
10.2 Substitution, Instantiation, and Specialization
10.3 Declarations versus Definitions
10.3.1 Complete versus Incomplete Types
10.4 The One-Definition Rule
10.5 Template Arguments versus Template Parameters
10.6 Summary

11 Generic Libraries
11.1 Callables
11.1.1 Supporting Function Objects
11.1.2 Dealing with Member Functions and Additional
Arguments
11.1.3 Wrapping Function Calls
11.2 Other Utilities to Implement Generic Libraries
11.2.1 Type Traits
11.2.2 std::addressof()
11.2.3 std::declval()
11.3 Perfect Forwarding Temporaries
11.4 References as Template Parameters
11.5 Defer Evaluations
11.6 Things to Consider When Writing Generic Libraries
11.7 Summary

Part II: Templates in Depth

12 Fundamentals in Depth
12.1 Parameterized Declarations
12.1.1 Virtual Member Functions
12.1.2 Linkage of Templates
12.1.3 Primary Templates
12.2 Template Parameters
12.2.1 Type Parameters
12.2.2 Nontype Parameters
12.2.3 Template Template Parameters
12.2.4 Template Parameter Packs
12.2.5 Default Template Arguments
12.3 Template Arguments
12.3.1 Function Template Arguments
12.3.2 Type Arguments
12.3.3 Nontype Arguments
12.3.4 Template Template Arguments
12.3.5 Equivalence
12.4 Variadic Templates
12.4.1 Pack Expansions
12.4.2 Where Can Pack Expansions Occur?
12.4.3 Function Parameter Packs
12.4.4 Multiple and Nested Pack Expansions
12.4.5 Zero-Length Pack Expansions
12.4.6 Fold Expressions
12.5 Friends
12.5.1 Friend Classes of Class Templates
12.5.2 Friend Functions of Class Templates
12.5.3 Friend Templates
12.6 Afternotes

13 Names in Templates
13.1 Name Taxonomy
13.2 Looking Up Names
13.2.1 Argument-Dependent Lookup
13.2.2 Argument-Dependent Lookup of Friend Declarations
13.2.3 Injected Class Names
13.2.4 Current Instantiations
13.3 Parsing Templates
13.3.1 Context Sensitivity in Nontemplates
13.3.2 Dependent Names of Types
13.3.3 Dependent Names of Templates
13.3.4 Dependent Names in Using Declarations
13.3.5 ADL and Explicit Template Arguments
13.3.6 Dependent Expressions
13.3.7 Compiler Errors
13.4 Inheritance and Class Templates
13.4.1 Nondependent Base Classes
13.4.2 Dependent Base Classes
13.5 Afternotes

14 Instantiation
14.1 On-Demand Instantiation
14.2 Lazy Instantiation
14.2.1 Partial and Full Instantiation
14.2.2 Instantiated Components
14.3 The C++ Instantiation Model
14.3.1 Two-Phase Lookup
14.3.2 Points of Instantiation
14.3.3 The Inclusion Model
14.4 Implementation Schemes
14.4.1 Greedy Instantiation
14.4.2 Queried Instantiation
14.4.3 Iterated Instantiation
14.5 Explicit Instantiation
14.5.1 Manual Instantiation
14.5.2 Explicit Instantiation Declarations
14.6 Compile-Time if Statements
14.7 In the Standard Library
14.8 Afternotes

15 Template Argument Deduction


15.1 The Deduction Process
15.2 Deduced Contexts
15.3 Special Deduction Situations
15.4 Initializer Lists
15.5 Parameter Packs
15.5.1 Literal Operator Templates
15.6 Rvalue References
15.6.1 Reference Collapsing Rules
15.6.2 Forwarding References
15.6.3 Perfect Forwarding
15.6.4 Deduction Surprises
15.7 SFINAE (Substitution Failure Is Not An Error)
15.7.1 Immediate Context
15.8 Limitations of Deduction
15.8.1 Allowable Argument Conversions
15.8.2 Class Template Arguments
15.8.3 Default Call Arguments
15.8.4 Exception Specifications
15.9 Explicit Function Template Arguments
15.10 Deduction from Initializers and Expressions
15.10.1 The auto Type Specifier
15.10.2 Expressing the Type of an Expression with
decltype
15.10.3 decltype(auto)
15.10.4 Special Situations for auto Deduction
15.10.5 Structured Bindings
15.10.6 Generic Lambdas
15.11 Alias Templates
15.12 Class Template Argument Deduction
15.12.1 Deduction Guides
15.12.2 Implicit Deduction Guides
15.12.3 Other Subtleties
15.13 Afternotes
16 Specialization and Overloading
16.1 When “Generic Code” Doesn’t Quite Cut It
16.1.1 Transparent Customization
16.1.2 Semantic Transparency
16.2 Overloading Function Templates
16.2.1 Signatures
16.2.2 Partial Ordering of Overloaded Function Templates
16.2.3 Formal Ordering Rules
16.2.4 Templates and Nontemplates
16.2.5 Variadic Function Templates
16.3 Explicit Specialization
16.3.1 Full Class Template Specialization
16.3.2 Full Function Template Specialization
16.3.3 Full Variable Template Specialization
16.3.4 Full Member Specialization
16.4 Partial Class Template Specialization
16.5 Partial Variable Template Specialization
16.6 Afternotes

17 Future Directions
17.1 Relaxed typename Rules
17.2 Generalized Nontype Template Parameters
17.3 Partial Specialization of Function Templates
17.4 Named Template Arguments
17.5 Overloaded Class Templates
17.6 Deduction for Nonfinal Pack Expansions
17.7 Regularization of void
17.8 Type Checking for Templates
17.9 Reflective Metaprogramming
17.10 Pack Facilities
17.11 Modules
Part III: Templates and Design

18 The Polymorphic Power of Templates


18.1 Dynamic Polymorphism
18.2 Static Polymorphism
18.3 Dynamic versus Static Polymorphism
18.4 Using Concepts
18.5 New Forms of Design Patterns
18.6 Generic Programming
18.7 Afternotes

19 Implementing Traits
19.1 An Example: Accumulating a Sequence
19.1.1 Fixed Traits
19.1.2 Value Traits
19.1.3 Parameterized Traits
19.2 Traits versus Policies and Policy Classes
19.2.1 Traits and Policies: What’s the Difference?
19.2.2 Member Templates versus Template Template
Parameters
19.2.3 Combining Multiple Policies and/or Traits
19.2.4 Accumulation with General Iterators
19.3 Type Functions
19.3.1 Element Types
19.3.2 Transformation Traits
19.3.3 Predicate Traits
19.3.4 Result Type Traits
19.4 SFINAE-Based Traits
19.4.1 SFINAE Out Function Overloads
19.4.2 SFINAE Out Partial Specializations
19.4.3 Using Generic Lambdas for SFINAE
19.4.4 SFINAE-Friendly Traits
19.5 IsConvertibleT
19.6 Detecting Members
19.6.1 Detecting Member Types
19.6.2 Detecting Arbitrary Member Types
19.6.3 Detecting Nontype Members
19.6.4 Using Generic Lambdas to Detect Members
19.7 Other Traits Techniques
19.7.1 If-Then-Else
19.7.2 Detecting Nonthrowing Operations
19.7.3 Traits Convenience
19.8 Type Classification
19.8.1 Determining Fundamental Types
19.8.2 Determining Compound Types
19.8.3 Identifying Function Types
19.8.4 Determining Class Types
19.8.5 Determining Enumeration Types
19.9 Policy Traits
19.9.1 Read-Only Parameter Types
19.10 In the Standard Library
19.11 Afternotes

20 Overloading on Type Properties


20.1 Algorithm Specialization
20.2 Tag Dispatching
20.3 Enabling/Disabling Function Templates
20.3.1 Providing Multiple Specializations
20.3.2 Where Does the EnableIf Go?
20.3.3 Compile-Time if
20.3.4 Concepts
20.4 Class Specialization
20.4.1 Enabling/Disabling Class Templates
20.4.2 Tag Dispatching for Class Templates
20.5 Instantiation-Safe Templates
20.6 In the Standard Library
20.7 Afternotes

21 Templates and Inheritance


21.1 The Empty Base Class Optimization (EBCO)
21.1.1 Layout Principles
21.1.2 Members as Base Classes
21.2 The Curiously Recurring Template Pattern (CRTP)
21.2.1 The Barton-Nackman Trick
21.2.2 Operator Implementations
21.2.3 Facades
21.3 Mixins
21.3.1 Curious Mixins
21.3.2 Parameterized Virtuality
21.4 Named Template Arguments
21.5 Afternotes

22 Bridging Static and Dynamic Polymorphism


22.1 Function Objects, Pointers, and std::function<>
22.2 Generalized Function Pointers
22.3 Bridge Interface
22.4 Type Erasure
22.5 Optional Bridging
22.6 Performance Considerations
22.7 Afternotes

23 Metaprogramming
23.1 The State of Modern C++ Metaprogramming
23.1.1 Value Metaprogramming
23.1.2 Type Metaprogramming
23.1.3 Hybrid Metaprogramming
23.1.4 Hybrid Metaprogramming for Unit Types
23.2 The Dimensions of Reflective Metaprogramming
23.3 The Cost of Recursive Instantiation
23.3.1 Tracking All Instantiations
23.4 Computational Completeness
23.5 Recursive Instantiation versus Recursive Template
Arguments
23.6 Enumeration Values versus Static Constants
23.7 Afternotes

24 Typelists
24.1 Anatomy of a Typelist
24.2 Typelist Algorithms
24.2.1 Indexing
24.2.2 Finding the Best Match
24.2.3 Appending to a Typelist
24.2.4 Reversing a Typelist
24.2.5 Transforming a Typelist
24.2.6 Accumulating Typelists
24.2.7 Insertion Sort
24.3 Nontype Typelists
24.3.1 Deducible Nontype Parameters
24.4 Optimizing Algorithms with Pack Expansions
24.5 Cons-style Typelists
24.6 Afternotes

25 Tuples
25.1 Basic Tuple Design
25.1.1 Storage
25.1.2 Construction
25.2 Basic Tuple Operations
25.2.1 Comparison
25.2.2 Output
25.3 Tuple Algorithms
25.3.1 Tuples as Typelists
25.3.2 Adding to and Removing from a Tuple
25.3.3 Reversing a Tuple
25.3.4 Index Lists
25.3.5 Reversal with Index Lists
25.3.6 Shuffle and Select
25.4 Expanding Tuples
25.5 Optimizing Tuple
25.5.1 Tuples and the EBCO
25.5.2 Constant-time get()
25.6 Tuple Subscript
25.7 Afternotes

26 Discriminated Unions
26.1 Storage
26.2 Design
26.3 Value Query and Extraction
26.4 Element Initialization, Assignment and Destruction
26.4.1 Initialization
26.4.2 Destruction
26.4.3 Assignment
26.5 Visitors
26.5.1 Visit Result Type
26.5.2 Common Result Type
26.6 Variant Initialization and Assignment
26.7 Afternotes

27 Expression Templates
27.1 Temporaries and Split Loops
27.2 Encoding Expressions in Template Arguments
27.2.1 Operands of the Expression Templates
27.2.2 The Array Type
27.2.3 The Operators
27.2.4 Review
27.2.5 Expression Templates Assignments
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
27.3 Performance and Limitations of Expression Templates
27.4 Afternotes

28 Debugging Templates
28.1 Shallow Instantiation
28.2 Static Assertions
28.3 Archetypes
28.4 Tracers
28.5 Oracles
28.6 Afternotes

Appendixes

A The One-Definition Rule


A.1 Translation Units
A.2 Declarations and Definitions
A.3 The One-Definition Rule in Detail
A.3.1 One-per-Program Constraints
A.3.2 One-per-Translation Unit Constraints
A.3.3 Cross-Translation Unit Equivalence Constraints

B Value Categories
B.1 Traditional Lvalues and Rvalues
B.1.1 Lvalue-to-Rvalue Conversions
B.2 Value Categories Since C++11
B.2.1 Temporary Materialization
B.3 Checking Value Categories with decltype
B.4 Reference Types

C Overload Resolution
C.1 When Does Overload Resolution Kick In?
C.2 Simplified Overload Resolution
C.2.1 The Implied Argument for Member Functions
C.2.2 Refining the Perfect Match
C.3 Overloading Details
C.3.1 Prefer Nontemplates or More Specialized Templates
C.3.2 Conversion Sequences
C.3.3 Pointer Conversions
C.3.4 Initializer Lists
C.3.5 Functors and Surrogate Functions
C.3.6 Other Overloading Contexts

D Standard Type Utilities


D.1 Using Type Traits
D.1.1 std::integral_constant and
std::bool_constant
D.1.2 Things You Should Know When Using Traits
D.2 Primary and Composite Type Categories
D.2.1 Testing for the Primary Type Category
D.2.2 Test for Composite Type Categories
D.3 Type Properties and Operations
D.3.1 Other Type Properties
D.3.2 Test for Specific Operations
D.3.3 Relationships Between Types
D.4 Type Construction
D.5 Other Traits
D.6 Combining Type Traits
D.7 Other Utilities

E Concepts
E.1 Using Concepts
E.2 Defining Concepts
E.3 Overloading on Constraints
E.3.1 Constraint Subsumption
E.3.2 Constraints and Tag Dispatching
E.4 Concept Tips
E.4.1 Testing Concepts
E.4.2 Concept Granularity
E.4.3 Binary Compatibility

Bibliography
Forums
Books and Web Sites

Glossary

Index
Preface

The notion of templates in C++ is over 30 years old. C++ templates


were already documented in 1990 in “The Annotated C++ Reference
Manual” (ARM; see [EllisStroustrupARM]), and they had been
described before then in more specialized publications. However,
well over a decade later, we found a dearth of literature that
concentrates on the fundamental concepts and advanced techniques
of this fascinating, complex, and powerful C++ feature. With the
first edition of this book, we wanted to address this issue and
decided to write the book about templates (with perhaps a slight
lack of humility).
Much has changed in C++ since that first edition was published in
late 2002. New iterations of the C++ standard have added new
features, and continued innovation in the C++ community has
uncovered new template-based programming techniques. The
second edition of this book therefore retains the same goals as the
first edition, but for “Modern C++.”
We approached the task of writing this book with different
backgrounds and with different intentions. David (aka “Daveed”), an
experienced compiler implementer and active participant of the C++
Standard Committee working groups that evolve the core language,
was interested in a precise and detailed description of all the power
(and problems) of templates. Nico, an “ordinary” application
programmer and member of the C++ Standard Committee Library
Working Group, was interested in understanding all the techniques
of templates in a way that he could use and benefit from them.
Doug, a template library developer turned compiler implementer and
language designer, was interested in collecting, categorizing, and
evaluating the myriad techniques used to build template libraries. In
addition, we all wanted to share this knowledge with you, the reader,
and the whole community to help to avoid further misunderstanding,
confusion, or apprehension.
As a consequence, you will see both conceptual introductions with
day-to-day examples and detailed descriptions of the exact behavior
of templates. Starting from the basic principles of templates and
working up to the “art of template programming,” you will discover
(or rediscover) techniques such as static polymorphism, type traits,
metaprogramming, and expression templates. You will also gain a
deeper understanding of the C++ standard library, in which almost
all code involves templates.
We learned a lot and we had much fun while writing this book. We
hope you will have the same experience while reading it. Enjoy!
Random documents with unrelated
content Scribd suggests to you:
Drongs, 179
Druid days, 296
Dwarf Willows, 139
Dyrhólaey, 39

Earthquakes, 164, 169, 172, 173, 175, 176.


List of, 196
East, Iceland recalls the, 101, 103, 127-128
East coast, 197
Education, 61-62
Eider-down, 54.
Ducks, 48
Einarsdrángr, 44
Eldey, 46, 162
Endurance, Powers of, 298
English Tapestry and Linen in Iceland, 41
Eric, 41, 307
Erlendsey, 44
Eruptions, List of, 195-196
Essian Mountains, 160
Evening at Governor’s, 144
Exports from Faröe, 25
Extinct Geysers, 110
Eyafialla Jökul, 162

Factories, 200, 203.


Mr. Henderson’s, 202
Fair, Annual, 99
Fair Isle, 7-8, 214
Fairy Tales, 226
Famine and pestilence, 172, 192
Farms, 72, 96-98, 101.
Above Seydisfiord, 205.
Fifty destroyed, 173
Faröese, 12-34, 209
Faröese Atmospheric effects, 33.
Birds, 15, 34.
Boatman, 28.
Boatmen in saloon of steamer, 212.
Book, 211.
Cataracts, 33.
Interior, Mediæval aspect of, 26.
Knives, 26.
Lakes, 33.
Tidal currents, 33
Faxa Fiord, 47, 199
Fellow travellers, 3
Ferns, 88
Feudal system, 297
Fiords, 198-201.
Uses of, 200
First sight of Iceland, 38
Fisheries at Westmanna Islands, 40
Fishermen on East coast of Scotland, 6
Fishing boats, Faröese, 28
Fish, Mode of catching, at Lax-elv, 71
Fissures at Althing, containing water, 87
Fitful Head, 8
Fishermen’s houses at Reykjavik, 66
Flames and floods, 168, 171
Flosi, 87
Flowers larger in the North, 73
Fly, The, 224
Foaming fire-stream, 189
Foam-flakes, 9
Folk-lore, 305
Food, 97
Foola, 10
Forest, Dwarf, 91, 100
Formation of Faröe islands, 12-13, 32-33
Fort at Thorshavn, 23
Fox, 210
Free institutions, 296, 300
French policy and interests in Iceland, 58-59
Frodi, Ari, 125
Front street of Reykjavik, 52
Frost, Action of, on rocks, 14
Fuel, 97

Garden-plots at Reykjavik, 67
Geirfuglasker, 44
Geranium, Wild, 73
German race, 293
Germs of British character, 298, 301
Geyser bumpers, 130
Geysers, how formed, 109, 100
Geyser Eruption, 117.
Expedition, Arranging for, 50-51
Geyser ground, 123
Geyser water, Analysis of, 109
Gilitrutt, 240
Glaciers, 30, 179
Glades, 74
Glen above Seydisfiord, 205
Globes, Vast red-hot, 174
Glossary, 292
Goblin, The, and the Cowherd, 222
Goblin’s Whistle, The, 225
Government, 154
Governor, 154
Grand eruption of Great Geyser, 117
Grassy plot, 74
Great Geyser, 107
Grimsey, Island of, 57
Gritty slope, 107-108
Grœnavatn, 103
Guide, 50
Guillemots, 15
Guldbringu, Sysla, 99
Gudmundsson, M., 157
Gudrun and Sigurd, 265
Gusts in Faröe, 28

Haco, 306
Harold Harfagra, 304
Hastings, 307
Haukadal, 103, 107
Bird’s eye view of, 125
“Hávamál,” The, or High Song of Odin, 266
Hay-harvest, 84.
In túns, 85, 96.
200 Loads of, destroyed, 167.
Head-dress of Icelandic females, 49, 51, 68
Heimaklettur, 43
Heimaey, 40
Hekla, 99, 135,
Eruption of in A.D. 1766, 136.
Abode of Hela, 138
Heradsthing, 155
Hermanness, 11
Hildur the Fairy Queen, 244
Holum, 137
Hornafiord, 198
Horses sure-footed, 73, 75, 80, 92, 105-106
Hostess’ duties to Guests, 133-134
Hotel at Reykjavik, 64, 149
Hot Springs, 112.
At Laugervatn, 96
Houses of Faröese Fishermen, 21
Houses at Reykjavik, 67
Household Suffrage, 153
Hrafnagjá, 79, 89, 92, 139
Hummocks on pasture land, 85
Hung-milk, 97
Hvitá, 103

Ice-floes from Greenland, 55-58


Icebergs from Spitzbergen, 55-58
Ice-drift, Effects of, 72, 76, 86
Iceland Spar, 144,
where found, 204
Iceland left behind, 209
Illusory feeling over flowing water, 105
Indoor occupations, 98
Ingolf, 304
Intercourse between Britain and Iceland in Fifteenth century, 41-42
Inundations of melted ice, 166
Islands Minni, 146
Islendingur newspaper, 157
Islet-patches, 108

Jacks-of-all-trades, 98
Jökuls, 106
Jökulsá, 197.
formed, 166
Jonsbook, 155
Jonson, Rector, 157
Jutes, 303

Kaupstadr, 40
Kirkuboe, Church of, 210
Kiss of peace, 102
Kitchen fires, 72
Kittiwakes, 15
Kleifervatn, 158
Krisuvik, 45.
Ride to, 158
Kötlugjá, 125, 162.
Eruptions of, 163-177

Lambs, Mode of carrying, 101


Landfoged, 155
Lang Jökul, 103
Lang-spiel, 144
Laugervalla, 96, 99, 103
Laugervatn, 96
Language, Scandinavian element in, 294
Launay’s, Capt., vessel, Agile, 150
Latin conversation, 85, 141
Latin Vowel Sounds, 34
Lava-blister, 93
Lava, ejected by Skaptár, Bulk of, 187
Lava-waste, 74, 86
Lava-streams, Fluid, 188.
Extent of, 190
Lay of the Vikings, 278.
do. in Icelandic, 279
Laxá, 103
Lax-elv, or salmon river, 71
Leather bottle, 101
Leif, 307
Lerwick, 8.
Sloop, 211
Library at Reykjavik, 152.
at Thorshavn, 23-24
Light-house north of Orkney, 214
Lime juice, 151
Literature, Icelandic love of, 62
Little breakfast, 149
Little Geyser, 107, 111, 114, 123
Löbner, Miss, visit to 211
Lögberg, 86-90
Love of country, 145
Love of truth, 298
Lutheran Service at Thorshavn, 29-31

Maelsek, 46
Magna Charta, 297
Magnetic stones, 137
Mackenzie’s, Sir George, Geyser theory, 124
Markarfliót, 177
Meddomsmen, 155
Meeting on the Althing, 88-89
Milk diet, 97-98
Mits with two thumbs, 53-54
Mortality of children, 98
Mosquitoes, 105
Mud-caldrons, 158
Municipal institutions, 297
Mural precipice, 78
Myrdals Jökul, 162

Naalsöe, 15, 212


Naddodr, 304
National Song, 144
Native Manufactures of Iceland, 53
Needle Rocks or Drongs, 33
Nesey, 76
Newspapers, 157
Njal’s Saga, 305.
Scene of, 177
Nordurfari, 65
Norse Language, 183
Norse Words, 294,
Customs, 295
Norfolk commerce with Iceland, 41
Norman outgoing, 307
Northern “Dim,” 116
Northmen, The, 293.
Traces of, 294, 303.
Invade England, 303.
In Russia, 303.
Noss, 9

Occupations of Faröese, 26.


Of the Icelanders, 181.
Old Nick made himself as little as he was able, 224
Olfusá, 103
Oræfa Jökul, 185
Organ in Church at Thorshavn, 29
Our Scandinavian Ancestors, 293
Outfit for Iceland, 2, 289
Out-door Occupations, 98
Oxerá, 82, 88-90, 140.
Waterfall of, 78

Pack of Lava Blocks, 86


Pálsson’s, Rev. Olaf, Library, 60-61
Parliament, Functions of, 88.
Assembled, 152
Parnassia, 94, 108
Pasturage covered with ashes, 169, 172, 191
Perseverance, 298
Personal Liberty, 297
Pet Raven, 209
Petrifactions, Geyser, 108
Piratical Habits, 294, 300, 303
Plain, 94
Plateau, 74
Planters, 299
Plopping Pits, 107
Ploughs, 85
Plover, Golden, 75, 93, 100
Pluck, 301
Poems on Northern Subjects, 278
Poetry, Specimens of old Icelandic, 260
Ponies, 51.
Guided by the heel, 106.
Left to shift for themselves, 106.
Adventure of a, 158
Population of Faröe, 13, 26.
Of Iceland, 61
Porpoises, 18
Portland, 179, 182, 184
Portland Huk, 38
Premonitory symptoms of Geyser eruptions, 113
Preserved salmon, 71
Priest’s house, 82, 90
Produce, 203
Ptarmigan, 100
Puffins, 15
Pumice, 137
Puritan Fathers, 299

Rainfall, 55-56
Rake, 85
Rampart, 79
Randröp, Mr., 60
Range of vari-coloured hills, 94-95
Raven, Tame, 204
Ravine, 73
Red-hot stones, 189
Relay ponies, 71, 75
Remembrance of Iceland, The, 147
Representative parliaments, 153, 296, 304
Retrospect of Icelandic travel, 215-216
Reverence, 298
Reydarfiord, 199, 204, 209
Reykjanes, 45, 162
Reykjavik, 48-68, 143.
Library of, 63-64
Ride to the Geysers, 69
River disappears, 188
Rock-walls, 78, 79, 82
Rolling of ship, 35
Rollo, 307
Rover, Norse, 300
Runic characters, 306
Run-milk, 97

Sæmund gets the living of Oddi, 221.


Stories of, 219
Sagas, 305
Salmon-preserve of Europe, Iceland the, 59.
River, 144
Salutations, 101-102
Sandey, 76
Sand-glasses in church at Thorshavn, 24
Saula-hleith, 141
Scalds, 305
Scandinavian Ancestors, Our, 293
Scoriæ, 74
Scythe, 85
Sea-birds, Graceful motions of, 39
Swarms of, 40, 43
Sea training, 294, 301
Sea-pinks, 76, 108
Sea swallows, 134
Sea-fowls used as food, 16
Sea-gull shot, 16
Seamanship, Shetland, 301
Seething clay, 112
Self-denial, Self-reliance, 298
Seydisfiord, 201
Sheep’s knee bone, 101
Shetland Isles, 8-11
Shoes, Icelandic, 53
Showers, 76
Silex, 132
Silica in solution, 109
Silver Trinkets, 53, 60, 150
Sira, 102
Sivertsen, Mr., 52-53.
His late son, 53
Skagi, 48
Skaptár Jökul, 135, 186-187.
Eruption of, in A.D. 1783, 187-193
Skialdbreid, 140
Skier, 97-98, 99
Skiffs of the Northmen, 302
Skogar-foss, 178
Skua-gulls, 15.
Mode of obtaining fish, 37
Sky darkened with dust and ashes, 166, 170, 171, 174, 189
Slag, 93
Slattaretind, 33
Sleeping Apartment in Farm, 206
Sleeping at Thingvalla, 91
Smith, Dr. R. Angus, 132
Smith, Icelandic use of the word, 183
Snæfell’s Jökul, 47, 161
Snaps, 203
Snorro Sturleson, 305
Snow-birds, 75, 100
Sog, The, 103
“Sólar Ljód,” or “Sun Song,” 262
Solheima Sand formed, 165
Sport, 17-18
Stappen, 161
Start for the Geysers, 70
Statistics, 180-182
Steaming Holes, 107
Steward’s Bell, 5
Stock fish, 203
Stock, Icelanders rear, 96
Stony Moor, 74
Store at Seydisfiord, 204
Streets of Thorshavn, 21
Strokr, 107, 110, 121, 123.
Eruption of, provoked by turf, 111, 121
Stromoe, 15.
Caves on, 32, 210
Stuffed Birds, 150
Sulphur Banks, 158.
Spring, 46
Sumburgh Head, 8
Sumpter Ponies, Mode of loading, 69
Sunset, 6, 44.
Due north, 45
Surnames, 182
Surturbrand, 205
Sysselmen, 154

Tabasheer, 109
Temperature of Geysers, 113.
Of Faröe, 29.
Of Iceland, 55-58
Tent in a gale, 130
Terns, 75
Thea, 149
Thingvalla, 86, 92, 140.
Lake of, 76, 92.
Vale of, 77-80
Thingore, 137
Thióthólfr Newspaper, 157
Thorláksson, 62
Thorshavn, 18-31
Thorlevsholm, 88
Thorpe, 200
Thrasi’s Treasure, 178
Thorwaldsen’s Font, 63
Thyckvaboe, 169
Thyme, 94, 108
Time of Henry III, 41
Tints of Mountains, 47, 50.
Peaks, Reykjavik, 160
Tintron, Crater of, 93-94
Toilet at the Geyser, 120
Tourists, Information for intending, 2
Trackless wastes, 75
Tracks worn in Turf, 100
Traffic, 203
Trampe, Count Von, 58
Transparency of Atmosphere, 141
Trap Hills in Faröe, 13, 32
Trial by Jury, 300
Trout, 83
Tún, 72, 85, 96
Túngufljot, 103
Turf-fires, 72
Turf-roofs, 19, 21, 40, 49, 82, 90, 96
Two-thumbed mits, 149

Una the Fairy, 235


Unpacking Traps, 83

Vale of Thingvalla, 77-80


Varder or Guiding Marks, 75
Vegetables grown, 67
Velvet Turf, 106
Ventilation on Shipboard, 11
Véron’s, Capt., Vessel, Artemise, 151
Ver-tima, 98
Vestments of the Bishop, 63
Videy, 48
Vikings, 301.
Raven, The, 281
Volcanic History, 193.
Sand, 93.
Wastes, 72
Völuspá 260

War, Thirst for, 298


Waterfalls, 39.
Of the Oxerá, 90.
Above Seydisfiord, 204
Water-floods, 167, 172
Waterfowl, Lines to, 36
Westmanna Islands, 39-45.
In the 13th and 19th century, 42-43
Westmanna Skerries, 43, 44
Westmannshavn, 40
Whales, 179-80.
Whale-flesh, 22.
Rib-rafters, 72.
Steak, 213
Whirlpool at the Monk, 13
Wild-flowers, 74, 88, 100, 134
Wilderness, 75
William the Conqueror, 307
Willows, Dwarf, 91, 100, 106
Witchcraft, 88
Wrinkled rock surfaces, 76, 86, 139
Just Published, foolscap 8vo. price 5s. cloth.

New Edition.

HAREBELL CHIMES
OR

SUMMER MEMORIES AND MUSINGS.


BY

Andrew James Symington.

Also, by the same Author,

THE BEAUTIFUL
IN

NATURE, ART, AND LIFE.


In 2 vols. crown 8vo. price 21s. cloth.

London: LONGMAN, GREEN, LONGMAN & ROBERTS

1. Nos. 19, 20, 21, 23, 24, and 31.

2. Reduced to extreme destitution, by the failure of crops, subscriptions are at present


(1862) being collected to enable the inhabitants of Fair Isle to emigrate.

3. The original name is Fitfiel—probably the white mountain—fit signifying white, and fiel,
fell or mountain. In the same way England was called Albion, from its white cliffs.

4. For a selection of these, see Appendix.

5. Where the two Icelandic letters occur which are wanting in the English alphabet, they
are here represented, respectively, by d and th.

6.
“Di rado
Incontra, me rispose, che di nui
Faccia il cammino alcun per quale io vado.” L 19-21.

7. Pronounced Tingvatla.

8. In the same way a river in Perthshire is called Bruar; evidently from the natural rock-
bridge by which it is spanned.

9. Dr. Black’s analysis of the Geyser water is—


Soda, 0.95
Dry Sulphate of Soda, 1.46
Muriate of Soda, 2.46
Silica, 5.40
Alumina, 0.48
10.75

10. From the specific gravity of the globe, taken in connection with the increasing ratio of
heat as we descend from the surface, it is calculated that all metals and rocks are melted
at a depth of thirty miles below the sea level, and that the fluid mass is chiefly melted iron;
while the temperature would indicate somewhere about 4000° Fahrenheit.

11. The specimens nearly all became red before they got home, and Dr. R. Angus Smith,
F.R.S. &c., has since fully confirmed my surmise as to the origin of the colours.

12. See Olafsen’s Reise, th. ii. p. 138-140. Finnsen’s Efterretning om Tildragelserne ved
Bierget Hekla. (Copenhagen 1767). Barry’s Orkney Islands, p. 13; quoted by the author
of Iceland, Greenland, and the Faröe Islands, pp. 30-1.

13. See illustration at p. 84.

14. See note at foot of page 65.

15. Alluding to the old Icelandic female head-dress which is now again being introduced—
See illustration p. 68.

16. See illustration at p. 53.

17. Hassel, vol. 10. p. 231-233. Mackenzie, p. 312-323. Henderson, vol. 1. p. xxvi. Barrow,
pp. 293-305. Iceland, Greenland, and the Faröe Islands, pp. 209-10.

18. “Iceland, Greenland, and the Faröe Islands,” p. 37.

19. Since our visit, there has been another eruption of Kötlugjá in 1860, the particulars of
which have been collected by Lauder Lindsay, Esq. M.D., F.L.S. &c., and published in the
Edinburgh “Philosophical Journal” for January. From his interesting and admirable
scientific paper, which treats the subject largely, we learn that this eruption, like that of
1823, was “mild and innocuous.” It began on the 8th, and continued to the 28th or 29th
of May, and was preceded for several days by earthquakes. On the morning of the eighth
a dark cloud was seen to rise from the mountain, which at the same moment sent forth
an enormous flood of water, with very large pieces of ice, running with the water-stream
into the sea. Some of the pieces of ice were so large that they were stranded at a twenty
fathom depth in the sea. On the 12th of May the flames could be seen from Reykjavik,
although this town is no less than about eighty English miles distant. During the
evenings flashes of lightning were seen in the same direction. On the 16th May, the
smoke was about twenty-four thousand (?) feet high; it was sometimes of a dark colour,
but at other times it resembled steam. At this time the fire was seen from several places
at a distance of about 80 English miles. The wind being northerly during the eruption,
the sand and ashes fell chiefly in Myrdals-sand, which was the direction also taken by the
water-floods. Sulphur was found floating in the sea, and the fish disappeared from
certain parts of the neighbouring coasts. A large quantity of cinders was mixed with the
water-floods. Cinders and balls of fire, as well as smoke, were thrown up; but the cinders
and ashes, from being carried by the wind partly into the sea and partly to the
neighbouring snow-fields, did comparatively little damage to the lowland farms; although
the well-known devastations of former eruptions, especially those of 1665 and 1755,
gave rise to extreme alarm and the most serious apprehensions among the poor
inhabitants.

20. Longest interval.

21. Shortest interval.

22. Most important eruption.

23. ‘In estimating the seriousness of such a loss, it is necessary to bear in mind that the hay
harvest is, so far as the vegetable kingdom is concerned, the only harvest in Iceland; and
that hay is almost the sole provender for horses, sheep, and cattle during three-fourths of
the year.’

24. Founding his statements on the manuscript of the Surgeon Sveinn Pálsson, and on
Horrebow’s Natural History of Iceland—p. 12: London 1758.

25. From the Greek επι and ζωον—a term applied to diseases among animals; e.g. murrain, in
which cattle are preyed upon by parasites.

26. ‘The celebrated agitation of the waters of our own Loch Ness occurred
contemporaneously with the great earthquake of Lisbon, here also referred to.’

27. Stukesley’s “Philosophy of Earthquakes,” 3d ed., London 1756, 8vo, pp. 9-30.

28. “Journal of a Tour in Iceland in the Summer of 1809,” 2d ed., 2 vols., London 1813, by
Sir William Jackson Hooker, K.H., D.C.L., L.L.D., &c., the present distinguished
Director of the Royal Botanic Garden at Kew.

29. See Dasent’s admirable translation of “Burnt Njal,” since published.


30. Mr. Brynjúlfsson had the following lines—intimating the hopelessness of searching for
the treasure concealed below—repeated to him, when recently visiting the locality. They
are thus literally rendered by him into English.
“Thrasa kista audug er “Thrasi’s chest wealthy is
Under forsi Skoga Under foss of Skogar;
Hver sem thángad fyrsti fer Whosoever thither first goes
Fiflsku hefir nóga.” Foolishness has enough.”

31. There was a slight eruption of this mountain on March 23, 1861, which only lasted a few
days. The smoke and sulphurous gases which it exhaled tarnished metal at 50 miles
distance.

32. See illustration, p. 160.

33. See illustration p. 134, where Skaptár is represented as rising in the distance, over a hill-
range on the other side of a level plain, which in the wood-cut resembles and might be
mistaken for water.

34. This also happened during the eruption of Hekla in 1693.

35. “Greenland, Iceland, and Faröe,” pp. 38-42: chiefly abridged from Stephenson’s
“Account of the Eruption,” published at Copenhagen in 1785, which will be found
translated in Hooker’s Journal, vol. ii., 124-261. See also Henderson, vol. i., pp. 272-290;
and Gliemann, pp. 107-109.

36. Second ed. published in 1841.

37. Should be Kötlugjá. A.J.S.

38. At night it sunk to 50°.

39. See illustration D at p. 53.

40. Compare illustrations pp. 202, 206, and 207.

41. See illustration p. 197.

42. Sæmund Frodi, like other learned men of those days, was supposed to be in possession
of magic powers. He was the Friar Bacon of Iceland; and these stories in which his name
figures, handed down by tradition, are still often told in Iceland by the fireside on the
long winter evenings. Curious to observe, that, in most mediæval stories of this kind,
Satan is always outwitted and gets the worst of it. A.J.S.

43. This story may explain the origin of the Scotch proverb, “Deil tak’ the hindmost.”—
There is another version of Sæmund’s mode of escape; viz.: That when he was about to
be seized, pointing to his shadow on the wall, he said, “I am not the hindmost, don’t you
see him that is coming behind me!” Old Nick then caught at the shadow, and thought it
was a man; but Sæmund got out, and the door was slammed on his heels. But after that
time, it is added, Sæmund was always without a shadow, for Old Nick would not let his
shadow free again. Here, in this old-world story, we have the germ of Chamisso’s
“Shadowless Man.” A.J.S.

44. The reader will here be reminded of Aladdin’s Lamp, Genii, and of the East, from
whence these Stories also originally came in the days of Odin.

45. To the right understanding of the story of “Biarni Sveinsson,” it must be remembered
that a superstition prevailed amongst the Icelanders regarding the central deserts. These,
they believed, were inhabited by a strange mysterious race of men who held no
intercourse with the other inhabitants, and were said to be in the habit of kidnapping
women from the country. This belief may have had its origin in the fact, that, in former
days, some few outlaws and their families took refuge in the deserts, and lived there for a
time in order to escape the hands of justice. A.J.S.

46. In Iceland vegetation is late.

47. These popular northern fireside stories and tales are partly gathered from direct oral
narration, and partly taken from a small volume, “Islenzk Æfintyri,” the collection of
Messrs. M. Grimson and J. Arnason, published in Icelandic, at Reykjavik, in 1852.

48. Völu-spá or spae, the Prophesy—wisdom, oracle, or mystic song—of Völu (Völu is the
genitive of Vala). Scoticê, Vala’s spae, as in the word spae-wife. One of these Valor, or
Northern sybills, whom Odin consulted in Neifelhem, when found in the tomb where
she had lain for ages, is represented as saying—
“I was snowed over with snows,
And beaten with rains,
And drenched with the dews;
Dead have I long been.”

49. These specimens of old Icelandic poetry are selected from “The Literature and Romance
of Northern Europe,” by William and Mary Howitt: 2 vols. 8vo., Colburn & Co., 1852.

50. Written in reply to the following lines, by Delta, sent her by way of a challenge.
“To where the Arctic billow foams
Round Shetland’s sad and silent homes,
There sighs the wind and wails the surge
As ’twere of living things the dirge.”

In these old heathen days, be it remembered, where all were sea-rovers there were good
and bad among them. For a fine description of the best type of the Viking and his code
of honour, see Tegner’s beautiful northern poem, “The Frithjof Saga.”

51. The “Lay of the Vikings,” translated into Icelandic verse by the Rev. Olaf Pálsson. It is in
the free metre of the old sagas—the same as that which Thorláksson adopted in his
translation of “Paradise Lost.” The following is the translation of Delta’s lines:

You might also like