Still trawling through old stuff I found stream_cast<>

----------  Forwarded Message  ----------

Subject: stream_cast<>
Date: 13 Oct 2000 15:51:52 +0200
From: [EMAIL PROTECTED] (Lars Gullik Bjønnes)
To: [EMAIL PROTECTED]

A nice thing that popped out on clpc++

template <class T, class S>
T stream_cast(S const & s)
{
        stringstream st;
        st << s;
        st.gseek(0);
        T t;
        st >> t;
        return t;
}

this is a very simplistic implementation...

I want to convert a string to int:

int a = stream_cast<int, string>("123");

or a int to string:

string a = stream_cast<string, int>(123);

This could easily be used for the FuncSlot.

        Lgb

-------------------------------------------------------

and I also found Allan's follow up

----------  Forwarded Message  ----------

Subject: Re: stream_cast<> and Re: LyXFunc/LyXAction
Date: Thu, 19 Oct 2000 16:49:54 +1000 (GMT+1000)
From: Allan Rae <[EMAIL PROTECTED]>
To: LyX Developers <[EMAIL PROTECTED]>

On 14 Oct 2000, Lars Gullik Bjønnes wrote:
[...]

> more on FuncSlot... when I first though of this it was as a direct
> replacement for the string that we pass to dispatch now, it is not too
> hard to create a FuncSlot that can transfere the type untranslated.
> It would be a larger implementation because we would need to create an
> small class hierachy for the types possible to transfere with
> FuncSlot... all of these would have to have the same root class.

C/C++ Users Journal October 2000 edition has an even better(?) idea using
templates that is pretty neat (and somewhat larger).  They define an
elaborate template class variant_t and an ArguementList class that uses
it.  It even allows type-safe access to the arguement list (and throws an
exception if the type you want doesn't match).

That way you can pass anything you like and it doesn't have to be
derived from some common class.

Allan. (ARRae)

-------------------------------------------------------

This sounds like xtl to me. Would FuncRequest not benefit from this? (No-more 
unscrambling of stringifications...)


Angus

Reply via email to