View mode: basic / threaded / horizontal-split · Log in · Help
September 19, 2005
Re: Compile-time variadic functions
AJG wrote:
<snip>
> For example, why couldn't I do something like the following:
> 
> void Foo(...) in {
>     static assert(_arguments.length > 1);
>     static if (_arguments[0] == typeid(float)) {
>         pragma(msg, "Warning, float will be truncated to int.");
>     }
> }

Why would you want to truncate floats but pass all other types through 
unchanged?

If OTOH you want the first argument to be an int, then you would do

    void Foo(int bar, ...) {
    }

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:- C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- 
PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.
September 19, 2005
Re: Compile-time variadic functions
Hi,

Stewart Gordon wrote:
> AJG wrote:
> <snip>
> 
>> For example, why couldn't I do something like the following:
>>
>> void Foo(...) in {
>>     static assert(_arguments.length > 1);
>>     static if (_arguments[0] == typeid(float)) {
>>         pragma(msg, "Warning, float will be truncated to int.");
>>     }
>> }
> 
> 
> Why would you want to truncate floats but pass all other types through 
> unchanged?
> 
> If OTOH you want the first argument to be an int, then you would do
> 
>     void Foo(int bar, ...) {
>     }
> 
> Stewart.
> 

No, the example was trivial and not intended to do anything sensible.

The point was to show that variadic functions should be resolved at 
compile time so that static checks can be done. Right now, those checks 
must:

a) Occur at runtime.
b) Occur every time a function is called.

This is completely unnecessary. Everything (AFAIK) needed to convert the 
process to compile-time is there. Functions cannot be called with a 
dynamically-built parameter list. Therefore, why treat it as if it were one?

I think the solution lies with what the others suggested, i.e., some 
form of implicit templating.

Cheers,
--AJG.
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home