On 09/06/2019 01:46 PM, Bob4 wrote:
> Thanks; this works, but I'm not sure why. Where does `T` come from?
Well... I assumed this would make you research templates. ;) Here is one
resource: http://ddili.org/ders/d.en/templates.html
(T) means "this function is for any type; and I call that
On Friday, 6 September 2019 at 20:16:58 UTC, Ali Çehreli wrote:
On 09/06/2019 01:02 PM, Bob4 wrote:
> I feel like it's wrong to rewrite identical functions over
and over.
Enter templates. :)
auto clamp(T)(T value, T mini, T maxi) {
if (value >= maxi) {
return maxi;
}
if (value <=
On 09/06/2019 01:02 PM, Bob4 wrote:
> I feel like it's wrong to rewrite identical functions over and over.
Enter templates. :)
auto clamp(T)(T value, T mini, T maxi) {
if (value >= maxi) {
return maxi;
}
if (value <= mini) {
return mini;
}
return value;
}
unittest {
Hi,
I'm coming from a background in Python, without a lot of
experience in statically typed languages, and I'm struggling to
see how to make a certain function in D.
This is what I have in Python:
```
from typing import Union
Number = Union[int, float]
def clamp(value: Number, mini:
On Friday, 6 September 2019 at 18:39:47 UTC, Andrew Edwards wrote:
also probably u can do https://run.dlang.io/is/WMQE93
Ended up using this since it provides for named access and
solves the overloading requirement.
Thanks,
Andrew
You can also use std.typecons.Tuple for this, since it
On Friday, 6 September 2019 at 17:54:51 UTC, Adam D. Ruppe wrote:
On Friday, 6 September 2019 at 17:42:08 UTC, Max Samukha wrote:
That file was silently imported by the compiler (probably, a
bug).
That's by design - the automatic module import lookups actually
always look for .di file first,
On Friday, 6 September 2019 at 11:35:59 UTC, a11e99z wrote:
https://dlang.org/spec/simd.html
This didn't work two well because I wont be able to access the
members by name as C++ library expects. Will consider during
refactoring.
also probably u can do https://run.dlang.io/is/WMQE93
On 09/06/2019 02:14 AM, Andrew Edwards wrote:
> I'm seeking some pointers on how to define these in D
Here is my attempt:
struct Demo {
// NOTE: The types and number of elements can be templatized and
mixed-in like
// mixin (makeMembers!T(N));
float a = 0;
float b = 0;
float c =
On Friday, 6 September 2019 at 17:42:08 UTC, Max Samukha wrote:
That file was silently imported by the compiler (probably, a
bug).
That's by design - the automatic module import lookups actually
always look for .di file first, then .d files.
On Friday, 6 September 2019 at 16:55:31 UTC, Max Samukha wrote:
On Friday, 6 September 2019 at 15:52:46 UTC, Stefan Koch wrote:
If that is happening you hit a bug.
It seems unlikely though.
Could you elaborate a bit? How should extern(C/C++) definitions
be mangled - fully qualified or not,
On Friday, 6 September 2019 at 15:52:46 UTC, Stefan Koch wrote:
On Friday, 6 September 2019 at 15:09:22 UTC, Max Samukha wrote:
Consider the following two modules:
1. test.d:
module test;
import lib.a;
void main() {
foo();
}
2. lib/a.d:
module lib.a;
extern(C) void foo() {}
When
On Friday, 6 September 2019 at 10:52:43 UTC, aliak wrote:
On Friday, 6 September 2019 at 10:37:16 UTC, aliak wrote:
Are there any library APIs that allow this:
I just put this together. Any holes other the AA related ones?
string a = "hello";
string b = a.dupDeep;
// Error: cannot
On Friday, 6 September 2019 at 09:28:57 UTC, Andrew Edwards wrote:
This is my thought on how to accomplish op overloading:
struct Test
{
float a, b, c, d;
float opIndex(size_t i)
in(i >= 0 && i <= 3)
{
final switch(i)
{
case 0: return a;
On Friday, 6 September 2019 at 15:32:07 UTC, 0xEAB wrote:
On Friday, 6 September 2019 at 15:09:22 UTC, Max Samukha wrote:
Consider the following two modules:
What compiler version are you using?
DMD64 D Compiler v2.088.0-1-g4011382ea, linux
On Friday, 6 September 2019 at 15:09:22 UTC, Max Samukha wrote:
Consider the following two modules:
1. test.d:
module test;
import lib.a;
void main() {
foo();
}
2. lib/a.d:
module lib.a;
extern(C) void foo() {}
When compiled separately (dmd -c lib/a.d; dmd test.d a.o), the
On Friday, 6 September 2019 at 15:09:22 UTC, Max Samukha wrote:
Consider the following two modules:
What compiler version are you using?
Consider the following two modules:
1. test.d:
module test;
import lib.a;
void main() {
foo();
}
2. lib/a.d:
module lib.a;
extern(C) void foo() {}
When compiled separately (dmd -c lib/a.d; dmd test.d a.o), the
function in 'a.o' is mangled as 'foo', but the reference in
'test.o' is
module lib.a;
class C {
this() {
}
void foo() {
}
~this() {
}
}
dmd -H -o- a.d:
// D import file generated from 'a.d'
module lib.a;
class C
{
this()
{
}
void foo();
~this();
}
The destructor and
On Friday, 6 September 2019 at 09:14:31 UTC, Andrew Edwards wrote:
C++ allows the for following:
struct Demo
{
float a, b, c, d;
Demo() { a = b = c = d = 0.0f; }
Demo(float _a, float _b, float _c, float _d) {
a = _a;
b = _b;
On Friday, 6 September 2019 at 10:37:16 UTC, aliak wrote:
Are there any library APIs that allow this:
I just put this together. Any holes other the AA related ones?
Will it work with classes?
auto dupDeep(T)(ref T thing) {
import std.range: ElementType;
import std.traits:
Are there any library APIs that allow this:
struct S {
int[] arr;
}
void main() {
const a = S([1,2,3]);
S b = a.copy; // deep dup/copy
}
I'd also like to avoid implementing a copy constructor for each
type.
On Friday, 6 September 2019 at 09:49:33 UTC, Johan Engelen wrote:
On Friday, 6 September 2019 at 09:14:31 UTC, Andrew Edwards
wrote:
C++ allows the for following:
struct Demo
{
float a, b, c, d;
Demo() { a = b = c = d = 0.0f; }
Demo(float _a, float _b, float _c, float
On Friday, 6 September 2019 at 09:14:31 UTC, Andrew Edwards wrote:
C++ allows the for following:
struct Demo
{
float a, b, c, d;
Demo() { a = b = c = d = 0.0f; }
Demo(float _a, float _b, float _c, float _d) {
a = _a;
b = _b;
On Friday, 6 September 2019 at 09:14:31 UTC, Andrew Edwards wrote:
C++ allows the for following:
struct Demo
{
float a, b, c, d;
Demo() { a = b = c = d = 0.0f; }
Demo(float _a, float _b, float _c, float _d) {
a = _a;
b = _b;
On Friday, 6 September 2019 at 08:47:07 UTC, Kagamin wrote:
Physical objects work like reference types. A place on
bookshelf is at one coordinate and a book is at another
coordinate, you don't copy the book, you fill a place on
bookshelf with a reference to the book.
So it's more like a
On Thursday, 5 September 2019 at 21:22:12 UTC, Ali Çehreli wrote:
If it makes for the type to have immutable (or const) members,
then fine; with the understanding that objects of that type
cannot be assigned or mutated any other way, we can define them
like that. What I meant is, because we
C++ allows the for following:
struct Demo
{
float a, b, c, d;
Demo() { a = b = c = d = 0.0f; }
Demo(float _a, float _b, float _c, float _d) {
a = _a;
b = _b;
c = _c;
d = _d;
}
float
On Thursday, 5 September 2019 at 20:10:03 UTC, ag0aep6g wrote:
You're not putting an immutable int into an AA. You're copying
the value of an immutable int to a mutable one.
but I can't do that with a struct, having an immutable member.
When I remove that immutable inside of the struct it
On Thursday, 5 September 2019 at 12:46:06 UTC, berni wrote:
OK. This are two solutions and although I'll probably not going
to use any of those (due to other reasons), I still don't
understand, why the original approach does not work. If I've
got a book an put it in a box and later I'll get it
On Thursday, 5 September 2019 at 18:26:41 UTC, DanielG wrote:
And depending on the version of macOS / which framework you're
linking to, you might need to specify a search path as well
(-F):
lflags "-framework" "SomeFramework" "-framework"
"AnotherFramework" "-F/Library/Frameworks"
IIRC I
On Thursday, 5 September 2019 at 12:30:33 UTC, Jacob Carlborg
wrote:
On 2019-09-04 17:12, Andrew Edwards wrote:
Worked like a charm:
-L/System/Library/Frameworks/Cocoa.framework/Cocoa
This probably not a good idea. It relies on how a framework is
structured internally. Adam's solution is
Today we dig back into the MVC series to look at the multi-level
TreeStore and maybe learn a little geography. You can read all
about it right here:
https://gtkdcoding.com/2019/09/06/0068-multi-level-treestore.html
module lib.a;
class C {
this() {
}
void foo() {
}
~this() {
}
}
dmd -H -o- a.d:
// D import file generated from 'a.d'
module lib.a;
class C
{
this()
{
}
void foo();
~this();
}
The destructor and
On Thursday, September 5, 2019 11:59:30 PM MDT Jamie via Digitalmars-d-learn
wrote:
> On Friday, 6 September 2019 at 00:41:12 UTC, Jonathan M Davis
>
> wrote:
> > On Thursday, September 5, 2019 6:24:07 PM MDT Jamie via
> >
> > Digitalmars-d-learn wrote:
> >>
On Friday, 6 September 2019 at 05:59:30 UTC, Jamie wrote:
time and fmod is called so it breaks. In case 3, with default
struct arguments, I thought that the constructor I have defined
was being called, however the default constructor was being
called (this()) so fmod wasn't being called.
On Friday, 6 September 2019 at 00:41:12 UTC, Jonathan M Davis
wrote:
On Thursday, September 5, 2019 6:24:07 PM MDT Jamie via
Digitalmars-d-learn wrote:
/home/jamie/.dvm/compilers/dmd-2.077.0/linux/bin/../../src/phobos/std/math
.d(3702): Error: fmodl cannot be interpreted at compile time,
36 matches
Mail list logo