Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 04, 2012 Some compile time help.. | ||||
---|---|---|---|---|
| ||||
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? |
March 04, 2012 Re: Some compile time help.. | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | "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); } |
March 04, 2012 Re: Some compile time help.. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | 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?
|
March 04, 2012 Re: Some compile time help.. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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.
|
March 05, 2012 Re: Some compile time help.. | ||||
---|---|---|---|---|
| ||||
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 |
Copyright © 1999-2021 by the D Language Foundation