On Saturday, 16 July 2016 at 21:39:42 UTC, cym13 wrote:
A variable definition in a foreach
-> A variable definition *with auto* in a foreach
On Saturday, 16 July 2016 at 20:00:39 UTC, Seb wrote:
On Saturday, 16 July 2016 at 14:11:34 UTC, cym13 wrote:
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote:
foreach(auto v; msg)
writeln(v);
gives an error that a basic type is expected
foreach(v; msg)
writeln(v);
works
.. but why
On Saturday, 16 July 2016 at 20:00:39 UTC, Seb wrote:
On Saturday, 16 July 2016 at 14:11:34 UTC, cym13 wrote:
[...]
It's not arbitrary. It keeps the language simple and easy to
read. After all the entire auto keyword is just there, because
the compiler needs a keyword and in loops it's
On Saturday, 16 July 2016 at 14:11:34 UTC, cym13 wrote:
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote:
foreach(auto v; msg)
writeln(v);
gives an error that a basic type is expected
foreach(v; msg)
writeln(v);
works
.. but why?
Arbitrary limitation. If you want to say how
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote:
.. but why?
because. i've lost that fight too.
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote:
foreach(auto v; msg)
writeln(v);
gives an error that a basic type is expected
foreach(v; msg)
writeln(v);
works
.. but why?
Arbitrary limitation. If you want to say how surprising and
uselessly limiting it is wait at the end
On Saturday, 16 July 2016 at 14:00:56 UTC, dom wrote:
foreach(auto v; msg)
writeln(v);
gives an error that a basic type is expected
foreach(v; msg)
writeln(v);
works
.. but why?
`Note: The ForeachTypeAttribute is implicit, and when a type is
not specified, it is inferred
foreach(auto v; msg)
writeln(v);
gives an error that a basic type is expected
foreach(v; msg)
writeln(v);
works
.. but why?
On Sunday, 3 July 2016 at 22:00:39 UTC, MMJones wrote:
I like the term var better than auto. Is there a way to alias
auto?
If you're thinking of var as in JS's var, they're not the same
thing.
Even if you could alias it I would advise against doing something
like that; assume your code
On 07/04/2016 12:00 AM, MMJones wrote:
I like the term var better than auto. Is there a way to alias auto?
no
I like the term var better than auto. Is there a way to alias
auto?
On Thursday, May 05, 2016 19:09:01 Steven Schveighoffer via Digitalmars-d-
learn wrote:
> On 5/5/16 6:50 PM, Erik Smith wrote:
> > Alias works at the cost of adding a 2nd type name:
> >
> > alias Res = Resource!();
> > auto res = Res.create
> >
> > The oth
On 5/5/16 6:50 PM, Erik Smith wrote:
Alias works at the cost of adding a 2nd type name:
alias Res = Resource!();
auto res = Res.create
The other problem is that the alias definition by itself instantiates,
which I can't afford.
I have createResource() now, it just doesn't fit well
On Thursday, 5 May 2016 at 16:12:40 UTC, Steven Schveighoffer
wrote:
On 5/5/16 12:10 AM, Erik Smith wrote:
I want to have a struct template auto instantiate when the
template
parameters are defaulted or missing. Example:
struct Resource(T=int) {
static auto create() {return Resource
On 5/5/16 12:10 AM, Erik Smith wrote:
I want to have a struct template auto instantiate when the template
parameters are defaulted or missing. Example:
struct Resource(T=int) {
static auto create() {return Resource(null);}
this(string s) {}
}
auto resource = Resource.create
On Wednesday, 4 May 2016 at 22:10:16 UTC, Erik Smith wrote:
Any ideas?
Using an alias could be a solution.
I want to have a struct template auto instantiate when the
template parameters are defaulted or missing. Example:
struct Resource(T=int) {
static auto create() {return Resource(null);}
this(string s) {}
}
auto resource = Resource.create;
As a plain struct it works
On 02/03/16 3:50 PM, Hanh wrote:
Hi,
Is there a way to declare a class field 'auto'? I have a problem when I
try to 'promote' a variable to a field.
import std.csv;
import std.typecons;
class Test {
this() {
auto text = "Joe,Carpenter,30\nFred,Blacksmith,4
Hi,
Is there a way to declare a class field 'auto'? I have a problem
when I try to 'promote' a variable to a field.
import std.csv;
import std.typecons;
class Test {
this() {
auto text = "Joe,Carpenter,30\nFred,Blacksmith,40\r\n";
a
On Saturday, 9 January 2016 at 15:50:33 UTC, Jay Norwood wrote:
I'm reading Jack Stouffer's documentation:
http://jackstouffer.com/blog/nd_slice.html
considering the UFCS example below and how it would impact
auto-completion support.
auto slice = sliced(iota(1000), 5, 5, 40);
auto slice
if auto-completion provided correct
possible parameter type lists for the last three, but obviously
the first two would provide no help, and I'd be pleasantly
surprised if the third form provided the parameter type list
without the first parameter.
anyway ... I'll just try some simple cases
I'm reading Jack Stouffer's documentation:
http://jackstouffer.com/blog/nd_slice.html
considering the UFCS example below and how it would impact
auto-completion support.
auto slice = sliced(iota(1000), 5, 5, 40);
auto slice = 1000.iota.sliced(5, 5, 40);
Seems like auto-complete support
On Sunday, 27 December 2015 at 07:40:55 UTC, Ali Çehreli wrote:
It looks like you need map(), not each():
import std.algorithm;
import std.typecons;
import std.array;
void main() {
auto a = [ 1, 2 ];
auto arr = a.map!(e => tuple(2 * e, e * e)).array;
static assert(is(typeof(
On 12/27/2015 08:42 AM, Jay Norwood wrote:
> However, I was trying to use each!, with the intention of then moving to
> parallel processing by samples blocks. My guess is this would be more
> efficient than using parallel map or amap, which would parallel process
> by function application, if I
On 12/26/2015 09:45 PM, Jay Norwood wrote:
> This is getting kind of a long example,
There are issues with that code that make it hard for me to guess the
intent.
> a way to have the Tuple array defined as auto instead of having to
specify
> the types. I tried using .array() a
This is getting kind of a long example, but I'm really only
interested in the last 4 or 5 lines. This works as desired,
creating the array of tuples, but I'm wondering if there is a way
to have the Tuple array defined as auto instead of having to
specify the types. I tried using .array
e some other way to get a valid fully specified type for
these sliced auto variables?
import std.stdio;
import std.experimental.ndslice;
void main() {
import std.algorithm.iteration: map;
import std.array: array;
import std.range;
import std.traits;
auto t0 = 1000.iota.slice
So, the extra confusion of the typeof(iota) Result return goes
away when slicing arrays.
auto a1 = new int[100];
auto t3 = a1.sliced(3,4,5);
pragma(msg,typeof(t3)); //This prints Slice!(3u, int*)
Slice!(3u, int*) t4 = a1.sliced(3,4,5); // and this works ok
on win32, "dip80-ndslice": "~>0.8.4"
Is there some other way to get a valid fully specified type for
these sliced auto variables?
import std.stdio;
import std.experimental.ndslice;
void main() {
import std.algorithm.iteration: map;
import std.array: array;
impor
21.12.2015 07:23, Jay Norwood пишет:
import std.stdio;
import std.experimental.ndslice;
void main() {
import std.algorithm.iteration: map;
import std.array: array;
import std.range;
import std.traits;
auto t0 = 1000.iota.sliced(3, 4, 5);
pragma(msg, typeof(t0
import std.stdio;
import std.experimental.ndslice;
void main() {
import std.algorithm.iteration: map;
import std.array: array;
import std.range;
import std.traits;
auto t0 = 1000.iota.sliced(3, 4, 5);
pragma(msg, typeof(t0));
Slice!(3u, Result) t1 = 1000
, well this worked, so it seems to be something lacking in the
description of iota's type rather than an issue with ndslice.
alias RESULT = typeof(1000.iota);
Slice!(3u, RESULT) t1 = 1000.iota.sliced(3, 4, 5);
auto t2 = 1000.iota();
pragma(msg, typeof(t2));
This just prints Result
On Friday, 20 November 2015 at 20:39:58 UTC, Ilya wrote:
Can DMD frontend optimize
string concatenation
```
enum Double(S) = S ~ S;
assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__);
```
to
```
assert(condition, "Text ++_function_name_");
```
?
At least for string (and array?)
On Friday, 20 November 2015 at 20:39:58 UTC, Ilya wrote:
Can DMD frontend optimize
string concatenation
```
enum Double(S) = S ~ S;
assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__);
```
to
```
assert(condition, "Text ++_function_name_");
```
?
If you really want to make sure it is
Can DMD frontend optimize
string concatenation
```
enum Double(S) = S ~ S;
assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__);
```
to
```
assert(condition, "Text ++_function_name_");
```
?
On Fri, 20 Nov 2015 20:39:57 +, Ilya wrote:
> Can DMD frontend optimize
> string concatenation
> ```
> enum Double(S) = S ~ S;
>
> assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__);
> ```
>
> to
>
> ```
> assert(condition, "Text ++_function_name_");
>
> ```
> ?
Yes this occurs as
On Monday, 22 June 2015 at 13:49:21 UTC, Steven Schveighoffer
wrote:
On 6/20/15 10:26 PM, Yuxuan Shui wrote:
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote:
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
auto ref R) is indeed a template function, so I don't
On 6/22/15 1:37 PM, Yuxuan Shui wrote:
On Monday, 22 June 2015 at 13:49:21 UTC, Steven Schveighoffer wrote:
On 6/20/15 10:26 PM, Yuxuan Shui wrote:
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote:
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
auto ref R
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
Try to compile this code snippet:
import std.traits;
template a(R) {
auto a(S)(auto ref R i) {
return cast(S)i*2;
}
}
template ReturnTypeEx(alias A, B) {
alias ReturnTypeEx = ReturnType!(A!B
On Sunday, 21 June 2015 at 02:37:59 UTC, Yuxuan Shui wrote:
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote:
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
auto ref R) is indeed a template function, so I don't
understand.
But R is not a parameter on the function
On 6/20/15 10:26 PM, Yuxuan Shui wrote:
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote:
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
auto ref R) is indeed a template function, so I don't understand.
But R is not a parameter on the function itself. It comes from
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
auto ref R) is indeed a template function, so I don't
understand.
But R is not a parameter on the function itself. It comes from
the outside template.
Move it to the inside template, rewrite it as:
auto a(S, R)(auto ref
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote:
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
auto ref R) is indeed a template function, so I don't
understand.
But R is not a parameter on the function itself. It comes from
the outside template.
Move
On Sunday, 21 June 2015 at 01:26:51 UTC, Adam D. Ruppe wrote:
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
auto ref R) is indeed a template function, so I don't
understand.
But R is not a parameter on the function itself. It comes from
the outside template.
Move
Try to compile this code snippet:
import std.traits;
template a(R) {
auto a(S)(auto ref R i) {
return cast(S)i*2;
}
}
template ReturnTypeEx(alias A, B) {
alias ReturnTypeEx = ReturnType!(A!B);
}
template b(alias R) {
int b(S)(S i
On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
Try to compile this code snippet:
import std.traits;
template a(R) {
auto a(S)(auto ref R i) {
return cast(S)i*2;
}
}
template ReturnTypeEx(alias A, B) {
alias ReturnTypeEx = ReturnType!(A!B
On 04/15/2015 10:50 AM, Ali Çehreli wrote:
pragma(msg) has been added to Programming in D but it is not available
online yet:
Sorry for the spam :( but apparently it is already online:
http://ddili.org/ders/d.en/templates.html#ix_templates.pragma
Ali
On 04/13/2015 07:44 AM, matovitch wrote:
Thanks for the tip ! I was looking at something like this.
pragma(msg) has been added to Programming in D but it is not available
online yet:
Thanks for the tip ! I was looking at something like this.
On 4/11/15 6:08 AM, matovitch wrote:
Hi,
I just learn about auto ref functions and tried this :
import std.stdio;
auto ref foo(int i, ref float f)
{
if (i f)
{
return i;
}
else
{
return f;
}
}
void main
Hi,
I just learn about auto ref functions and tried this :
import std.stdio;
auto ref foo(int i, ref float f)
{
if (i f)
{
return i;
}
else
{
return f;
}
}
void main()
{
int i = 1;
float f1
In fact I am now thinking it's great...I tried with string
instead of float and got a clear error message. I should have
read the spec more thoroughly.
(you can remove the ref stuff)
Ok this explain it :
http://dlang.org/function.html#auto-functions. It should return a
float.
On 2015-03-19 13:22:44 +, Benjamin Thaut said:
Generally don't expect to many things to work with DLLs at the moment.
Hi, well, I think what's available is good enough to get most things done.
Generally speaking only exporting global functions works. Don't try to
export classes /
On Thursday, 19 March 2015 at 12:58:42 UTC, Robert M. Münch wrote:
On 2015-03-18 21:50:39 +, Adam D. Ruppe said:
It will not work because a function with an auto return value
is actually a template, and unused templates won't be put into
a dll.
Ok, that makes it clear. Thanks
On 2015-03-18 21:50:39 +, Adam D. Ruppe said:
It will not work because a function with an auto return value is
actually a template, and unused templates won't be put into a dll.
Ok, that makes it clear. Thanks.
--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster
Windows, 32-Bit, DLL:
export extern(C) struct1 struct1(){
struct1 x;
return(x);
}
export extern(C) auto struct2(){
struct1 x;
return(x);
}
struct1 is visible in the DLL, struct2 is not visible in the DLL.
--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster
On Wednesday, 18 March 2015 at 15:50:16 UTC, Robert M. Münch
wrote:
struct1 is visible in the DLL, struct2 is not visible in the
DLL.
It will not work because a function with an auto return value is
actually a template, and unused templates won't be put into a dll.
On Wednesday, 18 March 2015 at 03:54:01 UTC, Dennis Ritchie wrote:
Hi.
To create int-double array I have to pre-initialize the auto
array:
There's no such thing as an int double array, what you made there
is just a double[]. The ints are converted to double when added
to that array.
So
Hi.
To create int-double array I have to pre-initialize the auto
array:
import std.stdio;
import std.algorithm;
void main() {
auto s = [5.31, 6];
s = s.remove(0, 1);
double k;
readf(%s, k); // 17.32
s ~= k, s ~= 5, s ~= 1.125;
writeln(s
On Wednesday, 18 March 2015 at 04:00:04 UTC, Adam D. Ruppe wrote:
So you can just do
double[] s;
Thanks.
Yes, I overthink everything :)
On Thu, 12 Mar 2015 04:51:40 +, amber wrote:
On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote:
On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote:
...
http://dlang.org/function.html#function-attribute-inference might be a
good read if you haven't read it already.
I did
On Thursday, 12 March 2015 at 05:01:50 UTC, amber wrote:
On Thursday, 12 March 2015 at 04:51:42 UTC, amber wrote:
On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote:
On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote:
...
On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote:
...
http://dlang.org/function.html#function-attribute-inference might
be a good read if you haven't read it already.
On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote:
On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote:
...
http://dlang.org/function.html#function-attribute-inference
might be a good read if you haven't read it already.
I did read it but didn't really understand it, so I've
On Thursday, 12 March 2015 at 04:51:42 UTC, amber wrote:
On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote:
On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote:
...
http://dlang.org/function.html#function-attribute-inference
might be a good read if you haven't read it already.
and
for others they're not.
I'd rather not duplicate each function body just to get
attributes working.
Hmm, just had a thought, would this work??
---
struct S(T) {
T[] values;
private void someFuncImpl()(int i) {
// the impl goes here with auto-deduced attributes
On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote:
Hi,
I just wonder why with (auto p = new ...) is not working.
It would be some syntax sugar in this scenario:
with (auto p = new Panel())
{
parent = this;
text = bla
On Friday, 26 September 2014 at 19:59:56 UTC, Freddy wrote:
On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote:
Hi,
I just wonder why with (auto p = new ...) is not working.
It would be some syntax sugar in this scenario:
with (auto p = new Panel
aOn Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote:
Hi,
I just wonder why with (auto p = new ...) is not working.
It would be some syntax sugar in this scenario:
with (auto p = new Panel())
{
parent = this;
text = bla
Enhancement 13526 filed:
https://issues.dlang.org/show_bug.cgi?id=13526
On Wed, 24 Sep 2014 14:39:25 +
Andre via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:
Enhancement 13526 filed:
https://issues.dlang.org/show_bug.cgi?id=13526
i wrote a quickhack-patch for this ER. as it's my first patch that
goes outside parser it needs to be reviewed by
Hi,
I just wonder why with (auto p = new ...) is not working.
It would be some syntax sugar in this scenario:
with (auto p = new Panel())
{
parent = this;
text = bla;
with (auto b = new Button
On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote:
I just wonder why with (auto p = new ...) is not working.
It would be some syntax sugar in this scenario:
I presume with is limited to expressions and not statements as
the messages says.
However, you can use
if (auto p
How about:
auto b - new Button(); with (b) {
On Tuesday, 23 September 2014 at 15:19:59 UTC, Andre wrote:
Hi,
I just wonder why with (auto p = new ...) is not working.
It would be some syntax sugar in this scenario:
with (auto p = new Panel())
{
parent
Sorry, I sent that last message before I intended to.
How about:
auto b = new Button(); with (b) {
...
}
'b' is explicitly outside of the scope of the 'with' block, which
may not be what you intended. But you could use more braces to
add an extra level of scope if that's
Yes, that is also working. As far as I remember (only my tablet
currently available) also this works:
Panel p;
with(p = new Panel ()) {}
Therefore it seems strange,the same does not work with auto.
Kind regards
André
On Tuesday, 23 September 2014 at 19:49:22 UTC, Graham Fawcett
wrote
I think this is just a language oversight. It's allowed in if
statements, and people have made a good case for allowing it for
switch statements. It just hasn't been implemented. I made an
attempt one evening to implement it for switch statements, but
I'm not at all familiar with DMD, so I
On Tuesday, 23 September 2014 at 20:16:29 UTC, andre wrote:
Therefore it seems strange,the same does not work with auto.
Yes, it seem logical to me allow this also in with and switch.
class A
{
string getName(this Klass)()
{
return Klass.stringof;
}
}
class B : A
{}
void main()
{
import std.stdio;
auto a = new A;
auto b = new B;
writeln(a.getName());
writeln(b.getName
inherit from base class Component, I need to auto-create
child own static fields with child type.
It should look like this, after compilation:
class Component
{
//it doesn't matter to have any fields here
//but it's important to be able to create an instance of
Component
//and when
(foo.getName() == B);
...
Hi! I'm stuck at one issue, and I don't know how to solve it. I
think this is about mixins/templates, isn't it?
When inherit from base class Component, I need to auto-create
child own static fields with child type.
It should look like this, after compilation:
class
On Thursday, 21 August 2014 at 12:58:13 UTC, MarisaLovesUsAll
wrote:
I found a rough solution. It's not ideal and I still want to
make autoinject, but it works.
mixin template Manager(T) {};
class Component {};
class Sprite:Component
{
mixin Manager!Sprite;
};
1) How to make mixin inject
(this)` in Manager:
mixin template Manager()
{
void someMethod(typeof(this) otherInstance) {}
}
Thanks, it works.
...I also have more questions %)
When I make mixin injection in one class, I want auto-injection
in another class. How can I do this?
class Component:GameObject
{
//second
this is about mixins/templates, isn't it?
When inherit from base class Component, I need to auto-create child own
static fields with child type.
It should look like this, after compilation:
class Component
{
//it doesn't matter to have any fields here
//but it's important to be able to create
On Thursday, 21 August 2014 at 19:58:18 UTC, MarisaLovesUsAll
wrote:
When I make mixin injection in one class, I want auto-injection
in another class. How can I do this?
class Component:GameObject
{
//second injection must be here and must be automatic
};
class Sprite:Component
On Thursday, 21 August 2014 at 20:05:13 UTC, Ary Borenszweig
wrote:
I'll tell you how it's done in Crystal in case someone wants to
come up with a proposal to make it work in D.
~~~
class Foo
macro inherited
def method_in_{{@class_name.downcase.id}}
puts Hello {{@class_name.id}}!
On Thursday, 21 August 2014 at 20:16:33 UTC, anonymous wrote:
Maybe you can explain what you're trying to achieve with all
this. There may be a different/better way to do it.
Sure.
Class tree: GameObject-Component-Sprite.
GameObject structure:
Component[];
Component
On Wed, 20 Aug 2014 01:38:52 +
uri via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:
Hi all,
Bit new to D so this might be a very naive question...
Can the compiler auto infer function attributes?
I am often adding as many attributes as possible and use the
compiler
On Wednesday, 20 August 2014 at 09:13:15 UTC, Jonathan M Davis
via Digitalmars-d-learn wrote:
On Wed, 20 Aug 2014 01:38:52 +
uri via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:
Hi all,
Bit new to D so this might be a very naive question...
Can the compiler auto infer
Hi all,
Bit new to D so this might be a very naive question...
Can the compiler auto infer function attributes?
I am often adding as many attributes as possible and use the
compiler to show me where they're not applicable and take them
away. It would be great if this could be achieved like
On Wednesday, 20 August 2014 at 01:38:53 UTC, uri wrote:
Hi all,
Bit new to D so this might be a very naive question...
Can the compiler auto infer function attributes?
I am often adding as many attributes as possible and use the
compiler to show me where they're not applicable and take them
This doesn't work:
bool less_than (T)(auto ref T a, auto ref T b)
{
return a b;
}
Error: auto can only be used for template function parameters
What am I doing wrong? Is this not a template function?
On Sunday, 3 August 2014 at 19:07:32 UTC, Vlad Levenfeld wrote:
This doesn't work:
bool less_than (T)(auto ref T a, auto ref T b)
{
return a b;
}
Error: auto can only be used for template function parameters
What am I doing wrong? Is this not a template function?
I think you can
This would make the function always take its argument by
reference. I'm trying to use the feature here:
http://dlang.org/template.html
from the section Function Templates with Auto Ref Parameters
On Sunday, 3 August 2014 at 19:07:32 UTC, Vlad Levenfeld wrote:
bool less_than (T)(auto ref T a, auto ref T b)
{
return a b;
}
Error: auto can only be used for template function parameters
Works for me with dmd versions back to 2.060. What compiler are
you using?
On Sunday, 3 August 2014 at 19:26:28 UTC, anonymous wrote:
Works for me with dmd versions back to 2.060. What compiler are
you using?
dmd 2.065
less_than.d
bool less_than (T)(auto ref T a, auto ref T b)
{
return a b;
}
void main()
{
int a = 1, b = 2;
assert(less_than(a, b));
assert(less_than(a, 2));
assert(less_than(1, b));
assert(less_than(1, 2));
}
$ dmd less_than.d echo ok
ok
On Sunday, 3 August 2014 at 19:25:32 UTC, Vlad Levenfeld wrote:
This would make the function always take its argument by
reference. I'm trying to use the feature here:
http://dlang.org/template.html
from the section Function Templates with Auto Ref Parameters
I thought I finally saw
301 - 400 of 695 matches
Mail list logo