Boost logo

Boost :

From: dexsch (DavidS_at_[hidden])
Date: 2002-02-19 20:47:50

I have yet another take on template type specification.
You are really talking about two things.
Limiting the template type by explicit list. The tags concept.
Limiting the template type by behaviour. The if
(constraint<T>::value) mechanism.

The first is not general enough for wide applicability
in building libraries.
The would lead to horrendously long winded template
parameter list specifications.

The problem lies with the keywords typename and class.
These currently take the role of merely introducing a type or class
as a parameter.
Syntactically they are dead wood.

Let's propose that they be replaced something more formal.

Just we currently use typedef to generate a new type,
we should have the ability to use 'typespec' to generate
a new type of type.

Here is an example of a meta type definition.

// This says ListNode types must
// declare a typedef value_type,
// have a copy constructor,
// and a next() method which returns a ListNode*
// and an equality comparison operator
// Remember the name ListNode is a place holder
// for the actual type(s) being constrained
typespec ListNode
        typedef value_type;
        ListNode(const ListNode&)
        ListNode* next();
        bool operator==(const ListNode&)

// This says the LinkedList template class
// accepts only types that satisfy the ListNode typespec
template <ListNode T>
class LinkedList

You should be able to utilise a previously defined typespec
within a typespec to allow complex behaviour relationships
to be defined. It then becomes a pattern language modelled
after the implementation language.

template <ListNode T>
typespec DequeT
        ListNode& operator[](int);

which describes a DequeT type specification.
DequeT are a template type which requires a ListNode template
They are also required to implement an operator[] which returns a
ListNode reference.


Boost list run by bdawes at, gregod at, cpdaniel at, john at