|
Boost Users : |
From: Frank Bergemann (FBergemann_at_[hidden])
Date: 2007-10-13 06:53:07
Hi,
i posted this to comp.lang.c++.moderated:
-------------------------------------------------------
Hi,
i am just starting to work with "C++ Template Metaprogramming" - using
the book of David Abrahams & Aleksey Gurtovoy.
And you know, there are things like mpl::plus<> for some operator,
mpl::if_<> for a control-struct, mpl:insert<>, mpl:erase<>, mpl:clear<>
for STL container like operations, etc.
Lots of things re-modeled the "unaccustomed template-syntax" - way for
types, which are there in C/C++ language definition already for
operating on variables and values.
So i wonder if it would be a good option to introduce some
mpl {
...
}
in remembrance of
asm {
...
}
This time not for going down to the assembler level, but going up to the
meta level.
But with the goal to drop the template fashioned syntax for meta
programming by a syntax already familiar in C/C++ language without
templates (if this is possible - i don't now enough about that).
Well, this is just a gut feeling, that there might be a chance this way
to more align "standard" programming with "meta" programming, which then
might enable to easier catch the the gray area of borderline between
compilation and runtime execution and how to shift that back and forth.
What do you think?
rgds!
Frank
-------------------------------------------------------
Then i was thinking, that instead of extending the C++ language, it
might be sufficient to use an own preprocessor before handing over to
g++ (e.g.).
For this maybe using boost::spirit?
Finally i was remembering, that there is already some 'preprocessor'
project in boost itself.
But having a 1st look at it, it doesn't seem to do what i'd like to have.
Just as an example - see this extract from boost::enable_if documentation:
template <class T>
typename enable_if_c<boost::is_arithmetic<T>::value, T>::type
foo(T t) { return t; }
I'd like to make it s.th. like:
mpl {
template <class T>
if (is_arithmetic(T)) {
T foo (T t) { return t;}
}
}
This is just a simple example.
But just imagine use of mpl metafunctions like mpl::and_ mpl::or_,
mpl::plus, mpl::minus, mpl::equal_to, mpl::less, etc, that could come
back to the "natural" &&, ||, +, -, ==, <, etc.
[ hmm, i think, i mixed up mpl::enable_if with mpl::if_ - so my example
is not correct - but i hope you get my point here ]
Them maybe it would also be possible somehow:
mpl {
template <class T>
if (is_arithmetic(T)) {
T foo (T t) { return t;}
}
else {
#error "instantiation of foo() not supported for given type T"
}
}
... to generate usefulcompiler warning/errors.
The main point for me is to get find an equivalent to the "strange"
template syntax that is more C/C++ alike way to deal with variables and
values. Not because template syntax is "strange". But in order to
re-align again.
rgds!
Frank
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net