Topic: Better metaprogramming support
Author: philippe_mori@hotmail.com ("Philippe Mori")
Date: Fri, 17 Jan 2003 17:05:03 +0000 (UTC) Raw View
I would like that the metaprogramming part of the language be extended so
that we would be able to do far more complex metaprogramming in C++.
Some of the thinks that I would like:
- More complete and integrated type traits in the compiler. For ex. it would
be possible to detect POD type, enumerations, whether a type is
copy-constructible, convertible,...
- Support for type list (see Modern C++ design)
- Support for a kind of function that would returns a type or a compile-time
constant. This could be used to build complex type from more simple type. I
am not sure of the appropriate syntax. We can do many of that using template
classes but maybe extending the language would make metaprogramming a bit
easier. Here are some basic idea:
template <typename R /* ??? */ , typename T>
R f() {
// Have a type that depends on some compile-time constant...
return sizeof(T) > 4 ? typeof(T) : typeof(T[2]);
}
template <typename T, int i>
int ArraySize(T[i]) { return i; }
- Support typeof operator
- Support for variable type deduction at declaration. Partial and complete
deduction would be possible. Complete deduction is something like:
typename t = 25 + 3.1; // t would be a double here
Partial deduction would be something like:
std::pair<...> pair(23, 45.9);
Here the compiler deduces unknown part... Ideally it would be possible to
specify partial arguments like that:
std::pair<int, ...> pair2(24, 44.8); // deduce second arg only.
- The possibility to detect if a function (member or not) exists. It would
be possible to check only for name of for matchable functions (that is one
that would be usable in a certain context), for an exact prototype or a
compatible prototype (i.e. usable but not exactly the same).
- It would also be possible to detect if a function is virtual, if a class
is abstract,...
- The possibility to specifier that any modifier may appears here (and the
ability to copy those modifier elsewhere). For ex. it would be possible to
implement a mem_fun that would works for cdecl, pascal, fastcall calling
convention... or that would works for const and non-const member
functions...
- Compile-time assertion support that would allows to display user-friendly
messages.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: pavel_vozenilek@yahoo.co.uk (Pavel Vozenilek)
Date: Sat, 18 Jan 2003 06:04:22 +0000 (UTC) Raw View
philippe_mori@hotmail.com ("Philippe Mori") wrote in message news:<w1WV9.10893$0E.1166756@news20.bellglobal.com>...
[snip]
> - More complete and integrated type traits in the compiler. For ex. it would
> be possible to detect POD type, enumerations, whether a type is
> copy-constructible, convertible,...
>
Available in Boost (http://www.boost.org/). Type traits are already
admitted as part of C++0x.
> - Support for type list (see Modern C++ design) ...
>
You may work with them now. What you probably look for is better
integration of metapropgramming with IDEs, better error messages and
so.
Type lists are also supported in Boost MPL library.
> - Support for a kind of function that would returns a type or a compile-time
> constant. This could be used to build complex type from more simple type. I
> am not sure of the appropriate syntax. We can do many of that using template
> classes but maybe extending the language would make metaprogramming a bit
> easier.
>
Take a look on Boost.MPL library (really very advanced stuff).
> - Support typeof operator
> - Support for variable type deduction at declaration. ...
>
Something was submitted to Comittee - I think by David Abrahams.
Definitely would be useful.
> - The possibility to detect if a function (member or not) exists. It would
> be possible to check only for name of for matchable functions (that is one
> that would be usable in a certain context), for an exact prototype or a
> compatible prototype (i.e. usable but not exactly the same).
>
You may do this now, at least party with SFINAE (see book C++
Templates, The Complete Guide, Josuttis & Vandervoorde, recommended).
> - It would also be possible to detect if a function is virtual, if a class
> is abstract,...
>
Virtual functions: is_polymorphic<class T> is available in Boost
(Python library).
Abstract class: see http://groups.google.com/groups?q=is_abstract_class&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=df893da6.0207110613.75b2fe90%40posting.google.com&rnum=1.
Already working on handful of compilers.
> - The possibility to specifier that any modifier may appears here (and the
> ability to copy those modifier elsewhere). For ex. it would be possible to
> implement a mem_fun that would works for cdecl, pascal, fastcall calling
> convention... or that would works for const and non-const member
> functions...
>
Do not understand what it means.
> - Compile-time assertion support that would allows to display user-friendly
> messages.
>
See static_assert library in Boost.
/Pavel
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]