Tyr Library
This page contains source
code for Semantics Consulting's Tyr
library.
What is the Tyr Library?
The Tyr
library is an outgrowth of the code that accompanied my "Common
Knowledge" C/C++ Users Journal columns and this site's (now
discontinued) "Once, Weakly"
web column. Eventually, the complexity and redundancy of
maintaining totally separate applications became annoying enough to
force me to consider establishing a more standard environment: the Tyr
library.
In answer to many questions I've received on the subject: Yes,
the name Tyr is a joke poking fun at the naming of Andrei
Alexandrescu's Loki library. (Just consider the relative merits
of Tyr
and Loki.)
Note, however, that Loki is a production-quality library, whereas Tyr
is entirely experimental.
Each source file should
contain a copyright notice similar to the
following:
// Semantics Consulting's Tyr Library
// http://www.semantics.org
//
// Copyright (c) 2003 by Stephen C. Dewhurst
//
// Permission to use, copy, modify, distribute, and sell this software
// for any purpose is hereby granted without fee, provided that the above
// copyright notice appears in all copies and that both that copyright
// notice and this permission notice appear in supporting documentation.
// The author makes no representations about the suitability of this
// software for any purpose. It is provided "as is" without express
// or implied warranty.
Some warnings:
First, these facilities were developed primarily
to
illustrate C++ programming techniques, and are not necessarily
generally
useful (some are even kind of weird). Second, a lot of the code
employs
template features that are not handled well by some C++
compilers. If you have problems with some of the template code,
please check it first with a highly standard compliant compiler before
making a bug report. As I get time to work on the code, I hope to
port it to less-compliant compilers.
How Can I Get a Copy?
The individual files from
the library are available
below.
Alternatively, you may download a zip of the whole library:
A quick test program for
the library is included in main.cpp. Simply unzipping the
files into a directory and issuing a "CC main.cpp" (or the local
equivalent) should result in an executable. The README.txt
file may also have some
more-or-less useful information.
What's in the Library?
STL
- An STL-inspired list container that uses two-way pointers to
implement fickle-forward iterators.
- An output iterator
adapter that allows an output
sequence to be sent to an unbounded number of output streams
simultaneously. Figuring out the value_type of the resultant
iterator requires a lot of metaprogramming.
- An input/forward iterator adapter that allows an
unbounded number of differently-typed input/forward sequences to be
treated
as a single "supersequence," without copying the values from the
constituent
sequences.
Compile-Time Type
Manipulation
- A framework for the dismantling, pattern matching/substitution,
and
regeneration
of a type.
- Algorithms, meta-function objects, and meta-function object
adapters
for manipulating typelists.
- A typeof implementation that
translates
a type into a Gödel number, then back to a type in order to
implement
most
of the functionality of a built-in typeof operator.
Extended-Precision
Compile-Time Arithmetic
- A "binary" version of a library that performs
extended-precision
compile time arithmetic using the type system instead of binary
arithmetic.
Depending on the capabilities of the compiler, it's possible to perform
compile time arithmetic on 1000-bit (or larger) integers.
- Moving typeints from a binary representation to a 2**n
representation
in order to deal with compilers' restrictive template instantiation
recursion
depth limits. Compile time arithmetic in excess of 5000-bit
precision is possible.
Patterns
- A version of Monostate that allows members to added and removed
at compile time just by referencing them.
Other Miscellaneous Files
- Various utilities.
- A simple test driver.
- A casting/conversion utility.
- Information about this pre-1.0 version of the library.