Topic: type requirements for template instantiation


Author: Joel Conraud <conraud@pommard.ensg.u-nancy.fr>
Date: 1997/10/03
Raw View
        Hello,

        With the growing use of template mechanism, wouldn't be
        interesting to be able to write code like this :

template <class XYPoint> class Triangulation {
public:
        ...

private:
        ...

requires: <- // NEW KEYWORD HERE

        float XYPoint::x() const;
        float XYPoint::y() const;
};

My - humble - proposal is to add, with a syntax or another, a clause
to enumerate what we want a type to provide in order to be used in a
given template.


By expliciting the requirements on the type we want to use, we get
several advantages :

        - as this kind of information is mandatory, up to know, it is
        provided (when it is provided :-)) in comments, or software
        document ; so there is no language constraints for giving this
        information.

        - if this piece of information is available, I guess it could
        help compiler vendors to manage template mechanism more
        easily, for example by testing statically a templated type
        declaration and checks if a type fits or not the requirements.

                Any comments ?

-----
Joel CONRAUD
TSurf SA - gOcad maintenance team
Tel : +33 3.83.50.30.25 / Fax : +33 3.83.51.23.12
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: stephen.clamage_nospam@eng.sun.com (Steve Clamage)
Date: 1997/10/03
Raw View
On 03 Oct 97 09:31:12 GMT, Joel Conraud
<conraud@pommard.ensg.u-nancy.fr> wrote:
>
>My - humble - proposal is to add, with a syntax or another, a clause
>to enumerate what we want a type to provide in order to be used in a
>given template.

See D&E for an extended discussion of why that feature is not included
in C++, and how you can get the effect you want without a language
extension. (B. Stroustrup, "The Design and Evolution of C++",
Addison-Wesley)


---
Steve Clamage, stephen.clamage_nospam@eng.sun.com
( Note: remove "_nospam" when replying )
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]