« first day    last day (698 days later) » 

3:25 AM
Guys. can anyone tell me how to compare the current element of a vector to the next element of the said vector
 
 
3 hours later…
6:52 AM
@JoelSeah sure. Just tell me what "current" element means to you. I would probably do that with a zip iterator that's set off by 1.
Something like for (auto cmp : zip(v, v | skip(1))
 
 
2 hours later…
8:42 AM
Hello :)
 
@TorbenC hi :)
 
9:34 AM
@JoelSeah Did you start with an index, or an iterator?
You can do it messily by copying it, incrementing the copy, checking the copy against .end(), and then dereferencing it and comparing....
....or you can be clever with Barket's zip magic
 
 
3 hours later…
12:43 PM
i like the idea of this chatroom, good luck :]
 
2:32 PM
im using iterator
 
G'day.
4
Q: Most vexing parse and pointer indirection/dereferencing

iammilindMinimal code: struct A { A(int = 0) {} }; int i = 0, *p = &i; int* foo () { return p; } int main () { A(); // calls `A::A(int=0)` A(i); // calls `A::A(int=0)` A(*p); // <--- (1) same as local `A *p;` { A((*p)); // <--- (2) same as local `A *p;` } A (*foo()); // <--- (3) ...

If anyone's interested, theyre kindly invited to explain better than I did (If i'm correct in the first place).
 
 
1 hour later…
3:39 PM
@jrok Hmm I might give it a go
No, wait, I can't. You already did the best I ever could :P
 
 
1 hour later…
4:44 PM
@JoelSeah then I guess my zip solution is the cleanest one, though you obviously have to understand how does that work; concept isn't that hard
@LightnessRacesinOrbit you know, it's not really that hard.
 
@BartekBanachewicz It could be called unnecessarily complex
 
@LightnessRacesinOrbit complex? It's a one-liner
 
@BartekBanachewicz Short != simple
@BartekBanachewicz Long != complex
 
I think the idea is simple. You need to compare each pair of consecutive elements, so you provide two ranges that generate them and then compare
 
The idea is simple - the line of code is not self-explanatory, however. Not really.
And what happens on the last iteration? Presumably you still need a comparison to .end()
 
4:47 PM
no
zip iterator has to be chosen/constructed to handle ranges of non-equal length
 
Okay, so the zip iterator produces a new range, and automatically manages the fact that the length will be different from that of the original range.
 
This is not at all clear from for (auto cmp : zip(v, v | skip(1))
 
if it wouldn't, this would crash obviously
 
With just one or two extra lines, you can get the same magic, but with self-explanatory code.
 
4:49 PM
um, and what would those lines do?
 
7 hours ago, by Lightness Races in Orbit
You can do it messily by copying it, incrementing the copy, checking the copy against .end(), and then dereferencing it and comparing....
 
> messily
IIRC the default behaviour of zip in all reasonable languages will handle non-equal-length
the only thing I would change is skip(1)
I've did a bit of research and it appears that skip is usually used as (skip)every_nth_element, more or less
 
Yes, that too
 
so offset or next or something like that, but it's only a naming isse
we can ask @Xeo
 
So what is it in the standard?
 
5:01 PM
@LightnessRacesinOrbit standard has no true range operations in C++11
@LightnessRacesinOrbit but obviously, zip is perfectly implementable. So is our offset.
you can make them reusable and store in some utils.hpp
 
OK, so your solution is in fact "one line plus several new type definitions"
17 mins ago, by Bartek Banachewicz
@LightnessRacesinOrbit complex? It's a one-liner
 
but they are not specific to this solution.
 
My solution is two lines of pure C++
All I'm saying is that that is (a) more intuitive, and (b) less complex.
 
write it then.
@LightnessRacesinOrbit it's not, if you understand at least the basics of functional programming and ranges / range composition.
which I think you should when coding C++
 
I already explained how skip is not intuitive here. You even agreed with it.
 
5:04 PM
I also said it's merely a naming issue
 
But the point is that your line of code is obviously more terse and less self-documenting.
"merely a naming issue"
The way we arrange characters in a program is what we are talking about!!
 
for (auto elem_pair : zip(v, v | offset(1))) {
    if (elem_pair.first != elem_pair.second)
      //
}
 
It's better, but it's still a lot more terse than simple iterator arithmetic.
I'm not saying I wouldn't use it
 
I don't see why you really insist on using iterators.
 
I'd write documenting comments, though.
@BartekBanachewicz Um, I don't. I never claimed to.
 
5:07 PM
@LightnessRacesinOrbit okay.
 
> Linux is easily portable to most general-purpose 32- or 64-bit architectures as long as they have a paged memory management unit (PMMU) and a port of the GNU C compiler (gcc) (part of The GNU Compiler Collection, GCC).
^ what?
 
@BartekBanachewicz :P
@ShuklaSannidhya whatwhat
 
@ShuklaSannidhya what what?
lol h5
 
How come a compiler builds an OS when the compiler itself runs on top of an OS?
 
@LightnessRacesinOrbit a few months ago I wouldn't even think of something like that, but all this haskell in Lounge made an impact on me.
@ShuklaSannidhya it builds it running on another OS.
 
5:09 PM
@BartekBanachewicz And how was that OS built ?
 
@ShuklaSannidhya running on yet another OS.
or previous version of the current OS being built (which pretty much is the same in this context)
the complexity of OSes grew over time
 
Do you think this room will be able to compete with C# in not binning things?
 
first were really trivial and written in machine code, and it all went up from there.
@JohanLarsson I am.. We are not going to compete with anyone, really.
 
@BartekBanachewicz nice answer to my silly question!
 
5:11 PM
@ShuklaSannidhya the first compiler was written in machine code and now compilers compile themselves hehe
 
written by a woman right?
 
@BartekBanachewicz Horrid!
@JohanLarsson No competition required
 
@JohanLarsson I am not sure. I bet first computer was created as a mathematical concept.
the fact of physical programming act is pretty much irrelevant, at least for me.
 
I think Grace Hopper is famous for it but I don't know much history.
 
@LightnessRacesinOrbit lern yourself a haskell too :) Or Terra, for that matter.
@JohanLarsson impressive
hm, back to Terra
 
5:15 PM
does C++ have any sort of std::next_combination(first_in, last_in, first_out, last_out)? en.wikipedia.org/wiki/Combination
 
I was supposed to write to mailing list
@MooingDuck there's next_permutation, and with carefully crafted rules for that I think it's possible
you just need to provide appropriate input to it.
 
4
Q: Generating combinations in c++

Keneth AdrianI have been searching a source code for generating combination using c++. I found some advanced codes for this but that is good for only specific number predefined data. Can anyone give me some hints, or perhaps, some idea to generate combination. As an example, suppose the set S = { 1, 2, 3, ......

 
@BartekBanachewicz I can't think of an easy way to write next_combination, even using next_permutation.
 
@MooingDuck well we would probably need a bit of thinking for that, but it's interesting, let's try
 
5:17 PM
@BartekBanachewicz it's already done :|
 
@EiyrioüvonKauyf well or that
@MooingDuck yeah the link @Eiyrioü pasted is legit
 
@BartekBanachewicz yeah, it was a confusing strategy, but now I see how it works. It needs state though, so it can't be a standard algorithm.
 
@MooingDuck it can; you can just pass a vector well yeah you would get an iterator back; so yes state unless you want a vector of vector :|
 
well, unless you had a combination_state object you passed to it for state, but that seems... un-C++-like
 
5:40 PM
@EiyrioüvonKauyf not in the std
@EiyrioüvonKauyf or have I seen it as a reusable generic component
@BartekBanachewicz like.... this
well, quasi. It does require the "source" elements to remain unchanged for the duration.
it also requires them to be copy constructable.
oh hey this isn't the lounge
 
easy enough to wrap it in a structure that makes a makes a backup copy of the source elements if you need it
 
It is Friday after all
@ShuklaSannidhya :)
 
5:57 PM
@MooingDuck :)
 
6:45 PM
@MooingDuck :| close enough
 

« first day    last day (698 days later) »