lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Matthew A. Nicholson wrote:
Jérôme VUARAND wrote:
2007/2/25, Thomas Harning Jr. <harningt@gmail.com>:
On 2/25/07, Matthew A. Nicholson <matt@matt-land.com> wrote:
Great job on the library, however I think it could use a little fixing
for the 'as' function.  Passing in a variable of the type in order to
get C++ to know what type to use doesn't sound like the best idea.
Using C++ templates seems to make the most sense to me.

Instead of:
int val = L.as(0, index);
It would be:
int val = L.as<int>(index);

... Just my 2 cents.

I was about to make the same suggestion. And if your original
intention was to write more generic code like :

int val;
val = L.as(val, index);

with a modern compiler you could write :

int val = L.as<typeof(val)>(index);

Not all compiler support the typeof operator yet, but GCC does and
template based limited implementations exist for those that don't.

The design for that function was taken from pqxx:

http://thaiopensource.org/devprojects/libpqxx/doc/2.6.8/html/Reference/

Looking at their docs, they use a template for it too (and have the option to specify a default value to return if the conversion fails). I will update it to match.

Here is the proper link:

http://thaiopensource.org/devprojects/libpqxx/doc/2.6.8/html/Reference/a00256.html#c1fc1b948ccb55079652b21b2b0b7abf
(http://tinyurl.com/36ukhs)

Thanks for the feedback.
--
Matthew A. Nicholson
matt-land.com