I have this code:
import std.stdio;
struct NotNull(T : Object) {
private:
T _value;
public:
@disable
this();
// constructs with a runtime not null check (via assert())
this(T value) {
assert(value !is null);
On Monday, 23 April 2012 at 18:44:37 UTC, Casey wrote:
I actually did print out the value being passed successfully.
It's just that when I used the queue methods (enqueue and
dequeue), it get this error. The queue itself is shared, but
none of the methods are expecting a shared value nor do
Count(5) is easy to replace with iota(5, int.max),
This also means that for the OP problem, using repeat(0) is more
correct than using count(), because count on default yields ints,
that are limited to about 2 milliards.
Bye,
bearophile
jerro:
Couldn't it just be iota with no parameters?
The Count range has a helper count() function similar to this,
that's meant to have an argument that defaults to zero:
Count!T count(T)(T start=0) if (isIntegral!T) { return
Count!T(start); }
The argument allows it to start from another
It's for a different purpose. So the count() I was proposing
will need a different name.
Couldn't it just be iota with no parameters?
On 04/23/2012 11:44 AM, Casey wrote:
> I actually did print out the value being passed successfully. It's just
> that when I used the queue methods (enqueue and dequeue), it get this
> error. The queue itself is shared, but none of the methods are expecting
> a shared value nor do I believe they
On Monday, 23 April 2012 at 02:34:19 UTC, Ali Çehreli wrote:
This works at least with 2.059 on 64-bit Linux:
import std.stdio;
import std.concurrency;
import core.thread;
class Foo
{
int i;
}
void workerFunc(Tid owner)
{
receive(
(shared(Foo) foo) {
writeln("Before:
On 04/23/2012 10:56 AM, Joseph Rushton Wakeling wrote:
On 23/04/12 19:46, Joseph Rushton Wakeling wrote:
On 23/04/12 18:56, bearophile wrote:
jerro:
return repeat(0).map!(_ => uniform(lower, upper))();
Yes, this works nicely. Thanks very much!
Is this a new addition? With GDC I get a com
On 23/04/12 19:46, Joseph Rushton Wakeling wrote:
On 23/04/12 18:56, bearophile wrote:
jerro:
return repeat(0).map!(_ => uniform(lower, upper))();
Yes, this works nicely. Thanks very much!
Is this a new addition? With GDC I get a compiler error:
expression expected, not '>'
... sugge
On Monday, 23 April 2012 at 17:18:30 UTC, Namespace wrote:
I thought that something like this
// not_null_struct.d
NotNull!(T) assumeNotNull(T : Object)(T t) {
return NotNull!(T)(t);
}
@property
NotNull!(T) makeNotNull(T : Object)() {
T t = new T();
return assu
On 23/04/12 18:56, bearophile wrote:
jerro:
return repeat(0).map!(_ => uniform(lower, upper))();
repeat(0) returns the same sequence as cycle([0]) and is as fast
as it gets, since popFront does nothing and empty is an enum.
Good idea.
Yes, this works nicely. Thanks very much!
On Monday, April 23, 2012 13:42:36 Jacob Carlborg wrote:
> On 2012-04-23 10:26, Era Scarecrow wrote:
> > On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote:
> >> "public" is the default access level.
> >
> > So it is... That explains why the tests came out backwards on the
> > results.
I thought that something like this
// not_null_struct.d
NotNull!(T) assumeNotNull(T : Object)(T t) {
return NotNull!(T)(t);
}
@property
NotNull!(T) makeNotNull(T : Object)() {
T t = new T();
return assumeNotNull(t);
}
// not_null.d which import not_null_struct.
ixid:
> Or any other appropriate methods to achieve things like:
>
> Loop unrolling
> foreach(i;0..12)
> //stuff involving the value
See Iota!() I've written here:
http://d.puremagic.com/issues/show_bug.cgi?id=4085
Bye,
bearophile
jerro:
> return repeat(0).map!(_ => uniform(lower, upper))();
>
> repeat(0) returns the same sequence as cycle([0]) and is as fast
> as it gets, since popFront does nothing and empty is an enum.
Good idea.
---
Dmitry Olshansky:
> What's wrong with:
> http://dlang.org/phobos/st
I think, WRITE_THROUGH would cause problems on many small files.
On Mon, 23 Apr 2012 09:49:50 -0400, Jay Norwood wrote:
On Monday, 23 April 2012 at 11:27:40 UTC, Steven Schveighoffer
wrote:
I think using std.string.icmp is the best solution. I would expect it
to outperform even schwartz sort.
-Steve
icmp took longer... added about 1 sec vs 0.3 sec (
Not really specific to D, but since there are git experts here: recently
while trying to determine when a D bug was introduced, I checked out old
revisions of druntime/phobos (detached HEAD state). This morning, I ran
git pull on both repos with --ff-only, and now git insists that I'm
ahead of upst
On Monday, 23 April 2012 at 14:50:14 UTC, Adam D. Ruppe wrote:
On Monday, 23 April 2012 at 14:31:05 UTC, Namespace wrote:
Yes, that's what i wrote a site before. Otherwise you couldn't
use it in other modules, that's right.
yeah i'll fix that next time i work on it.
I wouldn't write for all
Did you try without WRITE_THROUGH and without sequential scan?
Am 23.04.2012 16:51, schrieb ixid:
Or any other appropriate methods to achieve things like:
Loop unrolling
foreach(i;0..12)
//stuff involving the value
You can use this tuple-range, which is Compile-Time:
template TupleRange(int from, int to) {
alias TupleRangeImpl!(to-1, from) TupleRang
What about (untested):
auto uniformRange(T1 lower, T2 upper) {
return count().map!(_ => uniform(lower, upper))();
}
Where count() is just:
http://d.puremagic.com/issues/show_bug.cgi?id=7839
In the meantime cycle([0]) is acceptable but slower (untested):
return cycle([0]).map!(_ => uniform(
On 23.04.2012 17:52, bearophile wrote:
Joseph Rushton Wakeling:
struct UniformRange(T1, T2)
{
T1 _lower;
T2 _upper;
@property enum bool empty = false;
this(T1 a, T2 b)
{
_lower = a;
_upper = b;
}
@property auto ref front()
{
assert(!empty);
return uniform(_lower, _upper);
}
void popFront()
Or any other appropriate methods to achieve things like:
Loop unrolling
foreach(i;0..12)
//stuff involving the value
And making multiple functions with different values:
func1(int a) {//stuff}
func2(int a) {//stuff}
func3(int a) {//stuff}
where func 1 to 3 are all generated at compile ti
On Monday, 23 April 2012 at 14:31:05 UTC, Namespace wrote:
Yes, that's what i wrote a site before. Otherwise you couldn't
use it in other modules, that's right.
yeah i'll fix that next time i work on it.
I wouldn't write for all the objects which i would check
"method_with_not_null_object(Con
On Monday, 23 April 2012 at 11:04:24 UTC, Benjamin Thaut wrote:
Am 23.04.2012 09:14, schrieb Namespace:
I made several tests with NotNull yesterday and actually they
all passed.
In special cases i didn't get a compiler error but then a
runtime error
is better then nothing. :)
But there is sti
On Sunday, 22 April 2012 at 10:58:10 UTC, Namespace wrote:
If i got you right on git, you wouldn't allow something like
this:
NotNull!(Foo) f = new Foo(); and instead you want that
everybody writes
NotNull!(Foo) f = assumeNotNull(new Foo);
Is that correct?
No, I think that's too annoying, tho
On Sunday, 22 April 2012 at 16:59:05 UTC, Jesse Phillips wrote:
As such checkNotNull shoud be more than throwing an exception.
I have tried this, but it should get some constraints. Also
wouldn't the new lambda syntax look nice with null here: null
=> unsafe(a)?
Yeah, I like this idea, though
Joseph Rushton Wakeling:
struct UniformRange(T1, T2)
{
T1 _lower;
T2 _upper;
@property enum bool empty = false;
this(T1 a, T2 b)
{
_lower = a;
_upper = b;
}
@property auto ref front()
On Monday, 23 April 2012 at 11:27:40 UTC, Steven Schveighoffer
wrote:
I think using std.string.icmp is the best solution. I would
expect it to outperform even schwartz sort.
-Steve
icmp took longer... added about 1 sec vs 0.3 sec (for
schwartzSort ) to the program execution time.
bool myC
For some reason this got lost in the ether, so I'm resending.
Related to my earlier question on passing a function -- I was wondering if
there's a trivial way of generating a lazily-evaluated range of random numbers
according to a given distribution and parameters.
I wrote up the code below t
On 2012-04-23 10:26, Era Scarecrow wrote:
On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote:
"public" is the default access level.
So it is... That explains why the tests came out backwards on the
results Wasn't it private by default in C++? I honestly don't know
sometimes.
On 2012-04-23 10:05, Christophe wrote:
Hum, an acceptable solution would be to give an error, asking to
explicitely asking to fully qualify the name :
void fun(int c = 0) {...}
void main()
{
int c;
fun(c=5); // error, ambiguous qualifier "c"
fun(main.c = 5); // ok
fun((c=5)); // ok
On Sat, 21 Apr 2012 19:24:56 -0400, Jay Norwood wrote:
While playing with sorting the unzip archive entries I tried use of the
last example in http://dlang.org/phobos/std_algorithm.html#sort
std.algorithm.sort!("toLower(a.name) <
toLower(b.name)",std.algorithm.SwapStrategy.stable)(entries)
On Mon, 23 Apr 2012 01:32:25 +0200, Jonathan M Davis
wrote:
On Monday, April 23, 2012 01:21:21 Era Scarecrow wrote:
I think I have a misunderstanding of how 'package' is suppose to
work. How I understand it, you will give access to the directory,
unlike private which will hide it outside o
On Sat, 21 Apr 2012 18:25:44 -0400, Ali Çehreli wrote:
In D, arrays are what they should have been in C :). A pointer and a
size. Something the equivalent of the following (for the int type):
struct int_Array
{
int * elements;
size_t number_of_elements;
}
Technically speaking, th
Am 23.04.2012 09:14, schrieb Namespace:
I made several tests with NotNull yesterday and actually they all passed.
In special cases i didn't get a compiler error but then a runtime error
is better then nothing. :)
But there is still my problem with this:
void foo(NotNull!(Foo) n) {
}
void bar(
On Monday, 23 April 2012 at 08:47:22 UTC, Simen Kjaeraas wrote:
On Mon, 23 Apr 2012 10:38:27 +0200, Dmitry Olshansky
wrote:
On 23.04.2012 12:06, Simen Kjaeraas wrote:
On Mon, 23 Apr 2012 09:14:12 +0200, Namespace
wrote:
I made several tests with NotNull yesterday and actually
they all pa
On Mon, 23 Apr 2012 10:38:27 +0200, Dmitry Olshansky
wrote:
On 23.04.2012 12:06, Simen Kjaeraas wrote:
On Mon, 23 Apr 2012 09:14:12 +0200, Namespace
wrote:
I made several tests with NotNull yesterday and actually they all
passed.
In special cases i didn't get a compiler error but then a
No. The whole point of NotNull is that it should enforce not
being null.
Allowing implicit casting from PossiblyNull to NotNull would
break this.
Then i'm further for a keyword that checks an object for not null.
Or you check at runtime to avoid null, e.g. with assert or
enforce.
On 23.04.2012 12:06, Simen Kjaeraas wrote:
On Mon, 23 Apr 2012 09:14:12 +0200, Namespace
wrote:
I made several tests with NotNull yesterday and actually they all passed.
In special cases i didn't get a compiler error but then a runtime
error is better then nothing. :)
But there is still my pr
On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote:
"public" is the default access level.
So it is... That explains why the tests came out backwards on
the results Wasn't it private by default in C++? I honestly
don't know sometimes.
"Jakob Ovrum" , dans le message (digitalmars.D.learn:34971), a écrit :
> That is exactly the problem though, it can silently change the
> behaviour of existing code. It is the worst kind of breaking
> change, hence I don't think it will ever be in D in this form,
> much less the current iteratio
On Mon, 23 Apr 2012 09:14:12 +0200, Namespace
wrote:
I made several tests with NotNull yesterday and actually they all passed.
In special cases i didn't get a compiler error but then a runtime error
is better then nothing. :)
But there is still my problem with this:
void foo(NotNull!(Foo
I made several tests with NotNull yesterday and actually they all
passed.
In special cases i didn't get a compiler error but then a runtime
error is better then nothing. :)
But there is still my problem with this:
void foo(NotNull!(Foo) n) {
}
void bar(Foo n) {
}
in my optinion it must exi
45 matches
Mail list logo