From: "Trey Jackson" <[EMAIL PROTECTED]>

> 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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to