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

4:00 AM
@GeorgesOatesLarsen Considering std::transform and std::stringstream? I don't think that naming it longer than xsputn would be a big deal
 
Xeo
@KerrekSB well, how would you call it? string32? _32string? (for wide strings it's easier: w32string)
 
@Xeo It's u32string.
The u32string typedef exists, just not the u32stringstream.
 
Xeo
Oh
Why u?
 
UTF?
Unicode?
 
Xeo
Ah, ok
Yeah, makes sense
u"...."
 
4:06 AM
@Xeo u32istringstream
@RMartinhoFernandes Correct. Why?
Defect?
 
Submit?
 
I can't see a reason not to include such a typedef. So yes, I'd call it a defect.
There are no facilities to output u32strings to the console.
 
@RMartinhoFernandes No, of course not. There is no interface between the system and Unicode.
 
Xeo
 
4:13 AM
No need. We don't need u32cout etc.
That'd be magic.
 
@KerrekSB Why?
 
Xeo
I atleast couldn't find anything related with my ctrl-F fu
 
@RMartinhoFernandes because we don't expect C++ to know how to convert stuff
 
My console can handle Unicode output.
 
that's outside the scope
 
4:14 AM
@KerrekSB Convert to what?
 
@RMartinhoFernandes To Unicode
We have "the system's encoding" for I/O
And the translation from that to unicode is potentially very complex, so it's not in the standard
there's char/wchar on the "system" side, with mbstowcs/wcstombs...
and there's char/char16_t/char32_t on the Unicode side, with u16tou32 etc.
but no way between the two worlds
 
Can I have a u32ofstream at least?
 
@Xeo Hm, I can't find anything pertinent
The original paper mentions it, though.
 
#include <string>
#include <sstream>
#include <fstream>

int main() {
    using u32stringstream = std::basic_stringstream<char32_t>;
    using u32ofstream = std::basic_ofstream<char32_t>;

    u32stringstream ss;
    ss << U"Hello world!\n" << 42;
    std::u32string stuff = ss.str();
    u32ofstream os("blah.txt");
    os << stuff;
}
This produces a 0-byte file.
 
Xeo
@RMartinhoFernandes The library defects ToC did have atleast a defect claiming that (i|o)fstream is missing wchar_t*, char16_t* and char32_t* constructors
 
4:25 AM
You'd have to check if ss.str() is at least the right thing.
 
Well, one of them isn't working.
 
And it's the ofstream.
 
Xeo
Here it is
 
os << U"blah" doesn't write anything.
 
Xeo
4:27 AM
Maybe it's the filename?
 
@Xeo That's not the problem here. I'm writing an u32string into the file. The file name is not relevant (mine is char).
@Xeo The file is created.
But nothing is written to it.
 
Xeo
Oh, ok
Weeeell... how does the fstreambuf of that u32ofstream look like?
Maybe the error's there?
 
No idea.
I just typedefed it and hoped for the best.
 
Xeo
I just get a giant pile of poo back from clang. :( It may have to do with libc++
 
A POO, PILE OF would be a good sign!
But I suspect what you got was something else.
 
4:31 AM
Oh, I think there aren't any non-string overloads.
ss << 1 doesn't work
Again because there's no internal converter.
 
It compiles on GCC.
 
You can get the numeral for "1" in the system's encoding, but you can't convert it to Unicode
@RMartinhoFernandes Does it produce output?
 
Xeo
meh, libc++ complains about this:
error: implicit instantiation of undefined
      template 'std::__1::ctype<char32_t>'
And I somehow can't get Clang to use libstdc++ oO
 
Maybe it's missing char_traits, or something.
@KerrekSB At least it sets the fail bit.
 
4:35 AM
It could have thrown, imagine
Well, this is all perfectly fine. I'm totally happy that C++ doesn't mandate this.
No reason to rope a heavy library into the language.
If anything, they should make iconv part of the standard, I suppose.
Does anything from Posix ever make it into the standard?
But Unicoding would require databases of character information, and that feels like an odd thing to require a compiler to maintain.
 
user406009
Weren't they discussing have a c++ posix wrapper thing?
 
@EthanSteinberg Who are "they"?
 
Namespace posix is reserved for the POSIX standard.
@KerrekSB The SC.
 
I haven't heard of that
@RMartinhoFernandes Oh yes, I actually knew that. Good stuff
Basically Posix should ship with a C++ wrapper!
 
@KerrekSB I suppose there's no other reason for making that reserved.
 
Xeo
4:41 AM
Argh, whyyyy. Why does clang use the libc++ headers but the libstdc++ .so when I use -stdlib=libstdc++ T_T
 
It could include reinterpret_function_cast. That would be sweet.
 
Xeo
I get the feeling I'll need to recompile clang with the added hack in InitHeaderSearchPath.cpp... ugh
 
Hey! This was online last time I checked!
It mentioned that C++ POSIX API thingy.
 
Xeo
AHH, I somehow fucked up my header search paths. D: GCC also tries to use libc++
Ugh
 
user406009
I assume Microsoft would be opposed to any major C++ POSIX abstraction. I remember hearing they spend a lot of effort de-posixing the C1X threading API.
 
Xeo
4:50 AM
I need someone who knows how to use both GCC and Clang and both libstdc++ and libc++ together on linux
 
@Xeo Who doesn't.
 
Xeo
I mean, it worked.
Until I recompiled Clang without the include search path hack
And instead added stuff to my $CPLUS_INCLUDE_PATH
 
@EthanSteinberg It's not something to be part of the C++ standard. It's for the POSIX standard.
Microsoft can simply not care about POSIX.
 
0
Q: Should I use std::move or std::forward in move ctors/assignment operators?

DaveUnless I'm wrong it seems like either works just fine - is there a best practice reason to prefer one over the other?

0
Q: When should I use remove_reference and add_reference?

DaveI'm looking at [VC10's] unique_ptr and they do a couple things I don't understand: typedef typename tr1::remove_reference<_Dx>::type _Dx_noref; _Dx_noref& get_deleter() { // return reference to deleter return (_Mydel); } unique_ptr(pointer _Ptr, typename _If<tr1:...

Tutorial hour?
Teach yourself C++ by asking 10 simple questions on SO
 
Hey! I was about to complain about the same thing!
I'm NARQing the first one, and reading the second to decide.
Oh, and there's a question too.
 
Xeo
5:00 AM
@RMartinhoFernandes The first question is stupid, indeed. Who'd use std::forward in a move ctor/ass. op?
 
@Xeo Two days ago I had to comment somewhere that using std::forward<not_template_argument_here> was stupid (after commenters "bullied" the asker to put that in the question).
And now this.
 
Xeo
std::forward only makes sense together with templates and reference collapsing (T&&). If you have only one, it's useless.
 
Here.
4
Q: Passing std::forward_as_tuple() result to multiple functions that may move from that object's rvalue-reference members?

pheedbaqEdit: I think the most likely use case for what I'm asking about, is when creating a function that receives a tuple of rvalue-references from std::forward_as_tuple(). The reason this question came to mind is because I was checking the members of objects passed to constructor initializers to see ...

 
@RMartinhoFernandes Where's that? You know it has me written all over it. :)
 
Eventually I gave up on the question because everyone was trying to make out of it whatever they wanted to answer, instead of trying to figure out what the asker wanted an answer to...
@Mysticial Oh, this is a really silly one.
0
Q: C++ - constant value for reference parameter?

RPFeltzUsually, parameter values are copied when being passed on. Using a reference may save memory, especially for big structs. However, in this case: void foo( int parameter = 7 ); void bar( const int& parameter = 7 ); in the second declaration, what exactly will it do when the default value is...

It's not the kind you want to wander on.
 
5:05 AM
@RMartinhoFernandes Ah, yes. It doesn't count as a benchmark. :)
 
Arrgh, and now one about multi-dimensional arrays. Come on, I wanted something I can enjoy answering.
Is that too much to ask?
 
lol
I had my good question yesterday... Very happy about that. Hard to hope for more though...
 
Hmm, boost.multiarray doesn't seem to allow dimensions known at compile-time.
 
Xeo
FWIW
0
A: Should I use std::move or std::forward in move ctors/assignment operators?

XeoThe question is: Are those really the move constructor / assignment operator for the class? Or do they only look like that from the corner of your eye? struct X{ X(X&&); // move ctor #1 template<class T> X(T&&); // perfect forwarding ctor #2 X& operator=(X&...

 
Already +1ed :)
 
Xeo
5:12 AM
lol, 2 +1 and accept in an instant xD
Btw, anyone willing to take part in this comment discussion here?
 
and just like that you're doing better than me already, lol
 
Yep, boost.multiarray doesn't support compile time dimensions. :(
 
@Xeo To try and get 20 comments so start another comment-deleting rage again? :P
 
@Xeo No. You didn't mention sex in your comment about the end of the world.
 
Xeo
D:
 
5:15 AM
Anyone wants to have a quick look over this? ideone.com/C2lrz
 
Xeo
Okay, done. And now?
 
lol
I wanted to see if I made any obvious mistakes.
 
Xeo
> // You should have received a copy of the CC0 Public Domain Dedication along with this software.
I didn't!
 
I don't want to post snarky pieces of code on multidimensional array questions in order to dismiss them if those pieces are buggy.
@Xeo I copied that straight from the CC0 page. And there's a link for a place to get it.
 
Xeo
Why not simply name it matrix?
Also, you can get a way nicer syntax
 
5:17 AM
@Xeo Because I reserve that for the mathematical construct.
 
Xeo
matrix2d<int[10][10]>, same partial specialization as function really
 
This one doesn't do algebra. It's just a dumb piece of data.
@Xeo Oh, that's sweet!
 
Xeo
template<class Arr> struct sarray2d;

template<class T, unsigned N, unsigned M>
struct sarray2d<T[N][M]>{ /*...*/ };
should work in theory
 
Testing as we speak.
 
Xeo
T* end() { return &storage[row * M] + M; } shouldn't the second M be N?
 
5:21 AM
No.
I want the start of the next row.
 
Xeo
Ah, right
But why don't you use T arr[N][M]?
 
Because that makes the pointer stuff harder than it needs to be.
Or maybe it doesn't. I'm not sure.
 
I've been reading the transcript and now I'm sad I missed that fun time with Ascension Systems.
 
Xeo
Hm, yeah, you'd need an iterator to be well-defined for the 2D array stuff IIRC
Since you can't legally just keep advancing the pointer and get to the next row (although it will work everywhere). I could be wrong with that, though.
 
@Xeo Oh, right that's it. I wanted to avoid that fuzzy area.
 
5:25 AM
I'm still unclear as to the purpose of that other room, though.
 
Xeo
@RMartinhoFernandes So, result?
 
@Xeo It works! Sweet.
This means I could extend it to higher dimensions if I wanted. But I won't. If you have a 3 dimensional array, you're doing it wrong.
 
Xeo
Sadly, you can't say T[][] to specialize and emulate a vector<vector<T>>
 
Well, this is just so I can drop it on MD array questions and not feel bad.
 
Xeo
Y'know, you could make std::array the underlying storage and just return its iterators
std::array<std::array<T, M>, N> storage;
 
5:28 AM
@Xeo Yeah, I thought of that, but then I'd have to switch back to C arrays to support non-C++11.
 
@DeadMG Just a note, the FAQ section on etiquette (specifically the section titled "Be Nice") applies to chat as well. Your statement here can easily be misconstrued as "not nice". I'd recommend rethinking making comments in such a way in the future.
 
I do think I need to do something about initialization.
 
Xeo
Oh noes, the meta-police! Where is my microwave?!
 
As is I can't so::sarray2d<int[2][2]> = { { 1, 2 }, { 3, 4 } };.
 
@Xeo Yes, yes, very cute =)
 
