www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Some compile time help..

reply simendsjo <simendsjo gmail.com> writes:
Hi.
I have the following code:
void f(Args...)(Args args) {
   needs_wchar_t(args);
}

I want to loop over Args, and if it's a string of some type, I want to run  
it through toUTFz. For all other values, I just want to push them as  
normal.
How could I solve this?
Mar 04 2012
parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
"simendsjo" <simendsjo gmail.com> wrote in message 
news:op.wanctrbux8p62v simendsjo-desktop...
 Hi.
 I have the following code:
 void f(Args...)(Args args) {
   needs_wchar_t(args);
 }

 I want to loop over Args, and if it's a string of some type, I want to run 
 it through toUTFz. For all other values, I just want to push them as 
 normal.
 How could I solve this?

With a loop? void f(Args...)(Args args) { foreach(i, T; Args) { static if (isSomeString!T) args[i] = toUTFz(args[i]); } needs_wchar_t(args); }
Mar 04 2012
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 3/4/12, Daniel Murphy <yebblies nospamgmail.com> wrote:
 void f(Args...)(Args args) {
   foreach(i, T; Args)
   {
     static if (isSomeString!T) args[i] = toUTFz(args[i]);
   }
   needs_wchar_t(args);
 }

toUTFz returns a pointer, the isSomeString checks if a type is a string. IOW that will try to assign a pointer to a string. But I don't understand the OPs requirements, what type does 'needs_wchar_t' take? A wchar*? A wchar**? Variadic arguments? Or something else?
Mar 04 2012
parent simendsjo <simendsjo gmail.com> writes:
On Sun, 04 Mar 2012 18:14:28 +0100, Andrej Mitrovic  
<andrej.mitrovich gmail.com> wrote:

 On 3/4/12, Daniel Murphy <yebblies nospamgmail.com> wrote:
 void f(Args...)(Args args) {
   foreach(i, T; Args)
   {
     static if (isSomeString!T) args[i] = toUTFz(args[i]);
   }
   needs_wchar_t(args);
 }

toUTFz returns a pointer, the isSomeString checks if a type is a string. IOW that will try to assign a pointer to a string. But I don't understand the OPs requirements, what type does 'needs_wchar_t' take? A wchar*? A wchar**? Variadic arguments? Or something else?

A variadic C function: extern(C) void someFormatting(wchar_t* format, ...) But I get some unexpected results.. wchar_t is defined as dchar on linux and wchar on windows, but it seems to only work with utf8.. Sending in wchar or dchar prints only the first characted as I guess it just see \0 at the next. I'll have to look at the original source in case it has some strange typedefs.
Mar 04 2012
prev sibling parent Artur Skawina <art.08.09 gmail.com> writes:
On 03/04/12 18:14, Andrej Mitrovic wrote:
 On 3/4/12, Daniel Murphy <yebblies nospamgmail.com> wrote:
 void f(Args...)(Args args) {
   foreach(i, T; Args)
   {
     static if (isSomeString!T) args[i] = toUTFz(args[i]);
   }
   needs_wchar_t(args);
 }

toUTFz returns a pointer, the isSomeString checks if a type is a string. IOW that will try to assign a pointer to a string.

http://forum.dlang.org/thread/op.v94npikmx8p62v simendsjo-desktop#post-mailman.940.1330024934.20196.digitalmars-d-learn:40puremagic.com
Mar 05 2012