Boost logo

Boost :

From: Noah Stein (noah_at_[hidden])
Date: 2002-02-19 22:07:27

> -----Original Message-----
> From: dexsch [mailto:DavidS_at_[hidden]]
> Sent: Tuesday, February 19, 2002 5:48 PM

> 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&)
> };

I like the idea here, but I would prefer a notation that does not introduce
a keyword. I would suggest using a notation similar to that used by pure
virtual functions:

typename ListNode = 0
        typedef value_type;
        ListNode(const ListNode&);
        ListNode* next();
        bool operator==(const ListNode&);

The issues I still see with the above is that the "typedef value_type;" is
different than the normal syntax for typedef. Which leads me to another
suggestion. I think that there should be some type of ANY class designation
like that in Eiffel. It's a great way to specify a completely abstract
concept without resorting to using many template parameters and the
curiously recurring template pattern.

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

I don't think the proposed notation would work as-is. What if the
requirements on T are that it be a ListNode and, say, Serializable? Maybe
something such as:

template< class<ListNode,Serializable> T>
class LinkedList

-- Noah

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