Xeo
5:30 AM
@RMartinhoFernandes Use std::array. Or write a little wrapper yourself
 
@RMartinhoFernandes flagged
 
The thing is, a nested std::array has the same "fuzzy legality" as a 2d array.
Probably even less fuzzy and more illegal.
I could just make the member public and I'd get so::sarray2d<int[2][2]> = { 1, 2, 3, 4 }; even on C++03.
 
Xeo
@RMartinhoFernandes No, it's even better defined. You should use T** anyways with the 2D array
 
@Xeo I can't iterate over the nested std::array as a whole.
 
Xeo
Err, you shouldn't. A 2D array is an array of arrays
So you should treat each level individually
And you could make a zip-iterator if you really want to
 
5:33 AM
Then I can just use a T[N][M].
 
Xeo
template<class Arr> // array2d<int[20][20]>
using array2d = typename nested_std_array<Arr>::type;
Really, no need for that extra class actually
 
Good old Basic supported 2D arrays
 
Xeo
Oh, and I just wanted to write "Fuck non-C++11" right when casper joined. I think they're on to me or something.
 
No, wait, I need at least the ability to get a pointer to the first element, and from that go all the way to the last one.
 
Xeo
@RMartinhoFernandes zip_iterator
 
5:36 AM
Because kids use these things to say, pass them to OpenGL functions.
@Xeo Not a pointer.
 
@RMartinhoFernandes Fred Overflow asked about that once. I.e., is std::array guaranteed free of padding
 
Xeo
T* stripe_begin(){ return *begin(); }
 
@Xeo Ok, but how's that better than what I have?
@AlfPSteinbach Oh, I think I remember something like that. Do you have a link?
 
Xeo
@AlfPSteinbach Yeah, but is the following actually well-formed according to the standard?
int arr[10][10] = {0};
for(int* p = &arr[0][0], e = &arr[0][0] + 100; p < e; ++p);
 
@RMartinhoFernandes nope, sorry. but you're the archivist!
 
Xeo
5:39 AM
Because I faintly remember a problem with the stepping from row to row
@RMartinhoFernandes Well, I think you'd need to differentiate between a real 2D array and a "dense" one at that point
 
@Xeo I just want something to throw at kids that cry when 2d arrays beat them up.
 
@RMartinhoFernandes sizeof(T[N]) == N*sizeof(T) hence sizeof(T[N][M]) == N*M*sizeof(T)
 
@LucDanton So, is Xeo's snippet well-formed?
Can I use a pointer to cross over objects I know are contiguous?
 
Xeo
GCC atleast has no problem
 
@RMartinhoFernandes According to one interpretation, no. According to others, yes.
 
5:42 AM
Ah, fuzzy :)
 
Xeo
Like I said, it will work in all implementations
 
Well, this is for kids anyway.
 
Xeo
But according to the standard it isn't well-formed IIRC
 
@RMartinhoFernandes I always thought that was Doug McIlroy. So I had to check. Google, no they all said Ken. Going to primary source "The UNIX Programming Environment", argh, they also say Ken (footnote on page 204). How did my memory get screwed up so badly?
 
Age.
I heard it fucks memory up.
 
5:45 AM
must be
 
So, there's no other way to get std::array-like initialization without making the member public?
 
For C++11 perhaps you can use a constructor taking two arguments constructible from list-initialization.
 
Xeo
variadic template ctor?
Or would that be non-deducible for a list-initialization?
hmmm
sarray2d(std::initializer_list<std::initializer_list<T>> list);? :D
 
 so::sarray2d<int[4][4]> x = { {  1,  2,  3,  4 },
                               {  5,  6,  7,  8 },
                               {  9, 10, 11, 12 },
                               { 13, 14, 15, 16 } };
Doesn't work with the member (int[4][4]) public.
Wants me to have an extra set of braces around the whole thing.
 
Xeo
@RMartinhoFernandes Shouldn't, if you don't have any ctor/dtor/ass. op
aka have an aggregate
 
5:51 AM
Yep, it's an aggregate.
 
God hates flags.
 
I only have operator[], begin, end, and data. Nothing else.
 
Why did you choose that template syntax over a pair (or pack) of size_t?
 
I'm only caring about two dimensions.
Beyond that, I'll just close the tab.
 
Yes… but two size_t would guarantee that. It looks like the user can plug one or three dimensions into that.
 
5:54 AM
He'll get a nasty error complaining about missing specializations if he does that :P
 
Xeo
Hm, something's wrong. I don't get why nested initialization just won't work.
 
@Xeo Yep, that's what I get.
 
template<typename T> struct foo { static_assert(dependent_false_type<T>::value, "Don't instantiate that!"); };
 
Needing a lazy false is annoying.
 
Xeo
@LucDanton Ha, I also have a fake_dependency template :D
Gah, nested aggregate initialization just doesn't seem to work
 
5:59 AM
Yeah. I wonder if it's GCC's fault, or if it's ok.
 
Xeo
MSVC also doesn't like it
 
:2365792 Nah, that will get asserted every time.
 
Xeo
And I just shut down my debian vbox, gimme a sec
 
Nevermind, I misunderstood the intent
 
Xeo
Nope, Clang doesn't like it either
 
6:01 AM
Well, double braces it is.
:(
 
Xeo
Even for this I get a warning with clang:
struct X{
    int _[3];
};

int main(){
    X x = { 1, 2, 3 };
}
t.cpp:6:13: warning: suggest braces around initialization of subobject
      [-Wmissing-braces]
    X x = { 1, 2, 3 };
            ^~~~~~~
            {      }
 
GCC is okay with that.
Does it work with std::array?
 
Xeo
nope, same warning
Add -Wmissing-braces to GCC
 
I mean std::array<int, 3> x = { 1, 2, 3 };.
@Xeo That enables the warning.
 
Xeo
Yeah, same warning
 
6:03 AM
Which is already enabled.
 
Xeo
I know. :P
But I wonder why it triggers
 
The worst is that it errors out with that too many initializers thing.
 
Xeo
yeah
Anyways, I'm off to sleep. I'll make some questions when I wake up again
@RMartinhoFernandes, try the double-initializer-list constructor I mentioned before, maybe that works. Or variadic ctor
1
A: Returning a Pointer to a Multidimensional Array

Benjamin Lindleyret is a pointer to pointer to float. When you dereference it, like this: (*ret), you get a pointer to float. When you take an index on that, like this: ( *ret )[ i ], that gives you a float. When you take an index on that, like this: ( *ret )[ i ][ j ], well, you're trying to index off of a f...

> Just remove the dereferencing of ret to fix that.
And it was still in until the edit xD
 
Done. I'm not spending any more time on this. ideone.com/Dudo1. Bring those 2d array questions!
 
7:04 AM
@RMartinhoFernandes :)
 
7:20 AM
@RMartinhoFernandes what is "so"?
 
StackOverflow.
 
oh. thanks.
slooow mind, needs coffee
^ Swedish luxury meatballs, called "wallenbergers". they have lots of cream and egg yolks.
 
@AlfPSteinbach salivate, salivate, salivate...
 
English luxury meatballs
 
7:27 AM
That looks like eggs inside chocolate.
 
A Cadbury Creme Egg is a brand of chocolate manufactured in the shape of an egg. The product consists of a thick milk chocolate shell, housing a white and yellow fondant filling which mimics the white and yolk of a real egg. Creme Eggs are the best-selling confectionery item between New Year's Day and Easter in the UK, with annual sales in excess of 200 million and a brand value of approximately £50 million. Creme Eggs are produced by Cadbury UK in the United Kingdom and by Cadbury Adams in Canada. They are sold by Kraft Foods in all markets except the USA, where The Hershey Company has t...
i thought it looked real
 
I do like chocolate, but I'm a bigger fan of meat.
 
7:56 AM
@RMartinhoFernandes After eating this u'll never want meat again:
Mansaf () is a traditional Jordanian dish made of lamb cooked in a sauce of fermented dried yogurt and served with rice or bulgur. It is the national dish of Jordan. Preparation The lamb is cooked in a broth made with a fermented then dried yogurt-like product called jameed, and served on a large platter with a layer of flatbread (markook or shrak) topped with rice and then meat, garnished with almonds and pine nuts, and then sauce poured over all. Cultural role Mansaf is the most distinctive Jordanian dish, and it's the national dish of Jordan, thus Mansaf on the menu is the greatest s...
^ I wonder why this is the pride of Jordan. I hate it.
 
@IntermediateHacker I don't see what's so bad about it.
 
@RMartinhoFernandes Most people like it. Including my mom. But I have always hated it.
In my opinion, meat shouldn't be sweet. It should be salty or spicy.
 
Oh, that tastes sweet?
 
yup. A weird mixture of sweet almonds / cashews and salty rice. weird.
 
I don't like sweet meat either :)
 
8:05 AM
[thumps up] :)
 
 
1 hour later…
9:18 AM
Every place on Earth has a weird dish.
 
sbi
9:49 AM
@Xeo If you put the baby phone right beside the door and put it at full volume, you'll stand in your bed when he passes by on bare feet.
@JerryCoffin I have taken to buy Lego mostly 2nd-hand. That makes it affordable to me.
And I never buy any Lego package to build one thing out of, only boxes and bags (usually by weight) of assorted bricks out of which can be built anything. Keep them on their toes!
@KerrekSB That is a perfect dupe of the operator overloading FAQ. It explains this very scenario.
 
10:17 AM
0
Q: Fisher Yates variation

FredOverflowThe classic Fisher Yates looks something like this: void shuffle1(std::vector<int>& vec) { int n = vec.size(); for (int i = n - 1; i > 0; --n) { std::swap(vec[i], vec[rand() % (i + 1)]); } } Yesterday, I implemented the iteration "backwards" by mistake: vo...

 
@FredOverflow lol, you didn't get the answer you wanted.
 
@RMartinhoFernandes Oh and John Skeet didn't see the error :)
 
Hehe.
@FredOverflow My very non-mathematical analysis tells me it's the same. But I still have doubts.
 
@RMartinhoFernandes I feel the same.
 
10:34 AM
Also, testing with rand() is not a good idea. That thing is not uniform on its own.
 
Yes I know, just mentally replace the rand() stuff with a good PRNG ;)
 
@FredOverflow Why is vec[0] not swapped?
 
@StackedCrooked It is.
Anytime the random number picked is 0.
 
@RMartinhoFernandes std::swap(vec[i], vec[rand() % (i + 1)]);
 
10:36 AM
Aha.
That's what I get when looking at code after just waking up.
 
What's that Mersenne Twister number code again?
19937 or something?
 
@FredOverflow It's actually a good question.
 
@StackedCrooked It isn't swapped again at the last step, because you could only swap it with itself, which would be pointless.
@StackedCrooked And what do we do when we see good questions on SO? ;) just kidding
 
@FredOverflow I already upvoted.
 
@RMartinhoFernandes yes, exactly
typedef see below mt19937;
 
10:41 AM
ideone.com/I7L3d I get 2.3336 as the average of the first element in 10000 runs.
Doesn't sound very uniform.
Oh wait.
ideone.com/puA2c I need the distribution to be uniform across the whole vector :S
4.5 sounds better.
In fact, it's more exact than I expected.
I was hoping for 45001 or something.
 
Is that test thorough enough?
 
No, I should test the other indices.
Scarily precise.
Now someone needs to run a χ^2 test or something to make sure those results are not due to pure luck.
 
you guys scare me
how can you keep remembering stuff like that
 
Stuff like what?
 
I prove it with induction but I dunno how to write proofs
 
10:51 AM
like chi squared
 
@RMartinhoFernandes Doesn't it require a seed? Or does mersenne not work that way?
 
@StackedCrooked I don't need the seed to change every time I run it.
 
@Pubby A little more English in your answer would make it less frightening ;)
 
@FredOverflow "shitty" is English.
 
@RMartinhoFernandes I'm not sure dist(engine) % (i+1) is such a good idea. Wouldn't this prefer the lower indexes?
 
10:54 AM
@FredOverflow Isn't it the same you have in your answer?
 
@RMartinhoFernandes rand() always yields the same range, but... oh wait, brainfart, I mixed up your old and new code, forget it :)
 
Also, I have data to show for it :P
Unless you want to claim that the default seed for an mt19937 produces these lucky results.
 
why not mt1337
 
@FredOverflow I gave an example which might clear things up
 
@RMartinhoFernandes No wait, I'm still not comfortable... dist(engine) yields a number between 0 and n - 1, right? Let's say n is 10, then you have a number between 0 and 9. Now if (i + 1) is 9, then the probability of 0 is twice as high as the probability of the other numbers.
 
10:58 AM
@AlfPSteinbach Because it has period 2^19937 - 1.
 
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?
 
@FredOverflow The same thing happens with rand().
The range of rand() is always the same.
@FredOverflow Good point.
 

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