On Tuesday, 7 February 2023 at 09:49:46 UTC, Salih Dincer wrote:
Is it a feature or a bug that the code below can be compiled
without arguments?
You should use `@disable this()` recommended in the relevant
article:
https://dlang.org/spec/struct.html#disable_default_construction
```d
void ma
Hi All...
Is it a feature or a bug that the code below can be compiled
without arguments?
```d
import std.stdio, std.conv : to;
void main()
{
auto noArgument = Sarr!char(); // it works no argument...
assert(noArgument.length == 8);
string dlang = "D-lang";
const len = dlang.le
On Monday, 14 September 2020 at 18:58:44 UTC, 60rntogo wrote:
On Monday, 14 September 2020 at 17:11:59 UTC, k2aj wrote:
AFAIK the only way to have default ref arguments is to use a
global variable:
---
extern(C++) struct Foo
{
int x;
}
immutable foo1 = Foo(1);
extern(C++) void fun(const ref F
On Monday, 14 September 2020 at 17:11:59 UTC, k2aj wrote:
AFAIK the only way to have default ref arguments is to use a
global variable:
---
extern(C++) struct Foo
{
int x;
}
immutable foo1 = Foo(1);
extern(C++) void fun(const ref Foo foo = foo1);
---
Thanks. This appears to work, but feels l
On Monday, 14 September 2020 at 12:44:34 UTC, 60rntogo wrote:
I'm trying to use a C++ library that has a function declared
like this:
---
struct Foo
{
int x;
};
void fun(const Foo& foo = Foo(1));
---
I have translated this to a D declaration:
---
struct Foo
{
int x;
}
extern(C++) void f
On Monday, 14 September 2020 at 12:44:34 UTC, 60rntogo wrote:
---
struct Foo
{
int x;
}
extern(C++) void fun(const ref Foo foo = Foo(1));
---
I suppose this should have been:
---
extern(C++):
struct Foo
{
int x;
}
void fun(const ref Foo foo = Foo(1));
---
Not that it changes the questi
I'm trying to use a C++ library that has a function declared like
this:
---
struct Foo
{
int x;
};
void fun(const Foo& foo = Foo(1));
---
I have translated this to a D declaration:
---
struct Foo
{
int x;
}
extern(C++) void fun(const ref Foo foo = Foo(1));
---
This yields an error: "Foo
On Wednesday 07 October 2015 02:22, Steven Schveighoffer wrote:
> On 10/6/15 4:27 PM, anonymous wrote:
[...]
>> void foo(T...)(string str=null, T args = T.init) {
[...]
> I find it quite fascinating that in anonymous' solution, the T.init
> doesn't ever actually get used!
It's not used with IFTI
On 10/6/15 4:27 PM, anonymous wrote:
You can put an expression tuple ("expression AliasSeq"??) there. T.init is
one that always fits T's types. But you could generate one with different
values, too.
void foo(T...)(string str=null, T args = T.init) {
//...
}
void main()
{
fo
On Tuesday 06 October 2015 22:01, Nick Sabalausky wrote:
> Ok, D-style varargs can accept a parameter length of zero:
>
> ---
> void foo(T...)(T args) {
> //...
> }
> foo();
> foo(t1, t2);
> ---
Terminology fun:
The spec uses the term "D-style variadic function" for
Ok, D-style varargs can accept a parameter length of zero:
---
void foo(T...)(T args) {
//...
}
foo();
foo(t1, t2);
---
Is there any way to stick a param with a default value before that?
---
void foo(T...)(string str=null, T args=/+what goes here???+/) {
On Tuesday, 10 March 2015 at 22:00:29 UTC, safety0ff wrote:
On Tuesday, 10 March 2015 at 21:56:39 UTC, Xinok wrote:
I'm inclined to believe this is a bug.
https://issues.dlang.org/show_bug.cgi?id=11048
Thanks for the link, and I didn't mean to post this in D.learn.
>.<
On Tuesday, 10 March 2015 at 21:56:39 UTC, Xinok wrote:
I'm inclined to believe this is a bug.
https://issues.dlang.org/show_bug.cgi?id=11048
The following code fails to compile because unpredictableSeed is
impure:
void main()
{
foreach(i; 0..10) writeln(pureRandom);
}
pure uint pureRandom()
{
auto r = Random(unpredictableSeed);
return r.front;
}
However, make unpredictableSeed a defau
On Sunday, 4 January 2015 at 00:22:01 UTC, ixid wrote:
Why don't templates take a type from the default argument if
nothing else is supplied?
https://issues.dlang.org/show_bug.cgi?id=2803
On Sunday, 4 January 2015 at 00:22:01 UTC, ixid wrote:
Why don't templates take a type from the default argument if
nothing else is supplied? It would be useful to be able to use
an enum to set a default.
I doubt anyone's ever thought of that particular use-case. Using
your typeof(MAX) workar
Why don't templates take a type from the default argument if
nothing else is supplied? It would be useful to be able to use an
enum to set a default.
enum MAX = 1_000;
auto sieve(T)(T max = MAX) {
import std.bitmanip : BitArray;
BitArray n;
n.length = max;
T[] p
On Thu, 25 Dec 2014 03:07:55 +
aldanor via Digitalmars-d-learn
wrote:
> On Thursday, 25 December 2014 at 02:28:47 UTC, ketmar via
> Digitalmars-d-learn wrote:
> > happy hacking! ;-)
>
> Thanks once again! I think this mostly solves it. Would it be
> possible to somehow do the same trick wi
On Thursday, 25 December 2014 at 02:28:47 UTC, ketmar via
Digitalmars-d-learn wrote:
happy hacking! ;-)
Thanks once again! I think this mostly solves it. Would it be
possible to somehow do the same trick with this()? (I guess due
to having to write Type!() when default template arguments are
On Thu, 25 Dec 2014 02:07:51 +
aldanor via Digitalmars-d-learn
wrote:
> I'm wondering how to best implement the following pattern: the
> constructor of a class has some required and some optional
> arguments; and one of the (optional) arguments also controls if
> any additional arguments s
I'm wondering how to best implement the following pattern: the
constructor of a class has some required and some optional
arguments; and one of the (optional) arguments also controls if
any additional arguments should be passed.
A hypothetical/simplified example that I came up with: there's a
because in most cases the user will use the Point structure with
doubles, and only in rare cases Point with ints. So to simplify code
one doesn't have to write Point!double in all of their code, but
simply Point.
If the bang syntax wasn't required in presence of default arguments
then t
Point!double in all of their code, but
simply Point.
If the bang syntax wasn't required in presence of default arguments
then these workarounds wouldn't be needed.
I've wondered the same thing, why this doesn't work:
template Foo (T = int) {}
mixin Foo;
But this works:
t
#x27;t have to write Point!double in all of their code, but
simply Point.
If the bang syntax wasn't required in presence of default arguments
then these workarounds wouldn't be needed.
Perhaps a different approach:
struct PointT(T) {...}
alias PointT!(double) Point;
// and if so desir
and only in rare cases Point with ints. So to simplify code
> one doesn't have to write Point!double in all of their code, but
> simply Point.
>
> If the bang syntax wasn't required in presence of default arguments
> then these workarounds wouldn't be needed.
There
#x27;re not both a template Point() that takes a type argument
>> is because in most cases the user will use the Point structure with
>> doubles, and only in rare cases Point with ints. So to simplify code
>> one doesn't have to write Point!double in all of their code, but
#x27;t have to write Point!double in all of their code, but
simply Point.
If the bang syntax wasn't required in presence of default arguments
then these workarounds wouldn't be needed.
How would you then pass a single-argument template as a template alias
parameter?
Example:
temp
Point.
If the bang syntax wasn't required in presence of default arguments
then these workarounds wouldn't be needed.
28 matches
Mail list logo