Re: How to fix date format?

2017-04-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 26, 2017 04:02:12 Suliman via Digitalmars-d-learn wrote:
> I tried to do:
>
> writeln(DateTime.toISOExtString(DateTime.fromSimpleString(point[1].coerce!
> string)));
>
> But got error:
>
> Error: function std.datetime.DateTime.toISOExtString () const is
> not callable using argument types (DateTime)
> Error: function database.Database.getSingleTrackInfo no return
> exp; or assert(0); at end of function

toISOExtString is a normal member function on DateTime, not a static member
function. If point[1].coerce!string is giving you a string in Boost's
"simple time" format (e.g. "2016-Jan-04 12:19:17"), then
DateTime.fromSimpleString(point[1].coerce!string) will give you a DateTime.
Then if you called toISOExtString() on that, e.g.

DateTime dt = DateTime.fromSimpleString(point[1].coerce!string);
string str = dt.toISOExtString();

then the string would be in the ISO extended format (e.g.
"2016-01-04T12:19:17"). If you then wanted that in the format
"2016-01-04 12:19:17", then you could just replace the 'T' with ' ', e.g.

DateTime dt = DateTime.fromSimpleString(point[1].coerce!string);
string str = dt.toISOExtString().replace("T", " ");

And if you have "2016-01-04 12:19:17", and you want to convert that to the
Boost simple time format, you could do

DateTime dt = DateTime.fromISOExtString(str.replace(" ", "T"))
auto simpleStr = dt.toSimpleString();

Hopefully, that helps.

- Jonathan M Davis



Re: How to fix date format?

2017-04-25 Thread Ali Çehreli via Digitalmars-d-learn

On 04/25/2017 10:41 AM, Suliman wrote:

I am using mysql native. Date in DB have next format: 2016-11-01 06:19:37

But every tile when I am trying to get it I am getting such format:
2016-Oct-31 15:37:24

I use next code:
writeln(point[1].coerce!string);

Why coerce is forcing format changing? How I can extract result as
without month name between digits or easily convert it in proper data
format?


Here's a silly little code that gets the job done. :)

import std.stdio;

string[string] numeralMonth;

static this() {
numeralMonth = [ "Jan" : "01", "Feb" : "02", "Mar" : "03", "Apr" : 
"04",
 "May" : "05", "Jun" : "06", "Jul" : "07", "Aug" : 
"08",
 "Sep" : "09", "Oct" : "10", "Nov" : "11", "Dec" : 
"12" ];

}

auto goodDateFormat(string str) {
import std.range : chain, choose;
if (str.length >= 8) {
auto key = str[5..8];
auto numeral = key in numeralMonth;
if (numeral) {
import std.string : format;
return format("%s%s%s", str[0..5], *numeral, str[8..$]);
}
}
return str;
}

void main() {
writeln(goodDateFormat("2016-Oct-31 15:37:24"));
}

Ali



Re: How to fix date format?

2017-04-25 Thread Suliman via Digitalmars-d-learn

I tried to do:

writeln(DateTime.toISOExtString(DateTime.fromSimpleString(point[1].coerce!string)));

But got error:

Error: function std.datetime.DateTime.toISOExtString () const is 
not callable using argument types (DateTime)
Error: function database.Database.getSingleTrackInfo no return 
exp; or assert(0); at end of function


Re: How to fix date format?

2017-04-25 Thread Suliman via Digitalmars-d-learn

On Tuesday, 25 April 2017 at 20:10:02 UTC, Jonathan M Davis wrote:
On Tuesday, April 25, 2017 17:41:25 Suliman via 
Digitalmars-d-learn wrote:
I am using mysql native. Date in DB have next format: 
2016-11-01 06:19:37


But every tile when I am trying to get it I am getting such
format:
2016-Oct-31 15:37:24

I use next code:
writeln(point[1].coerce!string);

Why coerce is forcing format changing? How I can extract 
result as without month name between digits or easily convert 
it in proper data format?


What types are dealing with here? What is point[1]?

- Jonathan M Davis


writeln(point[1].coerce!string);
writeln(point[1].type);


std.datetime.DateTime
std.variant.VariantN!20LU.VariantN


Re: multi-dimensional array whole slicing

2017-04-25 Thread XavierAP via Digitalmars-d-learn

On Tuesday, 25 April 2017 at 20:46:24 UTC, Ali Çehreli wrote:


I think it's still consistent because the element type is not 
int in the case of multi-dimensional arrays.

[...]
int[3][4] b;
b[] = [1, 1, 1];


It is consistent, I just miss the possibility to more easily 
initialize multi-dimensional arrays uniformly in the same way as 
uni-dimensional ones.


I do not mean it would be good to change the current behavior. I 
think the best solution would be for D to implement built-in 
truly multi-dimensional arrays like T[,] as well as the existing 
(jagged) arrays of arrays T[][]. That's what C# does. The former 
could maybe even be lowered into jagged arrays (together with 
their initializations and slicings).


But again most people probably don't miss T[,] built-in arrays, 
specially since we can implement such [,] indexing for custom 
types. So there's not a strong use case.


But actually where I'm using multi-dimensional built-in arrays 
right now is in the private storage of a custom multi-dimensional 
type. Then I have the choice of either use them and live with 
this, but forward indexing transparently; or use uni-dimensional 
as private storage and map from 2d to linear during indexing...


Re: multi-dimensional array whole slicing

2017-04-25 Thread Ali Çehreli via Digitalmars-d-learn

On 04/23/2017 12:04 PM, XavierAP wrote:

> For both multi-dimensional and
> uni-dimensional arrays a[] and a[][] are the same. And yet, a[] has
> different type in both cases and a[]=1 compiles for uni-dimensional but
> not for multi-dimensional.

I think it's still consistent because the element type is not int in the 
case of multi-dimensional arrays. The following makes sense to me but I 
haven't profiled it. Otherwise, kinke's solution is perfectly fine in a 
system programming language. ;)


int[3] a;
a[] = 1;
a[][] = 1;  // Same effect

int[3][4] b;
b[] = [1, 1, 1];
b[][] = [1, 1, 1];  // Same effect

Ali



Re: function type parameter inference not working

2017-04-25 Thread Ali Çehreli via Digitalmars-d-learn

On 04/25/2017 01:02 PM, XavierAP wrote:

> It would be helpful if the error message talked about the ref qualifier
> as the root cause instead of the consequent failure to infer template
> parameters.

That's a common request but the solution is not implemented yet because 
it's not trivial if you consider multiple overloads.


The compiler must remember which parameters failed and present it in a 
readable format: "I considered these overloads and this failed for 
parameter 1 and this other one failed for parameter 2 (although it might 
succeed if it were not ref), etc."


Ali



Re: How to fix date format?

2017-04-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 25, 2017 17:41:25 Suliman via Digitalmars-d-learn wrote:
> I am using mysql native. Date in DB have next format: 2016-11-01
> 06:19:37
>
> But every tile when I am trying to get it I am getting such
> format:
> 2016-Oct-31 15:37:24
>
> I use next code:
> writeln(point[1].coerce!string);
>
> Why coerce is forcing format changing? How I can extract result
> as without month name between digits or easily convert it in
> proper data format?

What types are dealing with here? What is point[1]?

- Jonathan M Davis



Re: function type parameter inference not working

2017-04-25 Thread XavierAP via Digitalmars-d-learn

On Tuesday, 25 April 2017 at 19:57:30 UTC, Ali Çehreli wrote:


This is an intentional limitation of D. It's not possible to 
bind rvalues (temporaries) to reference parameters. The best 
option here is 'auto ref':


Aha I had forgotten about the ref (obviously, otherwise I 
wouldn't have passed a temporary even in the unit test -- I'm 
embarrassed). If that's the reason why it doesn't work I'm 
satisfied.


It would be helpful if the error message talked about the ref 
qualifier as the root cause instead of the consequent failure to 
infer template parameters.


Re: function type parameter inference not working

2017-04-25 Thread Ali Çehreli via Digitalmars-d-learn

On 04/25/2017 12:19 PM, XavierAP wrote:

> void assembleMass1D(Mat, Vec)(ref Mat M, const ref Vec x)
> { /* ... */ }
>
> Matrix!(2,2) M;
> Vector!2 V;
> assembleMass1D(M, V);  // OK
> assembleMass1D(M, Vector!2()); // ERROR template cannot deduce function
>
>
> Is this a bug?

This is an intentional limitation of D. It's not possible to bind 
rvalues (temporaries) to reference parameters. The best option here is 
'auto ref':


void assembleMass1D(Mat, Vec)(auto ref Mat M, auto ref const(Vec) x)
{ /* ... */ }

Ali



Re: function type parameter inference not working

2017-04-25 Thread XavierAP via Digitalmars-d-learn

On Sunday, 23 April 2017 at 19:40:39 UTC, ag0aep6g wrote:


Please post self-contained code. When I fill the gaps you left, 
it works for me:


Found it! It stops working (DMD v2.073.0 for Windows) if it has 
to infer the type of a temporary local variable -- constructed in 
place of the argument:



struct Matrix(size_t nr, size_t nc) {}
struct Vector(size_t n) {}

void assembleMass1D(Mat, Vec)(ref Mat M, const ref Vec x)
{ /* ... */ }

Matrix!(2,2) M;
Vector!2 V;
assembleMass1D(M, V);  // OK
assembleMass1D(M, Vector!2()); // ERROR template cannot deduce 
function



Is this a bug?


Re: How to overload member function pointer and a regualr member function

2017-04-25 Thread Ali Çehreli via Digitalmars-d-learn

On 04/25/2017 11:54 AM, Ali Çehreli wrote:

> _Dmain:
> pushRBP
> movRBP,RSP
> subRSP,010h
> movRAX,_D6deneme4funcFifZv@GOTPCREL[RIP]
> mov-010h[RBP],RAX
> movssXMM0,FLAT:.rodata[00h][RIP]
> movss-8[RBP],XMM0
> leaRDX,_TMP0@PC32[RIP]
> movEDI,0Eh
> movRSI,RDX
> movssXMM0,-8[RBP]
> call  _D3std5stdio17__T8writeflnTaTfZ8writeflnFNfxAafZv@PLT32
> movEAX,02Ah
> movssXMM1,FLAT:.rodata[00h][RIP]
> movss-4[RBP],XMM1
> movRDI,RAX
> movssXMM0,-4[RBP]
> callqword ptr -010h[RBP]
> xorEAX,EAX
> leave
> ret
> add[RAX],AL
> .text._Dmainends
>
> The call to jumbled writefln() is a direct call inside func():
>
> call  _D3std5stdio17__T8writeflnTaTfZ8writeflnFNfxAafZv@PLT32

My analysis is wrong because that writefln() is for the bar(float) 
overload but I still think what you want is achieved.


Ali



Re: How to overload member function pointer and a regualr member function

2017-04-25 Thread Ali Çehreli via Digitalmars-d-learn

On 04/25/2017 11:28 AM, ParticlePeter wrote:
> On Tuesday, 25 April 2017 at 16:27:43 UTC, Basile B. wrote:

>> with pragma(inline, true), the function body should be injected at the
>> call sites.
>
> This would not help I fear, the body of the function pointer is unknown
> in an external lib. I rather hoped that the compiler "sees" the
> parameter forwarding to the fp and is able to directly call it. Best
> thing would be for both overloads, but I would not know how to verify 
this.


pragma(inline, true) works because all you need inlined in this case is 
the body of bar(int, float). The compiler does call the function pointer 
directly.


import std.stdio;

struct Foo1
{
private void function(int,float) _bar;
void bar(float f) {
pragma(inline, true);
writefln("Called with %s", f);
}
void bar(int i, float f) {
pragma(inline, true);
_bar(i,f);
}
}

void func(int i, float f) {
writefln("Called with %s and %s", i, f);
}

void main() {
auto f = Foo1();
f.bar(1.5);
f.bar(42, 2.5);
}

Compile with -inline (and perhaps with -O):

  dmd -inline deneme.d

Generate the disassembly with obj2asm that comes with dmd (or with any 
other disassembly tool):


  obj2asm deneme.o > deneme.asm

You can open deneme.asm in an editor and search for function "_Dmain:" 
in it. Here is what my dmd 2.074 produced:


_Dmain:
pushRBP
mov RBP,RSP
sub RSP,010h
mov RAX,_D6deneme4funcFifZv@GOTPCREL[RIP]
mov -010h[RBP],RAX
movss   XMM0,FLAT:.rodata[00h][RIP]
movss   -8[RBP],XMM0
lea RDX,_TMP0@PC32[RIP]
mov EDI,0Eh
mov RSI,RDX
movss   XMM0,-8[RBP]
call  
_D3std5stdio17__T8writeflnTaTfZ8writeflnFNfxAafZv@PLT32
mov EAX,02Ah
movss   XMM1,FLAT:.rodata[00h][RIP]
movss   -4[RBP],XMM1
mov RDI,RAX
movss   XMM0,-4[RBP]
callqword ptr -010h[RBP]
xor EAX,EAX
leave
ret
add [RAX],AL
.text._Dmainends

The call to jumbled writefln() is a direct call inside func():

call  
_D3std5stdio17__T8writeflnTaTfZ8writeflnFNfxAafZv@PLT32

So, you're good... :)

Ali



Re: COM Expertise needed: COM Callbacks

2017-04-25 Thread Nierjerson via Digitalmars-d-learn

On Tuesday, 25 April 2017 at 10:03:30 UTC, Atila Neves wrote:

On Monday, 24 April 2017 at 00:55:45 UTC, Nierjerson wrote:
Still trying to get the com automation code working. This is a 
general issue with COM programming as I do not have the 
experience to solve the problem.


[...]


I tried looking at this because I just did some COM work even 
if most of it in C++. There's a _lot_ of code and I was 
instantly lost, even with your explanations.


There isn't a lot of code! All the code in Gen is irrelevant 
except for a few functions... even then, you don't ever really 
need to mess with it except to see a few of the definitions.


99.9% of the code is irrelevant, I could have removed most of it 
and it would function the same. The reason why I left it in is 
for completeness and because many of the different classes 
reference other classes so having one sorta requires having all 
the rest(even though they are never used, it is to avoid missing 
symbols, etc, which can be fixed but would require some editing 
and would prevent the code from working).


Only three classes are used is used in Gen.d: cApplication, 
cSolidColor, and cRGBColor.


One only really needs to look at main.d. I've put all the code 
necessary in that file. One only needs to look at Gen.d to get 
the general idea and at that, only those specific classes.





I'd forget about Photoshop for now, just write a simple COM 
client. That'd also ease in getting other people to help 
because having Photoshop is a high barrier for entry.


Photoshop is the main app I'm trying to get to work so this is 
appropriate for me and it is also the only real way I have to 
test COM.





Can you get this to work in C++?


The code generation probably could be tailored to work in C++ 
without too much issue. I'm not going to do it though! Too much 
work as it is and I first need to get this to work. I don't see 
any real difference between D and C++(if I'm going to use C++ for 
anything I'm going to use D instead). I've already had to rewrite 
the engine because D's CTFE could not handle the load. So this 
has turned out to be quite a bit of work.



---

The main issue has nothing to do with PS though(I imagine it is a 
general COM programming task).


The server(PS in this case) gives me an interface that has 
functions like RGB(cRGBColor rgb); (Actually a _RGBColor com 
interface which I wrap with a cRGBColor interface to provide the 
ability to handle the marshaling and such behind the scenes),



So I pass it a cRGBcolor interface, which actually can't be used 
because photoshop has no clue about that type.


Instead, I construct a dummy interface that inherits from 
IDispatch which I'll pass to server instead. I'll use it as a 
wrapper to hook up everything I need.


The problem is, when I do this, the app crashes. I do not know 
why. What I do know is that it seems to be calling QueryInterface 
and so it seems like it might actually be getting to the server 
and the server is calling the QueryInterface method. If that is 
the case, then the passing of the interface is working but 
something else is failing.


I'm just not sure though as I don't know enough about COM to 
determine what exactly is going on(after all, it's all happening 
on the server "behind closed doors").






auto rgb2 = new icRGBColor();
rgb2.iDispatch = rgb2;
//auto rgb = cast(icRGBColor)
//dd.RGB(cast(cRGBColor)(cast(void*)rgb));
//dd.RGB(cast(icRGBColor)(cast(void*)rgb));


cSolidColor.RGBSet = 
auto rgb = new icRGBColor();
//auto rgb = cast(icRGBColor)(cast(void*)dd.RGB());
	dd.RGB(rgb); // <--- This is where the work begins! Tries to get 
photoshop to set the RGB color through the rgb object



return 0;
}

// This is the invoker.Only useful for debugging(brought out from 
Gen.d here for convenience
// The invoke line is what is important. When it is called, 
photoshop will be given the icRGBColor object and will do things 
with it(if it works, that is... seems to and seems to call 
QueryInterface but doesn't get any further).

void RGB(icRGBColor ic, cSolidColor s)
{
import main;
EXCEPINFO exception;
uint argErr = 0;
auto iidNULL = IID_NULL;
auto RT = new SafeVariantPtr();
VARIANT[1] paramVars;
	DISPPARAMS params = {rgvarg: paramVars.ptr, cArgs: 1, 
cNamedArgs: 0};

auto ID = s.COMMethodIDs[`RGB`];
	paramVars[0].punkVal = ic; paramVars[0].vt = 
VARENUM.VT_DISPATCH; scope(exit) VariantClear([0]);
	auto res = s.iDispatch.Invoke(cast(int)ID, , 0, 
DISPATCH_PROPERTYPUT, , cast(VARIANT*)RT, , 
);
	assert(res == S_OK, `Could not invoke COM Function 
cSolidColor.RGB. Error `~to!string(res, 16));


}



...

The icRGBColor interface that follows is a simple callback 
interface. All the methods simply print their function name when 
called, this helps to know when they are called.


When one runs the program they should see a few calls to 

Re: How to overload member function pointer and a regualr member function

2017-04-25 Thread ParticlePeter via Digitalmars-d-learn

On Tuesday, 25 April 2017 at 16:27:43 UTC, Basile B. wrote:

On Tuesday, 25 April 2017 at 15:43:48 UTC, ParticlePeter wrote:

On Tuesday, 25 April 2017 at 09:50:14 UTC, Basile B. wrote:

On Monday, 24 April 2017 at 16:46:21 UTC, ParticlePeter wrote:


Thanks for your reply, but that's what I would like to avoid, 
the additional indirection to call the function pointer with 
the original argument count.


Oops, i can believe i didn't read the last part of your 
question.


Do you have any idea about the likelihood of the compiler 
removing this indirection as an optimizations?


with pragma(inline, true), the function body should be injected 
at the call sites.


This would not help I fear, the body of the function pointer is 
unknown in an external lib. I rather hoped that the compiler 
"sees" the parameter forwarding to the fp and is able to directly 
call it. Best thing would be for both overloads, but I would not 
know how to verify this.


Re: Set Intersection and Set Difference on Compile-Time lists

2017-04-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 25, 2017 at 05:43:34PM +, David Sanders via Digitalmars-d-learn 
wrote:
[...]
> Order is not important. (float, int) is a subset of (int, int, float).
> (int, int, float) is not the same thing as (int, float). Duplicates in
> the list are considered to be distinct set members.
> 
> The lists are not assumed to be sorted, but the first step could be to
> sort the lists. This would lead to the question of how do I sort
> compile-time lists of types?
[...]

You can probably save yourself a lot of headache by taking up my
suggestion to implement operations on types as strings, and then using a
mixin to turn them back into types afterwards. You can use .stringof to
get the string representation of each item in the list, which can then
be sorted in CTFE using std.algorithm, and you can even use
std.algorithm to do set operations on the list to save yourself the
trouble of reimplement those algorithms.

Here's a working proof of concept:


alias List(T...) = T;

// Convert a type list into an array of strings (type names).
template ToString(T...)
{
static if (T.length == 0)
enum ToString = [];
else
enum ToString = [T[0].stringof] ~ ToString!(T[1 .. $]);
}

unittest
{
import std.algorithm.comparison : equal;
import std.algorithm.sorting : sort;

static assert(ToString!(int, int, float) == ["int", "int", "float"]);
static assert(ToString!(int, double, float).sort()
.equal(["double", "float", "int"]));
}

// Convert an array of strings back to a type list.
template ToTypes(string[] typenames)
{
import std.array : array;
import std.algorithm.iteration : joiner;

mixin("alias ToTypes = List!(" ~ typenames.joiner(",").array ~ ");");
}

unittest
{
pragma(msg, ToTypes!(["int", "double", "float"]));
static assert(is(ToTypes!(["int", "double", "float"]) ==
List!(int, double, float)));
}

// Computes the intersection of two type lists.
template IntersectionOf(A...)
{
template With(B...)
{
// We need .array because Phobos likes packaging things up
// inside wrappers, but ToTypes only understands built-in
// arrays.
import std.array : array;
import std.algorithm.sorting : sort;
import std.algorithm.setops : setIntersection;

// Turn the lists into string arrays, use CTFE to compute set
// operations, then turn it back to a type list.
alias With = ToTypes!(
setIntersection(ToString!A.sort(),
ToString!B.sort())
.array);
}
}

unittest
{
// Here's how to use all of this to do what you want.
static assert(is(
IntersectionOf!(int, int, float).With!(float, byte, int) ==
List!(float, int)));
}


Implementing other set operations should be essentially the same thing
as the above, just substitute setIntersection with setDifference,
nWayUnion, etc..


T

-- 
They pretend to pay us, and we pretend to work. -- Russian saying


Re: Set Intersection and Set Difference on Compile-Time lists

2017-04-25 Thread David Sanders via Digitalmars-d-learn

On Tuesday, 25 April 2017 at 17:18:25 UTC, H. S. Teoh wrote:
On Tue, Apr 25, 2017 at 05:08:36PM +, David Sanders via 
Digitalmars-d-learn wrote:
I have two compile-time lists of types. How do I find their 
set intersection (to determine if one is a subset of the 
other) and their set difference? See the block comments below:


What's your definition of set intersection / set difference? Is 
order
important?  For example, is (float, int) a subset of (int, int, 
float),
or do you only consider (int, float) to be a subset of (int, 
int,
float)?  Also, is (int, int, float) the same thing as (int, 
float) or
are duplicates in the list considered to be distinct set 
members?


If order is not important, can the lists be assumed to be 
sorted?


If order is not important and the lists are not sorted, you may 
run into trouble with this kind of code, because you'd need to 
implement O(n^2) algorithms for computing subsets / set 
differences, and given the way templates are currently 
implemented, this may quickly exhaust available memory in the 
compiler.


Given what you're trying to achieve, you *may* have better luck 
implementing your type arithmetic using string manipulations, 
and then a mixin at the end to turn it back into a type list.



--T


Order is not important. (float, int) is a subset of (int, int, 
float). (int, int, float) is not the same thing as (int, float). 
Duplicates in the list are considered to be distinct set members.


The lists are not assumed to be sorted, but the first step could 
be to sort the lists. This would lead to the question of how do I 
sort compile-time lists of types?


Thanks,
Dave


How to fix date format?

2017-04-25 Thread Suliman via Digitalmars-d-learn
I am using mysql native. Date in DB have next format: 2016-11-01 
06:19:37


But every tile when I am trying to get it I am getting such 
format:

2016-Oct-31 15:37:24

I use next code:
writeln(point[1].coerce!string);

Why coerce is forcing format changing? How I can extract result 
as without month name between digits or easily convert it in 
proper data format?


Re: Set Intersection and Set Difference on Compile-Time lists

2017-04-25 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 25, 2017 at 05:08:36PM +, David Sanders via Digitalmars-d-learn 
wrote:
> I have two compile-time lists of types. How do I find their set
> intersection (to determine if one is a subset of the other) and their
> set difference? See the block comments below:

What's your definition of set intersection / set difference? Is order
important?  For example, is (float, int) a subset of (int, int, float),
or do you only consider (int, float) to be a subset of (int, int,
float)?  Also, is (int, int, float) the same thing as (int, float) or
are duplicates in the list considered to be distinct set members?

If order is not important, can the lists be assumed to be sorted?

If order is not important and the lists are not sorted, you may run into
trouble with this kind of code, because you'd need to implement O(n^2)
algorithms for computing subsets / set differences, and given the way
templates are currently implemented, this may quickly exhaust available
memory in the compiler.

Given what you're trying to achieve, you *may* have better luck
implementing your type arithmetic using string manipulations, and then a
mixin at the end to turn it back into a type list.


--T


Set Intersection and Set Difference on Compile-Time lists

2017-04-25 Thread David Sanders via Digitalmars-d-learn
I have two compile-time lists of types. How do I find their set 
intersection (to determine if one is a subset of the other) and 
their set difference? See the block comments below:


import std.variant;

alias Zero = void;

struct One{}

struct Difference(T, U) {
static if (is(U == Zero)) alias type = T;
else static if(is(T == U)) alias type = Zero;
else static if (is(T _ == VariantN!V, V...)) {
static if(is(U __ == VariantN!W, W...)) {
/* if W[1..$] is a subset of V[1..$] alias type = 
Algebraic!(setDifference(V[1..$], W[1..$])) */

} else {
/* if U is subset of V[1..$] alias type = 
Algebraic!(setDifference(V[1..$], U)) */

}
} else static if(is(U _ == VariantN!V, V...)) {
/* if V[1..$] is a single element set containing T alias 
type = Zero */

}

unittest
{
static assert (is(Zero == Difference!(Zero, Zero).type));
static assert (is(One == Difference!(One, Zero).type));
static assert (!is(Difference!(Zero, One).type));
static assert (is(Algebraic!(One) == 
Difference!(Algebraic!(One, One), Algebraic!(One)).type));

}
}

void main() {
alias type = Difference!(One, Zero).type;
}


Re: How to overload member function pointer and a regualr member function

2017-04-25 Thread ParticlePeter via Digitalmars-d-learn

On Tuesday, 25 April 2017 at 09:50:14 UTC, Basile B. wrote:

On Monday, 24 April 2017 at 16:46:21 UTC, ParticlePeter wrote:

I would like to have this kind of struct:

struct Foo {
  private int i;
  void function( int i, float f ) bar;  // will be defined at 
runtime

  void bar( float f ) {
bar( i, f );
  }
}

[...]
How else can I get the required behavior?


Like this:

struct Foo1
{
private void function(int,float) _bar;
void bar(float){}
void bar(int i, float f){_bar(i,f);}
}


Thanks for your reply, but that's what I would like to avoid, the 
additional indirection to call the function pointer with the 
original argument count.
Do you have any idea about the likelihood of the compiler 
removing this indirection as an optimizations?


Re: using shared effectively in a producer/consumer situation.

2017-04-25 Thread Kagamin via Digitalmars-d-learn

On Sunday, 23 April 2017 at 20:33:48 UTC, Kevin Balbas wrote:

Is this the correct way to do it?
 cast to shared, send to main thread, cast away shared?


Yes, as long as the thing is unique, you can cast it to shared or 
immutable just fine.


Re: GC: Understanding potential sources of false pointers

2017-04-25 Thread Kagamin via Digitalmars-d-learn

They are for static data an thread-local storage.


Re: COM Expertise needed: COM Callbacks

2017-04-25 Thread Atila Neves via Digitalmars-d-learn

On Monday, 24 April 2017 at 00:55:45 UTC, Nierjerson wrote:
Still trying to get the com automation code working. This is a 
general issue with COM programming as I do not have the 
experience to solve the problem.


[...]


I tried looking at this because I just did some COM work even if 
most of it in C++. There's a _lot_ of code and I was instantly 
lost, even with your explanations.


I'd forget about Photoshop for now, just write a simple COM 
client. That'd also ease in getting other people to help because 
having Photoshop is a high barrier for entry.


Can you get this to work in C++?


Re: How to overload member function pointer and a regualr member function

2017-04-25 Thread Basile B. via Digitalmars-d-learn

On Monday, 24 April 2017 at 16:46:21 UTC, ParticlePeter wrote:

I would like to have this kind of struct:

struct Foo {
  private int i;
  void function( int i, float f ) bar;  // will be defined at 
runtime

  void bar( float f ) {
bar( i, f );
  }
}

[...]
How else can I get the required behavior?


Like this:

struct Foo1
{
private void function(int,float) _bar;
void bar(float){}
void bar(int i, float f){_bar(i,f);}
}

Or like this:

struct Foo2
{
private void function(int,float) _bar;
void bar(float) {}
void function(int,float) bar() {return _bar;}
}


First solution looks better:

(new Foo2).bar()(0,0f) // less good
(new Foo1).bar(0,0f) // better




Re: Why File is exists in std.stdio and in std.file?

2017-04-25 Thread FreeSlave via Digitalmars-d-learn

On Tuesday, 25 April 2017 at 07:05:51 UTC, Suliman wrote:
Just interesting. Is there any rational reasons for this 
decision?


There's no File in std.file. It's located in std.stdio.
std.stdio and std.file are different modules. The first one has 
safe wrappers around stdio.h from C library, the second one 
provides operations on files as unit.


Re: Why File is exists in std.stdio and in std.file?

2017-04-25 Thread Daniel Kozák via Digitalmars-d-learn
V Tue, 25 Apr 2017 07:05:51 +
Suliman via Digitalmars-d-learn 
napsáno:

> Just interesting. Is there any rational reasons for this decision?
No it isn't. File is only in std.stdio;



Why File is exists in std.stdio and in std.file?

2017-04-25 Thread Suliman via Digitalmars-d-learn

Just interesting. Is there any rational reasons for this decision?