Boost logo

Boost :

From: dexsch (DavidS_at_[hidden])
Date: 2002-02-19 21:04:29


--- In boost_at_y..., "dexsch" <DavidS_at_a...> wrote:
> 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
> {
> public:
> 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.
> eg.
>
> template <ListNode T>
> typespec DequeT
> {
> public:
> ListNode& operator[](int);
> };
>
> which describes a DequeT type specification.
> DequeT are a template type which requires a ListNode template
> parameter.
> They are also required to implement an operator[] which returns a
> ListNode reference.
>
> dex

One could take this one step further and allow typespec inheritance
typespec ForwardIterator
{
public: void operator++();
};
typespec ReverseIterator : ForwardIterator
{
public: void operator--();
};
typespec RandomIterator : ReverseIterator
{
public: void operator+(int); void operator-(int);
void RandomIterator& operator+=(int); etc...
};

dex


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk