« first day (455 days earlier)      last day (4498 days later) » 

11:00 AM
@RMartinhoFernandes No, the same thing would happen with rand() % n % (i + 1). Note the % n.
 
rand() % (i+1) only gives you an uniform distribution if i+1 is a divisor of the maximum value of rand().
 
Yes, but rand() is still way better than rand() % n.
 
Guess what, shuffle1 doesn't give me results as good.
 
Does my answer make sense now?
 
4 mins ago, by FredOverflow
What happens if you initialize x to the sorted sequence [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] again before shuffling in line 20?
 
11:04 AM
@FredOverflow Bad things... ideone.com/hz92t
 
@RMartinhoFernandes Now try replacing line 7 with std::uniform_int_distribution<int> dist(0, 32767); to emulate rand(), what happens then?
 
And results for shuffle1, both methods: ideone.com/Wfl4J ideone.com/hz92t
 
It should get a lot better with my last suggestion.
 
0 doesn't even move.
I'm sure I'm doing something wrong.
 
WTF? That's a strange result.
What happens if you replace 32767 with a huge number like one billion?
Can you make the variables in lines 6 and 7 static, so they aren't initialized again and again? Maybe that's the problem.
 
11:08 AM
Wait...
I got it.
@FredOverflow Exactly.
 
Isn't programming with randomness fun? :)
 
Yay! Slightly varied results!
Bad Ctrl+V.
 
See! It is even distribution
 
@RMartinhoFernandes That looks a lot better. Now just to be sure, if you replace 1000000000 by n - 1, does it get funny again?
 
Bigger variance: ideone.com/bakKf
Needs real stats to be sure :(
 
11:11 AM
450480 450404 450545 449874 450795 447728 449992 451383 449752 449047
Looks good enough to me. How does shuffle1 compare?
 
449858 449621 450391 450766 449351 449356 451100 450305 449060 450192
Looks just as good to me, but I'm not a statistician :)
 
I know what kind of test one can do for this, but I just have no idea how it's done :(
 
@Pubby still not 100% clear to me, but +1 anyway
 
@FredOverflow Do you understand the cases for N=2 and N=3?
 
11:15 AM
Let's see how far I can go in doing wikipedia powered stats...
 
@Pubby The N=2 case is trivial, it's only one iteration with i = 1.
 
Yes. Do you agree that N=3 holds too?
 
@Pubby you only proved it for N=2 and N=3. That's not induction.
 
Oh I see, you simply insert the new element anywhere in the sequence.
 
You need to prove that if it holds for N-1, it also holds for N.
 
11:17 AM
He does, above the word "shitty" :)
 
As in, any N.
lol
 
But the diagram is so fucking terse! Still haven't grasped it.
 
Well, think of a tree
each child is the permutations of the height, if that makes sense
 
okay, thinking of a tree...
 
For N=3, the top node's childrens are the permutation of the first 2 indices
01,2 10,2
 
11:20 AM
I think I got it. You just take the old permutations and then simply insert the new element in each possible position, right?
 
Chi-squared = 24552.4
 
@RMartinhoFernandes What does that tell us?
 
Yay, now anyone knows what can I do with this?
 
@FredOverflow Yes.
 
I have to look it up on some table somewhere.
 
11:21 AM
@Pubby Sounds perfectly reasonable. Unless someone objects in the next couple of hours, prepare yourself for an accepted answer.
And then we can downvote Jon Skeet's answer. Did that ever happen before? :)
 
Oh Hello all :)
 
Hmm, the largest value I can see in a table is 10.83. 24 thousand sounds like too much.
Damn,
 
Maybe that table needs to be scaled appropriately for the input?
@RMartinhoFernandes How about you post that as evidence?
 
Well, for bigger values the probability that the results are not random increases...
I'm doubting that calculation of the statistic.
Damn you wikipedia!
shakes fist
 
Anyway, this was really interesting. What std::algorithm should we dissect next? :)
 
11:34 AM
^ very silly, youtube says the video is unlisted and only those with a link can see it, hah!
 
Isn't that the guy who played in Black Books?
 
That's way over the top.
Hmm, now I get 65.9408. That still tells me it's significantly different from a uniform distribution.
I should have paid attention in stats class.
 
Probably the PRNG's fault.
What happens when you pick a bigger number than 100000?
 
What pisses me off the most is that I passed stats class.
@FredOverflow Time limit exceeded :(
 
So what? I passed a lot of classes, but I cannot remember things I learned 5 years ago and never used since.
 
11:39 AM
@FredOverflow It was last year.
 
oh :)
 
And when I passed it, I didn't know this either.
 
lol
Well at least you didn't forget it then ;)
 
So, I discovered an error in my calculations. Nice. And now I get an even higher probability of non-uniform. I really suck at this.
 
11:45 AM
@RMartinhoFernandes Just let it go and accept @Pubby's proof ;)
 
^ is it just me, or have the volume and tone controls been removed on that guitar?
 
@FredOverflow Oh, I've accepted that. But I want my results to match that!
 
Where does mt19937 get its initial seed?
 
@AlfPSteinbach I think that's a guy
 
The default seed is such that " The 10000th consecutive invocation of a default-constructed object of type mt19937 shall produce the value 4123659995."
Anyway I need to go. Bye.
 
11:48 AM
@Pubby nah, but here's one, apparently an asian brought up in Scotland:
what's the disease that afflicts his legs? i can't remember the name.
 
Knock-knee?
 
12:03 PM
@Pubby yah, thnaks! genu valgum...
 
@AlfPSteinbach His? Is that a guy? OMG
 
Tin
hey guys!
is there a way to get a list of files (std::vector<std::string>) in a given directory using c++11?
i need sth. that is cross-platform ideally
 
@Tin boost filesystem
note that the current version does not support general unicode filenames in Windows when it's compiled with g++, i.e., for Windows use Visual C++
 
Tin
@AlfPSteinbach, thanks, i found actually sth. related to (boost)[stackoverflow.com/questions/612097/…, but would like to avoid using it. i would like to have sth. without any dependencies
 
@Tin then you're out of luck. only the standard library can do that. and it doesn't.
 
Tin
12:16 PM
:(
so far, i was reading a .txt file and processing line by line, i just wanted to do sth. more automatically. it seems though that C# offers such a functionality, right? for instance, i found sth. related to DirectoryInfo
 
@Tin well not C# as such, but the .NET platform.
 
Tin
@AlfPSteinbach, ah ok! thanks ;-)
 
if you're targeting only .NET (or common runtime platforms) then C++/CLI has the same, since it's provided by the platform
 
Tin
@AlfPSteinbach, thanks for the advice
@AlfPSteinbach, do you mind in checking briefly a const copy constructor for a class with std::unique_ptr as smart pointer? I'm getting some compiler errors. I would not like to copy construct the object pointed, but to move it. here the code pastebin.com/SjjD2pD9
 
Tin
12:39 PM
the question is open for sure to anyone who would like to shed some light :-)
 
@Tin not sure what you're asking. you have both a copy constructor and a move constructor. but in general (1) only post working code (in this case you have a mixture of names like Matrix and Foo), (2) inside the Foo template you generally don't have to write Foo<T> but can just write Foo, (3) don't force unnecessary qualification like the Bar_ prefix for the smart pointer name
 
2
A: Generic way of getting const-qualification of elements from container

FredOverflowI think you are looking for typename C::reference, see 23.2.1 [container.requirements.general] §4. Oh wait, the above doesn't work if C is already const. But wait, decltype to the rescue! template <typename C> auto get_nth( C&& c, int i ) -> decltype(*c.begin()) { //......

requesting proofread by template god
 
@Tin i looked at your copy constructor. it does an Unholy Move. don't.
 
Tin
@AlfPSteinbach, I updated the code pastebin.com/4FrefQ7Q
with working code
is there any problem in supplying a copy constructor and a move constructor?
why is it an Unholy move? how does a correct copy constructor would look like for this case then?
in line 61, i'm pointing the error i'm getting => pastebin.com/B1uSAhGK
 
@Tin it's Unholy because a move tends to modify the moved-from object. that's not a copy, and it's not permitted when the source object is const. your compiler should protest at that.
to copy you need to copy
it's that simple
 
Tin
12:48 PM
ok, i thought, i could avoid to create a copy, by only moving the pointer
 
you could possibly share ownership, if the referred object is never modified
 
Tin
i actually used shared_ptr for this class, but when i moved to unique_ptr, i get the referred compiler error
 
Tin
therefore, i thought, i could std::move and that should work
but now i see your point
i'm still having some difficulties to understand when to use a shared_ptr and when to use a unique_ptr, given your experience do you have a suggestion?
 
@Tin use them so that their names express the intended kind of ownership
 
Tin
12:54 PM
@AlfPSteinbach also you pointed that I had both a copy constructor and a move constructor, is there any problem by supplying both?
 
30
Q: Which kind of pointer do I use when?

sbiOk, so the last time I wrote C++ for a living, std::auto_ptr was all the std lib had available, and boost::shared_ptr was all the rage. I never really looked into the other smart pointer types boost provided. I understand that C++11 now provides some of the types boost came up with, but not all o...

 
Tin
@FredOverflow, thanks for the link ;-)
 
@Tin no, i was just trying to find out what you were really asking
 
Tin
@AlfPSteinbach :-) so, it means, that it's actually correct to provide both, right ?
 
1:12 PM
@Tin That depends, but it's definitely not unheard of to implement both.
 
Tin
@FredOverflow, do you have an example when it could eventually heard?
 
@Tin I don't know, the implementation of std::vector?
 
@RMartinhoFernandes what are you doing, or at least trying to do?
 
@rubenvb He wants to prove that the following distribution is randomly uniform or something:
 
Tin
@FredOverflow, why the implementation of std::vector could represent such a case?
 
1:27 PM
450480 450404 450545 449874 450795 447728 449992 451383 449752 449047
 
10 numbers can hardly be distributed in any single way.
 
@Tin Because a std::vector has a pointer member, and just copying the pointer does the wrong thing, so you need a copy constructor that does a deep copy. And a move constructor is a nice optimization that makes moving vectors more efficient than copying.
 
@AlfPSteinbach hmm he only ever plays the top one in that vid
boring
 
@JohannesSchaublitb: I just uploaded a new GCC 4.7 build for MinGW-w64 is you're still interested
 
@rubenvb ohh nice thanks
 
1:36 PM
@JohannesSchaublitb see here for x64 Windows: sourceforge.net/projects/mingw-w64/files/…
 
4.7 is not out yet, is it?
 
no it's not.
It's pretty stable-ish though
 
Tin
@FredOverflow, ok, i think, i get your point. that's a scenario when only a move constructor is provided and not a copy constructor, right?
 
@Tin What? No, you definitely want to be able to copy vectors.
 
Tin
@FredOverflow, exactly. that's what i was trying to point. if you don't provide a copy constructor no deep copy will happen.
now, if you only provide a move constructor and not a copy constructor, what will happen?
 
1:45 PM
@Tin Each time someone tries to assign the vector with the intent to copy its contents, the old vector is effectively rendered useless.
 
@rubenvb No, the move constructor won't accept lvalues.
@Tin If you only provide a move constructor, no copy constructor will be implicitly provided for you, and code that would normally invoke the copy constructor will fail to compile.
 
Tin
@FredOverflow, ok, thanks ;-)
 
That's why std::unique_ptr<T> a(new A()); std::unique_ptr<T> b(a); won't compile, because it would have to copy a into b which is not possible.
 
Tin
and that's why one needs to do sth. like: std::unique_ptr<T> a(new A()); std::unique_ptr<T> b(new A(*a)); , right?
 
I depends on what you want. Do you want another unique_ptr that points to a copy of the thing pointed to by the first, or do you want to transfer ownership?
 
Tin
1:57 PM
if we want another unique_ptr that points to a copy, then it would be ok, right?
 
Tin
if we want to transfer the ownership, it should be sth. like: std::unique_ptr<T> a(new A()); std::unique_ptr<T> b(std::move(a));, correct?
 
exactly
 
Tin
@FredOverflow, great!
@FredOverflow but now, when does one needs to do only a transfer of the ownership? do you have an illustration?
 
@JohannesSchaublitb no, he plays two of them
 
2:06 PM
@AlfPSteinbach um then i missed the other one. prolly a very short use of it
 
I wish that there was a Reader's Digest version of Stephen Baxter's Xelee series. Because I found my reading speed increased exponentially. At the end I don't think I used more than 0.1 second per page, there was so little actually going on, just empty talk all the way. :-(
@JohannesSchaublitb yes
 
@Tin Well, some types simply aren't copyable, like file handles or mutexes and such.
 
My mom had a Reader's Digest subscription when I was a kid. I read it a lot.
 
And wasn't the name "Xeelee" already used by the good writer, whatever's his name?
Oh, OK, no, they were the Heechee.
But sounds very alike.
The Heechee are a fictional alien race from the science fiction works of Frederik Pohl. The Heechee are portrayed as an exceedingly advanced star-travelling race that explored Earth's solar system millennia ago and then disappeared without a trace before humankind began space exploration. The Heechee first appeared in "The Merchants of Venus" (1972), a novella in the collection The Gold at the Starbow's End, sometimes called "The Merchants of Venus Underground". They also are referenced or appear in many of Pohl's novels and short stories published between 1977 and 2004. Pohl's novels fe...
 
@Tin Return value of a factory of a non-copyable type.
 
2:13 PM
The Xeelee are a fictional hyperadvanced species from Stephen Baxter's Xeelee Sequence. They were first remotely mentioned in the 1994 novel Timelike Infinity and were later central actors of several novels and a substantial number of short stories. Within the Xeelee Sequence, they are considered to be the most advanced of all Baryonic life-forms and possess technology and abilities far beyond other spacefaring civilization. They have demonstrated the ability to routinely construct Closed Timelike Curves and have exploited time travel to engineer their own evolution and history as far back...
Easy to confuse I think
 
Tin
@StackedCrooked, got it! thanks!
 
The muumuu or muumuu () is a loose dress of Hawaiian origin that hangs from the shoulder. Like the Aloha shirt, muumuu exports are often brilliantly colored with floral patterns of generic Polynesian motifs. Muumuu for local Hawaiian residents are more subdued in tone. Muumuu are no longer as widely worn at work as the aloha shirt, but continue to be the preferred formal dress for weddings and festivals such as the Merrie Monarch hula competition. They are also frequently worn as a uniform by women working in the hotel industry. Muumuu are also popular as maternity wear because they do...
 
Tin
@FredOverflow, as for this case std::unique_ptr<T> a(new A()); std::unique_ptr<T> b(new A(*a)); what if the class A is an abstract class?
this is where a virtual unique_ptr<A> A::clone() const make sense, right? so as to do std::unique_ptr<T> b(a->clone());
is that correct?
 
user406009
Can anyone explain how boost::asio is able to store copies of templated functors?
 
Hm.. variadic packs don't expand into the comma operator, do they...
So you can't just say f(args)...; to call a bunch of functions.
 
2:27 PM
@EthanSteinberg it uses something like std::function
 
user406009
So it is not statically typed(like how std::vector is static)?
 
user406009
Well how std::vector's allocator is static.
 
@KerrekSB That's why you have a call(...) function
 
@Pubby Have you? You mean in the standard?
 
I don't think it's in the standard
 
2:29 PM
I can make a template Dummy to say Dummy(f(args)...);, but not if f returns void.
I guess it's back to the recursive solution.
 
@EthanSteinberg it can hold any Callable, so yes, it's kinda dynamically typed
 
I thought the standard has some sort of INVOKE though, or perhaps that's only theoretical.
 
@KerrekSB Use brace enclosed list
 
@Abyx I think it uses type-erasure.
@Pubby How?
 
user406009
So it is unable to optimize static functions(which is probably impossible for something like a task queue).
 
2:30 PM
  struct pass {
    template<typename ...T> pass(T...) {}
  };

  pass{(some_function(args), 1)...};
That is from wikipedia
 
that's from me
look into history ^^
 
@Pubby Oh, you remove the void type by using the comma
clever
@JohannesSchaublitb Same thing :-)
 
@EthanSteinberg see implementation.
 
I.e. wikipedia is a version of Johannes
3
@Pubby Nothing to do with braces.
template <typename... Args> void Dummy(Args...) {} does just fine.
Dummy((f(args),1)...);
 
2:33 PM
Oh yeah, that works too
 
no, the braces require left to right evaluation
without them the f(arg) calls may be done in any order
 
user142019
Terrific afternoon.
 
user142019
Why is it so quiet?
 
@JohannesSchaublitb Ohh, intriguing
So could I just say auto a = {(f(args),1)...};?
 
yes indeed :)
 
2:41 PM
Or would I need to include <initializer_list>?
 
yes I believe you would
 
There's something about it being UB if you use the list without including the header...
 
alternatively you could say int a[] = { .... }
 
OK, now without the a.
 
or alias<int[]>{...} (alias being identity with alias templates...)
 
2:42 PM
@Tin yes
 
remember that c++11 allows you to create temporary arrays like that
 
Hm, (int[]{(f(args),1)...}); doesn't work
 
no. you need to "parenthesize" the "int[]"
so that it's a single type name or keyword or a template-id like "foo<..>"
 
Oh, compound literals -- not in C++, though!
 
no, not compound literals
 
2:44 PM
@JohannesSchaublitb typename ...T looks weird, I like typename... T better :)
 
functional casts
 
@JohannesSchaublitb I'm lost.
 
template<typename T> using alias = T; int main() { auto &&x = alias<int[]>{1, 2, 3}; }
that works perfectly fine
 
I clearly can't have a temporary naked array, because there are no CLs. So I have to loop it through some dummy template, right?
 
What is a CL?
 
2:45 PM
yes you can have "temporary naked arrays". there is no need for compound literals
 
@JohannesSchaublitb But I don't want the unused x
@FredOverflow "compound literal"
 
if you like the call them that way you can, though. but they do not have the c99 meanings
@KerrekSB then just don't assign to a reference
 
@JohannesSchaublitb Ah, right. Just alias<int[]>{...}?
 
@JohannesSchaublitb Well, I can't get rid of the alias, right?
Because the naked expression would be a CL
 
2:47 PM
unlike c99 CL, in c++ that array will have full expression life time, instead of automatic lifetime, though
 
@JohannesSchaublitb What is a naked array?
 
@KerrekSB you can say std::common_type<int[]>::type{1, 2, 3} but that is ugly
 
@FredOverflow If I just replaced alias by its content: (int[]){1,2,3}
 
@FredOverflow dunno ask @KerrekSB xD
yes that is the CL syntax
 
@JohannesSchaublitb Right. So the alias is just there to get around the grammar?
 
2:48 PM
@KerrekSB Does that actually work?
 
@FredOverflow Not officially
GCC supports it as an extension, and it's in C99
 
C++ arrays are so ugly!
 
@FredOverflow just say alias<int[]>{1, 2, 3} i don't think that's anymore ugly than (int[]){1, 2, 3}
it perfectly fits into the functional cast scheme
or you can say void f(int const(&)[3]); int main(){ f({1, 2, 3});}
 
@JohannesSchaublitb How can I even cast to an int[], isn't int[] an incomplete type?
 
template<int S> void take(int(&&)[S]); template<typename ...T> void f(T &&...t) { take<sizeof...(T)>({(g(t), 1)...}); }
xD
@FredOverflow it will deduce the size
liek for int a[]= {1, 2, 3}
unfortunately it does not work above. you cannot say int(&&)[] and bind it to a int(&&)[N]. c++ would need "compatible types" concept for this to work
in c it works, you can let a int(*)[] point to a int[N] there
 
2:54 PM
@JohannesSchaublitb ah okay
@JohannesSchaublitb example code plz?
 
"in c it works..."
 
@FredOverflow is asking for C code in the C++ lounge.
 
Please don't burn me at the stake!
 
Is there a flag for that, or should I open a question on meta?
 
2:56 PM
How about asking on StakeOverflow?
 
@FredOverflow please ask on StackOverflow about an example!
lol
 
Yes, give @JohannesSchaublitb more free rep
 
i will not answer it
i will just be happy about seeing my name put into his famous question and make a troll face behind the scenes
 
int main()
{
    int(*a)[] = (int[]) {1, 2, 3};   // warning: initialization from incompatible pointer type
    int *b    = (int[]) {1, 2, 3};   // ok
}
@JohannesSchaublitb It doesn't seem like it's possible, did I do something wrong?
 
user406009
@Fred shouldn't the first one be: int(&a)[] = (int[]) {1, 2, 3};
 
3:09 PM
@EthanSteinberg C doesn't have references.
 
3:30 PM
@FredOverflow yes you did it th wrong way
you need int(*a)[] = &(int[]) {1, 2, 3};
 
@JohannesSchaublitb Oh, I can take the address? What's the lifetime of (int[]) {1, 2, 3}?
 
user406009
Doesn't the lifetime of a temporary end when the statement ends?
 
I don't think C has temporaries.
 
user406009
So that literal would already be dead.
 
@FredOverflow it'S an lvalue and has automatic lifetime
 
3:36 PM
@JohannesSchaublitb meaning it dies at the end of the scope?
 
That's funny. C is funny.
 
C has temporaries
 
c1x introduced full expression temporaries IIRC
 
@Pubby What would be an example of such a temporary?
 
user406009
3:37 PM
Isn't what you are doing functionally equavalent to ideone.com/RSDhS
 
c99 and c89 has had problems with arrays contained in structs when returned from functions because they were alive only until the next sequence point
 
12
Q: printing a member of a returned struct

FredOverflowI'm having trouble printing a member of a struct that is returned from a function: #include <stdio.h> struct hex_string { char a[9]; }; struct hex_string to_hex_string_(unsigned x) { static const char hex_digits[] = "0123456789ABCDEF"; struct hex_string result; char * p =...

 
so when you said printf("%s", f().str); with struct A { char str[255]; }; you had UB in C99. AFAIK C1x makes this well defined
 
@EthanSteinberg No, because your code doesn't compile :)
 
yes you even have a question about it xD
 
3:39 PM
I was bound to stumble onto this niche sooner or later, wasn't I? :)
 
user406009
@JohannesSchaublitb What is the new defined behavior?
 
@EthanSteinberg In the next C standard, the "temporary" will live until the end of the full-expression just like in C++.
 
user406009
So it will work as expected?
 
user406009
Finally sane people on the standards committee.
 
Oh wait, C1x is now called C11 and it has been released one month ago :)
Although I wonder how much sense a new C standard makes. Does anyone even program in C99 so far?
 
3:42 PM
lol
 
C11 (formerly C1X) is an informal name for ISO/IEC 9899:2011, the current standard for the C programming language. It replaces the previous C standard, informally known as C99. This new version mainly standardizes features that have already been supported by common contemporary compilers, and includes a detailed memory model to better support multiple threads of execution. Due to delayed availability of conforming C99 implementations, C11 makes more features optional, to make it easier to comply with the core language standard. The final draft, N1570, was published in April 2011. The new s...
 
user406009
Technically we have all probably used some C99. stdint.h is wonderful and should have been in the standard from the start.
 
#define cbrt(X) _Generic((X), long double: cbrtl, \
                              default: cbrt, \
                              float: cbrtf)(X)
neat!
 
hi
 
c11 is so much cleaner than c++11
 
user406009
3:45 PM
@FredOverflow templates are still better.
 
@EthanSteinberg Of course, but it's unlikely C will ever get templates.
 
full stop. better for what?
 
C will never be as good as C++
 
better for macro haters
 
user406009
3:46 PM
Better for writing generic functions.
 
not only is it better, but with c11 it is nor possible at all i think
but I don't need it. i can live with generic macros too
 
I don't see why I'd need to
 
Is there any platform that supports C11 but not C++?
 
user406009
I wonder how long MSVC is going to take to be C11 compatable.
 
user406009
We will probably have C50 by then.
 
3:54 PM
0
Q: std::array<T> initialization

FredOverflowA std::array<T> is essentially a C-style array wrapped in a struct. The initialization of structs requires braces, and the initialization of arrays requires braces as well. So I need two pairs of braces: std::array<int, 5> a = {{1, 2, 3, 4, 5}}; But most of the example code I have ...

Where are the rep whores?
 
Didn't @litb explain that recently? I forgot what it was called though
 
They say you should favor composition over inheritance, but what if you consider inheritance to be a form of composition?
/troll :p
 

« first day (455 days earlier)      last day (4498 days later) »