|
Boost : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-10-07 22:09:33
David B. Held wrote:
> Here's what I have now:
>
> [...]
> #define BOOST_MPL_NO_FULL_LAMBDA_SUPPORT
> #include <boost/mpl/lambda.hpp>
> #include <boost/mpl/apply.hpp>
>
> namespace mpl = boost::mpl;
> using mpl::_;
>
> template <typename T>
> struct ownership
> {
> typedef ownership type;
> struct rebind_;
> BOOST_MPL_AUX_LAMBDA_SUPPORT(1, ownership, (T))
> };
>
> int main()
> {
> typedef mpl::lambda<ownership<_> >::type f_;
> mpl::apply<f_, int>::type t;
> }
>
> I checked out the latest CVS snapshot, noting that you
> recently checked in files, but still no luck with bcc. :(
OK, here's how to make it work with the current CVS state:
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/aux_/void_spec.hpp>
namespace mpl = boost::mpl;
using mpl::_;
template <typename T>
struct ownership
{
typedef ownership type;
BOOST_MPL_AUX_LAMBDA_SUPPORT(1, ownership, (T))
};
namespace boost { namespace mpl {
BOOST_MPL_AUX_VOID_SPEC(1, ownership)
}}
int main()
{
typedef mpl::lambda<ownership<_> >::type f_;
mpl::apply<f_, int>::type t;
}
If I knew you don't want to wait until I am finished with a less verbose
notation, I would provide you with the above from the very beginning - sorry
for making you wandering around.
[...]
> In case you aren't aware, there are some oddities with this
> code. First, note that I force NO_FULL_LAMBDA. That's because
> it appears not to be getting defined for bcc.
It should be. If you look in "boost/config/compiler/borland.hpp", you'll see
that BOOST_NO_TEMPLATE_TEMPLATES _is_ getting defined there. Could it be
that you use a custom config header?
[...]
> Second, after taking a look at the expansion of
> AUX_LAMBDA_SUPPORT, it looks like it defines a rebind<> template,
> so I'm wondering why it also needs rebind_.
Currently, you don't. I should have been more clear last time - everything I
wrote then was about how things will look after I check in my recent
lambda-related changes, - and that didn't happen yet.
> Third, adding a semicolon
> to the end of AUX_LAMBDA_SUPPORT evokes:
>
> [C++ Error] Unit1.cpp(29): E2321 Declaration does not
> specify a tag
> or an identifier
>
> from bcc. I guess this suprised me, because I'm used to being able to
> specify a semicolon when calling a macro function.
Practice shows that it's not always possible when your macros deal with
templates heavily, so it's in fact easier to maintain the opposite
convention here - no semicolon for auxiliary macros (like
BOOST_MPL_AUX_LAMBDA_SUPPORT or BOOST_MPL_AUX_VOID_SPEC).
> I suppose your example shows no trailing semicolon.
>
> Fourth, you show the declaration of AUX_LAMBDA_SUPPORT as
> being out-of-line, and not specifying the template params,
> when, in fact, it requires the template parameters (which I learned the
> hard way!), and it requires them to be in a tuple (which I also learned
> the hard way!).
MPL is not supposed to give you hard times, so every time you feel it's not
the case, it probably means that something's terribly wrong, and you better
ask for some guidance ASAP :). I hope you didn't spent too much time finding
out the differences between the future interface I was describing and the
current one.
> I don't see how it can guess the template parameters or work properly
> as an out-of-line expression.
It doesn't need to, because they don't have to match:
template< typename Sequence, typename T >
struct find_if
{
struct rebind;
// ...
};
template< typename T1, typename T2 > // here
struct find_if<T1,T2>::rebind
{
};
The only problem with this approach is that there is one compiler that is
not able to compile it - VC 7.0 (MSVC 6.5 is OK).
> I know the lambda part is a work in progress, but I'd really
> like to get this code working. ;)
BOOST_MPL_AUX_VOID_SPEC should get you there.
HTH,
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk