|
Boost : |
From: Dave Abrahams (dave_at_[hidden])
Date: 2003-02-06 14:27:05
From: "Trey Jackson" <tjackson_at_[hidden]>
> Hamish Mackenzie wrote:
> >These scoped locks will go out of scope before you "do stuff".
>
> Right, thanks for the catch.
>
> I started writing it thinking I'd be doing some cool new
> meta-programming, but it turned into just simple object inheritance
> (thus the function calls that let the locks go out of scope).
>
> But my original intent was actually to try to get code substituted at
> compile time.
>
> e.g.
>
> template<class ToBeSubstituted>
> class userClass {
> void function() {
> // code is inserted here, not a function call to a member of
ToBeSubstituted
> ToBeSubstituted::insertCode;
> }
> }
>
> class SubstituteHello {
> <whatever> insertCode {
> cout << "hello world" << endl;
> }
> }
>
> class SubstituteGoodbye {
> <whatever> insertCode {
> cout << "goodbye world" << endl;
> }
> }
>
>
> userClass<SubstituteHello> u1;
> u1.function(); // prints 'hello world'
>
> userClass<SubstituteHello> u2;
> u2.function(); // prints 'goodbye world'
>
>
>
>
>
> Any tips on how to do this?
> Is it possible in C++? I can see how to do it with lisp macros.
> I'm reading the MPL intro written by David Abrahams and Aleskey
> Gurtovoy, but it's slow going...
I don't think you need that document. Whatever could be:
typedef void fn(); static fn
In other words, make them static functions. userClass::function just needs
to add a couple of parens after "insertCode" ;-)
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk