On Friday, 15 August 2025 at 21:45:09 UTC, Marc wrote:
On Friday, 15 August 2025 at 21:09:50 UTC, Ali Çehreli wrote:
>
> Any help would be really appreciated.
This design doesn't seem useful. How about something like the
following:
import std.conv : to;
x[i, j].to!double;
y[i, j].to
On Monday, 18 August 2025 at 17:58:54 UTC, Dejan Lekic wrote:
So, to fix your error, you can remove the "const" method
qualifier from opApply, or cast the const away from the member
when you use it.
Thanks for the tip. It just needed more 'const' keywords
sprinkled in here and there.
Here
On Monday, 18 August 2025 at 13:32:57 UTC, Brother Bill wrote:
Page 496 of Programming in D
Going in circles. Please correct so it compiles and works.
An explanation would be helpful also.
Ali's book have a section about const member qualifier - "51.5
const member functions", but I think it
Page 496 of Programming in D
Going in circles. Please correct so it compiles and works.
An explanation would be helpful also.
Error Message
```
c:\dev\D\71 - 80\c73_2d_School_Student_Teacher\source\app.d(23):
Error: cannot implicitly convert expression
`this.students[cast(ulong)i]` of type `c
On Friday, 15 August 2025 at 21:09:50 UTC, Ali Çehreli wrote:
>
> Any help would be really appreciated.
This design doesn't seem useful. How about something like the
following:
import std.conv : to;
x[i, j].to!double;
y[i, j].to!float;
Ali
Thanks a lot for your reply. It should be
upposed
to allow the [i, j] syntax. Additionally, it is not clear what the
meaning of !double vs. !float is.
Wouldn't it be a bug to call !double when the data is float?
> It just doesn't work and I get the error `is not a
> template declaration, it is a variable`.
>
> ``
On Friday, 15 August 2025 at 17:51:50 UTC, Nick Treleaven wrote:
On Friday, 15 August 2025 at 17:38:53 UTC, Marc wrote:
Hello,
In my typed data frames I've this type of code. It works for
default value (float) but I can't call `opIndex!double[i, j]`
or `opIndex!string[i,j]`.
You need to writ
On Friday, 15 August 2025 at 17:38:53 UTC, Marc wrote:
Hello,
In my typed data frames I've this type of code. It works for
default value (float) but I can't call `opIndex!double[i, j]`
or `opIndex!string[i,j]`.
You need to write `opIndex!double(i, j)` to manually call the
method. (You're usi
Hello,
In my typed data frames I've this type of code. It works for
default value (float) but I can't call `opIndex!double[i, j]` or
`opIndex!string[i,j]`. It just doesn't work and I get the error
`is not a template declaration, it is a variable`.
```d
// Overload [i, j]
On Monday, 17 February 2025 at 09:33:32 UTC, mig09 wrote:
On Monday, 17 February 2025 at 09:17:24 UTC, ShadoLight wrote:
On Sunday, 16 February 2025 at 17:04:39 UTC, Jonathan M Davis
wrote:
[..]
Ok, gotcha. I suspected that is what you meant and agree with
that (in my example an implicit m
On Monday, 17 February 2025 at 09:17:24 UTC, ShadoLight wrote:
On Sunday, 16 February 2025 at 17:04:39 UTC, Jonathan M Davis
wrote:
[..]
Ok, gotcha. I suspected that is what you meant and agree with
that (in my example an implicit match would more sense on
'long', not 'bool').
Thanks for
On Sunday, 16 February 2025 at 17:04:39 UTC, Jonathan M Davis
wrote:
[..]
Ok, gotcha. I suspected that is what you meant and agree with
that (in my example an implicit match would more sense on 'long',
not 'bool').
Thanks for the detailed answer.
On Sunday, February 16, 2025 4:54:46 AM MST ShadoLight via Digitalmars-d-learn
wrote:
> On Sunday, 16 February 2025 at 05:39:07 UTC, Jonathan M Davis
> wrote:
> > _especially_ when VRP comes into play, because then you get
> > nonsense like foo(1) calling the bool overload.
&g
On Sunday, 16 February 2025 at 05:39:07 UTC, Jonathan M Davis
wrote:
_especially_ when VRP comes into play, because then you get
nonsense like foo(1) calling the bool overload.
I have often seen this mentioned, but I only see this happen if
there *isn't* an integer overload i.e.
eventually end up with so many that no human
> can remember them all, and code becomes much harder to understand.
>
> In C++, for example, overload resolution is extremely
> complicated, because they added a bunch of rules to make these
> kinds of "obvious" examples work:
>
rule so that the
compiler can also see it!
The problem with this approach is that, if you keep adding more
and more rules, you eventually end up with so many that no human
can remember them all, and code becomes much harder to understand.
In C++, for example, overload resolution is extremely
On Friday, 14 February 2025 at 15:58:26 UTC, Paul Backus wrote:
In your example, both overloads have match level 2: "match with
implicit conversions". So the compiler attempts to figure out
which one is more specialized by checking whether the
parameters of one overload can be us
On Friday, 14 February 2025 at 17:29:33 UTC, Andy Valencia wrote:
On Friday, 14 February 2025 at 15:58:26 UTC, Paul Backus wrote:
void foo(long x) { }
void foo(ulong x) { }
So I take it that a template with a static isSigned test would
be the way to bifurcate foo()'s behavior?
Andy
Yes, t
On Friday, 14 February 2025 at 15:58:26 UTC, Paul Backus wrote:
void foo(long x) { }
void foo(ulong x) { }
So I take it that a template with a static isSigned test would be
the way to bifurcate foo()'s behavior?
Andy
unsigned type with same priority as a
signed type?!?
Clearly a longer type with matching signedness should always be
a better match than a type that will discard the sign, no?
Here's the spec for overload resolution:
https://dlang.org/spec/function.html#function-overloading
In your ex
On Friday, 14 February 2025 at 04:28:25 UTC, Dom DiSc wrote:
Why does this happen:
```d
void foo(long x) { }
void foo(ulong x) { }
[...]
trying to confused the compiler
try that in c++ it will compile with no warnings
how would the compiler actually know the dif between ulong 1,
long 1, if n
Why does this happen:
```d
void foo(long x) { }
void foo(ulong x) { }
main()
{
foo(short(17)); // error: `foo` called with argument types
`(short)` matches both: `foo(long x)` and: foo(ulong x)`
}
```
Why does a short match an unsigned type with same priority as a
signed type?!?
Clearly a
an extremely overload draw function that
eventually calls some set of these functions, but Im pretty sure
that "named arguments dont survive T..." is causing problems for
me, and I'm unsure how to work around it as I make more complex
versions.
https://github.com/crazymonkyyy/r
more obfuscated for
which cases there is an overload and for which not.
A good (?!?) example of how bad this can get is the "to" template.
On Sat, May 27, 2023 at 05:49:27PM +, vushu via Digitalmars-d-learn wrote:
> On Saturday, 27 May 2023 at 16:38:43 UTC, Steven Schveighoffer wrote:
[...]
> > void make_lava(T)(ref T lava) if (hasMagma!T) {
> > lava.magma();
> > }
> >
> > void make_lava(T)(ref T lava_thing) if (!hasMagma!T){
lava();
}
```
-Steve
I see thanks for the example :), I think this probably the
closest equivalent i dlang.
I feel like overload in that case make things harder to read
My example has less context switch, and hte logic is correctly
understandable at first sight
Only one make_lava functio
:), I think this probably the
closest equivalent i dlang.
I feel like overload in that case make things harder to read
My example has less context switch, and hte logic is correctly
understandable at first sight
Only one make_lava function
On Saturday, 27 May 2023 at 16:38:43 UTC, Steven Schveighoffer
wrote:
On 5/27/23 9:50 AM, vushu wrote:
On Saturday, 27 May 2023 at 13:42:29 UTC, Basile B. wrote:
[...]
Yes I know there is template constraint, but not with
specialized overloading right?
so you need to use static if for chec
On 5/27/23 9:50 AM, vushu wrote:
On Saturday, 27 May 2023 at 13:42:29 UTC, Basile B. wrote:
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote:
[...]
Is there something equivalent in dlang, doesn't seem like d support
specialized overload?
D solution is called [template
constr
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote:
you can use: ``static if (__traits(hasMember, T, "magma"))``
```D
import std;
struct LavaMan {
void magma() { writeln(" LavaMan is throwing LAVA"); }
}
struct FakeVulcano {
void try_making_lava() { writeln( " Making fake lava"); }
}
On Saturday, 27 May 2023 at 13:42:29 UTC, Basile B. wrote:
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote:
[...]
Is there something equivalent in dlang, doesn't seem like d
support specialized overload?
D solution is called [template
constraints](https://dlang.org/spec/template
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote:
[...]
Is there something equivalent in dlang, doesn't seem like d
support specialized overload?
D solution is called [template
constraints](https://dlang.org/spec/template.html#template_constraints).
ing LAVA
```
Is there something equivalent in dlang, doesn't seem like d
support specialized overload?
Hi,
for the source code below, the compiler says:
app.d(26): constructor `app.TObject.this` hides base class
function `app.DelphiObject.this`
app.d(26): add `alias this = app.DelphiObject.this` to
`app.TObject`'s body to merge the overload sets
But if I add `alias
On Sunday, 11 September 2022 at 09:47:34 UTC, solidstate1991
wrote:
Here's this code:
This should be allowed, but also the way you're supposed to write
it now is a no-argument opIndex.
Here's this code:
```d
auto opSlice()
{
struct Range
{
Attr currentAttr;
auto front() { return currentAttr; }
void popFront() { currentAttr = currentAttr._nextAttr; }
bool empty() { return currentAttr is null; }
}
return Range(firstAttr);
}
```
Th
On Monday, 1 August 2022 at 00:23:21 UTC, Hipreme wrote:
On Sunday, 31 July 2022 at 19:25:51 UTC, Hipreme wrote:
[...]
Seems that is how it should be checked:
```d
enum hasOverload(T, string member, FuncType)()
{
bool ret;
static foreach(overload; __traits
On Sunday, 31 July 2022 at 19:25:51 UTC, Hipreme wrote:
I wish to generate some functions using mixin template and I
wish to check if the current class already has an specific
overload with parameters (A, B).
What I'm currently trying is doing `__traits(getOverloads, T,
"foo&qu
I wish to generate some functions using mixin template and I wish
to check if the current class already has an specific overload
with parameters (A, B).
What I'm currently trying is doing `__traits(getOverloads, T,
"foo")`, and then checking if its type are equal. But it seems
On Tue, Feb 15, 2022 at 06:37:44PM +, meta via Digitalmars-d-learn wrote:
> A trick i use often:
>
> ```D
> import std;
>
> void main()
> {
> import uni = std.uni;
> writeln("Learning D is fun".split!(uni.isWhite));
> }
>
> ```
>
> Under-rated way of importing things, you don't blo
A trick i use often:
```D
import std;
void main()
{
import uni = std.uni;
writeln("Learning D is fun".split!(uni.isWhite));
}
```
Under-rated way of importing things, you don't bloat your scope
anymore
ront
```
That second check is testing to see if it compiles, and if it doesn't
for any reason, then it doesn't match.
Now, the symbol `isWhite` is an overload set, which is in error
(ambiguous). So I'm not sure how to test this better.
Note, if I copy the entire definition of
On Monday, 14 February 2022 at 11:37:38 UTC, ag0aep6g wrote:
On 14.02.22 12:14, forkit wrote:
However, if I uncomment the //import std.uni : isWhite;
then it will compile.
I don't understand. I thought 'import std;' would be
sufficient here??
"isWhite" is ambiguous. There's std.uni.isWhite
On 14.02.22 12:14, forkit wrote:
However, if I uncomment the //import std.uni : isWhite;
then it will compile.
I don't understand. I thought 'import std;' would be sufficient here??
"isWhite" is ambiguous. There's std.uni.isWhite and std.ascii.isWhite.
`import std;` can't know which one you
This code will not compile.
Error: no overload matches for `split`
However, if I uncomment the //import std.uni : isWhite;
then it will compile.
I don't understand. I thought 'import std;' would be sufficient
here??
//
module test;
@safe:
import std;
void main()
On Tuesday, 14 December 2021 at 14:40:00 UTC, RazvanN wrote:
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
Foo!int foo;
}
void main(){
}
```
error: Segmentation fault
On Tuesday, 14 December 2021 at 13:02:16 UTC, Tejas wrote:
On Tuesday, 14 December 2021 at 12:04:36 UTC, RazvanN wrote:
[...]
Then why did my modification work?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(scope Foo!(T)* rhs){ //replaced typeof(this) with
Foo!
templated it is impossible for the compiler to
issue this error before actually instantiating the constructor.
I see 2 possible fixes for this: (1) either we rename the copy
constructor symbol to __cpCtor so that it does not clash with
the normal constructor overload set or (2) when a templated
2 possible fixes for this: (1) either we rename the copy
constructor symbol to __cpCtor so that it does not clash with the
normal constructor overload set or (2) when a templated
constructor is instantiated, we can check whether it is an rvalue
constructor and issue an error if a copy
On Sunday, 12 December 2021 at 19:17:53 UTC, vit wrote:
On Sunday, 12 December 2021 at 18:32:28 UTC, Imperatorn wrote:
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
Foo!int foo;
}
void main(){
}
```
error: Segmentation fault
On Sunday, 12 December 2021 at 18:32:28 UTC, Imperatorn wrote:
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
Foo!int foo;
}
void main(){
}
```
error: Segmentation fault
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
Foo!int foo;
}
void main(){
}
```
error: Segmentation fault (core dumped)
= %s*(%s + %s) =", p1, p1, p2);
write(p1 * (p1 + p2)); // compare this to code without
operator overload:
}
```
Compare: ``p1 * (p1 + p2)`` to something with a structure like
``dot(p1,(add(p1,p2)).``
(With the Dlangs UFCS it might become: ``p1.dot(p1.add(p2))`` )
On Tuesday, 24 August 2021 at 05:34:08 UTC, Ali Çehreli wrote:
On 8/23/21 10:25 PM, james.p.leblanc wrote:
So, you need a "property". Easy... :)
1) Rename the member e.g. as a_.
2) Write setter and getter functions named 'a'.
struct Foo{
int a_;
int a() const {
return a_;
}
void
On 8/23/21 10:25 PM, james.p.leblanc wrote:
So, you need a "property". Easy... :)
1) Rename the member e.g. as a_.
2) Write setter and getter functions named 'a'.
struct Foo{
int a_;
int a() const {
return a_;
}
void a(int value) {
a_ = value;
}
}
void main(){
auto x = F
Greetings,
With a struct, there are many overload possibilities available.
However, I haven't been able to find how to overload assignment
of **selected fields** of a struct.
For example, suppose:
struct Foo{
int a;
int b;
...
}
void main(){
auto x
On Tuesday, 20 July 2021 at 18:32:26 UTC, Ali Çehreli wrote:
On 7/19/21 11:20 PM, Tejas wrote:
> trying to create the spaceship operator of C++
Just to make sure, D's opCmp returns an int. That new C++
operator was added to provide the same semantics.
Ali
I know. As I already mentioned, I
On 7/20/21 11:49 AM, H. S. Teoh wrote:
> On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via
Digitalmars-d-learn wrote:
>> On 7/19/21 11:20 PM, Tejas wrote:
>>
>>> trying to create the spaceship operator of C++
>>
>> Just to make sure, D's opCmp returns an int. That new C++ operator was
>
On Tuesday, 20 July 2021 at 18:49:07 UTC, H. S. Teoh wrote:
On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via
Digitalmars-d-learn wrote:
On 7/19/21 11:20 PM, Tejas wrote:
> trying to create the spaceship operator of C++
Just to make sure, D's opCmp returns an int. That new C++
operato
On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 7/19/21 11:20 PM, Tejas wrote:
>
> > trying to create the spaceship operator of C++
>
> Just to make sure, D's opCmp returns an int. That new C++ operator was
> added to provide the same semantics.
[...]
F
On 7/19/21 11:20 PM, Tejas wrote:
> trying to create the spaceship operator of C++
Just to make sure, D's opCmp returns an int. That new C++ operator was
added to provide the same semantics.
Ali
On Tuesday, 20 July 2021 at 06:34:45 UTC, vit wrote:
On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote:
...
Initially, I was trying to create the spaceship operator of
C++, but we aren't allowed to create new operators
...
D has spaceship operator: opCmp
(https://dlang.org/spec/operator
wanted to verify whether we can even overload an
operator globally, but even that seems to be failing, atleast
for me.
From the docs:
Operator overloading is accomplished by rewriting operators
whose operands are class or struct objects into calls to
specially named members.
https://dlan
On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote:
Why isn't it working by default?
Initially, I was trying to create the spaceship operator of
C++, but we aren't allowed to create new operators, it seems.
Then I just wanted to verify whether we can even overload an
operato
On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote:
...
Initially, I was trying to create the spaceship operator of
C++, but we aren't allowed to create new operators
...
D has spaceship operator: opCmp
(https://dlang.org/spec/operatoroverloading.html#compare).
quot;+"(1,5);
```
It works as expected.
Why isn't it working by default?
Initially, I was trying to create the spaceship operator of C++,
but we aren't allowed to create new operators, it seems. Then I
just wanted to verify whether we can even overload an operator
globally
On Saturday, 3 April 2021 at 13:46:17 UTC, kdevel wrote:
Why does this code
[...]
```d
ec.opAssign (bar (1)); // okay
// ec = bar (1); // Error: expression bar(1) is void and has
no value
```
[...]
compile with the abovementioned error?
This is a compiler bug. You're not allowed to hav
On Monday, 5 April 2021 at 20:59:34 UTC, tsbockman wrote:
However, `=` and `~=` should not treat `lazy void` parameters
differently. They should either both work, or neither. I
checked and this is actually a very old regression; both worked
way back in DMD 2.061. So, I've filed a front-end bug
On Monday, 5 April 2021 at 05:22:22 UTC, frame wrote:
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
Thus, the solution is to use an explicit `delegate` instead of
`lazy`:
Yes, I forgot to mention that.
Could you please explain why you set 'scope' here? Isn't it
wanted to keep
On Monday, 5 April 2021 at 15:05:24 UTC, kdevel wrote:
You changed the definition of ``bar`` while the exception
collector (``EC``) is meant to catch and collect an exception
thrown from the *unmodified* function.
My point was that the code will work if you do explicitly what
`lazy` does impl
On Monday, 5 April 2021 at 15:05:24 UTC, kdevel wrote:
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
```
[...]
[...]
[...]
[...]
```
[...]
Nice, is this documented somewhere? 🤔
Maybe we could add a better error message or smth.
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
```
[...]
You cannot assign void returned from bar() as parameter to
opAssign(). The lazy keyword creates some internal delegate,
thus opAssign() works instead.
[...]
auto bar (int i) {
return () {
if (i == 1)
th
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
Thus, the solution is to use an explicit `delegate` instead of
`lazy`:
Yes, I forgot to mention that.
Could you please explain why you set 'scope' here? Isn't it
wanted to keep references here?
On Sunday, 4 April 2021 at 16:38:10 UTC, frame wrote:
On Saturday, 3 April 2021 at 13:46:17 UTC, kdevel wrote:
Why does this code
ec.opAssign (bar (1)); // okay
// ec = bar (1); // Error: expression bar(1) is void and has
no value
compile with the abovementioned error?
You cannot a
On Saturday, 3 April 2021 at 13:46:17 UTC, kdevel wrote:
Why does this code
ec.opAssign (bar (1)); // okay
// ec = bar (1); // Error: expression bar(1) is void and has
no value
compile with the abovementioned error?
You cannot assign void returned from bar() as parameter to
opAssig
Why does this code
```d
import std.stdio,std.typecons;
struct EC {
Exception [] ex;
auto opAssign (X: void) (lazy X f)
{
writeln (__PRETTY_FUNCTION__);
try return f (); catch (Exception e) ex ~= e;
}
}
class E : Exception { this (string s) { super (s); } }
void bar (int
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
I'd like to make this work s += 10 where s is a struct. How can
I do that?
You have your answer, but someone else might come upon this in
the future, so here's a link to the clearest explanation of
operator overloading for someone new to
On Monday, 25 January 2021 at 21:53:15 UTC, Jack wrote:
That naming is confusing
op: it is an operator method
Op: it takes an operator as a parameter
Assign: kinda obvious.
As an example, there are opIndex, opIndexAssign and
opIndexOpAssign.
opIndex overloads obj[i].
opIndexAssign overloads
On Monday, 25 January 2021 at 17:12:47 UTC, Paul Backus wrote:
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
I'd like to make this work s += 10 where s is a struct. How
can I do that?
+=, -=, *=, and other compound assignment operators can be
overloaded by defining `opOpAssign`:
h
On Monday, 25 January 2021 at 17:11:41 UTC, Adam D. Ruppe wrote:
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
auto ref opAssign(string op, T)(T value)
try
opOpAssign instead
opAssign is for =
opOpAssign is for +=, -=, etc.
It might be some variation but I think it works if y
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
I'd like to make this work s += 10 where s is a struct. How can
I do that?
+=, -=, *=, and other compound assignment operators can be
overloaded by defining `opOpAssign`:
https://dlang.org/spec/operatoroverloading.html#op-assign
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
auto ref opAssign(string op, T)(T value)
try
opOpAssign instead
opAssign is for =
opOpAssign is for +=, -=, etc.
It might be some variation but I think it works if you just
rename it.
I'd like to make this work s += 10 where s is a struct. How can I
do that?
this isn't working:
auto ref opAssign(string op, T)(T value)
if(op == "+")
{
m += value;
return this;
}
the compiler didn't consider that overload and return:
d
On Monday, 7 December 2020 at 06:18:33 UTC, mw wrote:
Now, how to convert it to a native array:
double[] row = record;
Error: cannot implicitly convert expression record of type
Tuple!(double, double, double, ..., double) to double[]
(I know for tuple, we can do: double[] arr = [record];)
On Monday, 7 December 2020 at 04:38:07 UTC, Paul Backus wrote:
On Monday, 7 December 2020 at 04:03:05 UTC, mw wrote:
So my next question: given N, how do I create a Tuple!(double,
double, ... n-double) type programmatically?
import std.meta: Repeat;
alias NDoubles = Tuple!(Repeat!(N, double))
On Monday, 7 December 2020 at 04:03:05 UTC, mw wrote:
So my next question: given N, how do I create a Tuple!(double,
double, ... n-double) type programmatically?
import std.meta: Repeat;
alias NDoubles = Tuple!(Repeat!(N, double));
Note that N must be a compile-time constant, since the number
On Monday, 7 December 2020 at 03:51:02 UTC, Paul Backus wrote:
On Monday, 7 December 2020 at 02:25:23 UTC, mw wrote:
onlineapp.d(8): Error: no [] operator overload for type
CsvRecord!(int, cast(Malformed)1, string, dchar)
should `r`'s type be integer array? and how do I access each
ele
On Monday, 7 December 2020 at 02:25:23 UTC, mw wrote:
onlineapp.d(8): Error: no [] operator overload for type
CsvRecord!(int, cast(Malformed)1, string, dchar)
should `r`'s type be integer array? and how do I access each
elelment of the row?
Thanks.
The docs [1] say that csvReader re
auto records = text.csvReader!int;
foreach(r; records) {writeln(r[0]);} // line 8
assert(records.equal!equal([
[76, 26, 22],
]));
}
but I got a compile error:
onlineapp.d(8): Error: no [] operator overload for type
CsvRecord!(int, cast(Malformed)1, string, dchar)
should `r`
Now my slice works fine.
// Tipo Nulo.
class None {}
// Função slice()
auto slice(T1, T2, T3 = None)(T1 conteudo, T2 inicio, T3 fim =
T3.init) {
int start, end, startlen;
static if (is(T2 == int)) {inicio = inicio < 0 ? conteudo.length
+ inicio : inicio;}
static if (is(T3 == int))
On Sunday, 29 November 2020 at 02:55:02 UTC, Ali Çehreli wrote:
On 11/28/20 6:40 PM, Marcone wrote:
void a(T1, T2)(T1 b, T2 c){
// I need parameter "c" optional, but only (String or
int). How can I make it without overload function?
}
Since it's optional, T2 must have a
On 11/28/20 6:40 PM, Marcone wrote:
void a(T1, T2)(T1 b, T2 c){
// I need parameter "c" optional, but only (String or int). How can
I make it without overload function?
}
Since it's optional, T2 must have a default type. I made it 'int' below.
void a(T1, T2 =
void a(T1, T2)(T1 b, T2 c){
// I need parameter "c" optional, but only (String or int). How
can I make it without overload function?
}
On Monday, 9 November 2020 at 22:04:55 UTC, kdevel wrote:
It appears to me that the overload resolution may depend on the
/value/ of the function argument. According to [1] the type of
1 is int and that of 1L is long. Thus I would have expected
foo!int and foo!long being called in those cases
On Monday, 9 November 2020 at 22:04:55 UTC, kdevel wrote:
It appears to me that the overload resolution may depend on the
/value/ of the function argument. According to [1] the type of
1 is int and that of 1L is long.
That's not exactly true because of value range propagation. It is
wei
(id (1L));
foo (0x1_);
foo (0x1_L);
return 0;
}
~~~
Output:
$ ./id
short id.foo(short s)
short id.foo(short s)
int id.foo!int.foo(int s)
long id.foo!long.foo(long s)
int id.foo!int.foo(int s)
long id.foo!long.foo(long s)
It appears to me that the overload resolution may depend on
On Friday, 25 September 2020 at 18:58:54 UTC, H. S. Teoh wrote:
You probably need to use the long-form of templates, with
separate function declarations, to accomplish this. E.g.:
...
Alright, but your example still contains shouldReturnByRef which
presumably I need to implement myself. But
1 - 100 of 383 matches
Mail list logo