Home | About | Partners | Contact Us

SourceForge Logo

Quick Links
Building XL
XL Mailing List

Understanding XL
Conceptual overview
XL examples
Inside XL
Concept Programming

In depth
Browse GIT
SourceForge Info

Other projects
GNU Project
The Mozart Project

XLR: Extensible Language and Runtime

The art of turning ideas into code

Generics validation

Prev: True Generic Types


Next: Language extensions

Frequently, when you declare a generic type, you also declare a number of related generic declarations (other types, algorithms, etc). Before the C++ STL, we had little experience with large bodies of generic code.

The STL has popularized a number of concepts, such as ForwardIterator, which is used for any data type where both a dereference operator (operator* and an increment operator (operator++) exist. Unfortunately, these concepts translate in the code with little more than naming conventions on template parameters. The compiler cannot check anything before actually instantiating a type. In other words, anybody in the C++ community knows what a ForwardIterator is, except the compiler! In other words, the bandwidth of the C++ template mechanism is insufficient to represent a concept such as ForwardIterator.

XL allows to declare validations for generics. Before even attempting to instantiate a template, the compiler attempts to instantiate the validation. If the validation is rejected, then the instantiation itself is rejected. There is even the possibility to select among candidates based on validation, as shown in this example, but I'm not really sure that this is a good idea...

Note: At this stage, only the C++ version of the compiler implements generics.

Prev: True Generic Types


Next: Language extensions

Copyright 2008 Christophe de Dinechin (Blog)
E-mail: XL Mailing List (polluted by spam, unfortunately)