« first day (1245 days earlier)      last day (1604 days later) » 

1:42 PM
What does "invalidate iterators, references or pointers" exactly mean on the context of those container operations?
 
@Rick it means that using them after they are invalidated is UB
 
Does it mean:
1. the iterators, references or pointers now points to junk, deleted, memory block

or

2. the iterators, references or pointers are pointing to the same address, but the values are changed?
 
@Rick could be either, it's not defined
 
God. That makes me so confused
 
@Rick why? just don't use them after invalidation
it's only an issue if you cache iterators
 
1:47 PM
"invalidate", logically invalid or language level invalid.
 
@Rick no longer valid for use, you need to get new ones from the container
 
Let me check the answer again
 
if you're not caching iterators it's not an issue
 
> deque: An insertion in the middle of the deque invalidates all the iterators and references to elements of the deque.
Why ?
Doesn't it only invalid the section where insertion ocurr?
My understanding of how deque is implmented is based on this answer stackoverflow.com/questions/6438086/iterator-invalidation-rules
Sorry, the link should be stackoverflow.com/a/6292437/5983841
Never mind, I gave up on this annoying part.
 
2:16 PM
@Rick no because elements may have to be moved
moreover that implementation is not guaranteed
 
2:46 PM
int i = nums.size() - 1, k = i;
    while (i > 0 && nums[i-1] >= nums[i])
        i--;
how does this decrementing work? because the while loop would work by counting upwards?
 
@Permian uh, no it's counting down.. it's starting at the proverbial back of the array and working to the 'front'
 
@Mgetz how do you know the while loop while decrement?
how do you know in what direction it will work?
 
@Permian i--; and the way it's indexing
 
what do you mean by the way its indexing?
 
that said I think there is UB in that loop
 
2:55 PM
UB?
 
undefined behavior, I'm pretty sure (albeit waking up) that the loop is actually indexing out of bounds at the start
 
it tests ok in leetcode
 
well in C++ arrays are zero index
ah no I'm reading it wrong
 
3:29 PM
@Permian well, this obviously starts from the last index and works down to 1. There is no UB here. And it simply checks if each element is greater than its predessor ie it is in descending order.
Now, if(i == 0) std::cout << "Sorted!";
 
 
1 hour later…
4:40 PM
Not C++ related, but c++ peeps are my favourite so imma ask here .
Is it possible to print out all the different numbers entered one by one without using arrays?
with arrays I mean all the STL stuff as well
I was thinking some clever use of recursion ?
if its possible by all means
 
Of course!
I suppose you are entering numbers until a sentinel value is entered?
Or maybe (ch != 'y' && ch != 'Y')?
 
sure yeah
actually you can fix the number of inputs to 5
or 10
doesn't really matter
 
And what will you do with the numbers?
Just display them?
 
yea just display all the different numbers
so if u enter 2 3 4 2 5
 
In order?
 
4:49 PM
it should print 2 3 4 5
no particular order matters
 
Oh, you are removing duplicates?
 
yeah
 
Lemme see...
 
seems like a tough job to me ( if it is possible at all hah)
good luck
 
lol.
Well, if you consider it, recursion is using a stack.
I suppose you could append it to a string.
Do you just not want to use an array, in which case I'll use something else. grins
 
5:00 PM
hahaha
no strings no arrays no stl
whats happening in the memory ; I don't really care
 
My own stack? ** bambi eyes **
 
hahaha you are only clever boy
one*
still the answer is no
imagine this
you are beginner in c++ and you only know integers , loops , basic keywords , functions and recursions
you've never heard of structures and classes
nor vectors, sets etc.
nor arrays
 
If there are 5 inputs, I can have 5 variables. ;-)
 
sure
I also said 10 is a possibility
so just for fun then, you don't know the number of inputs as well :D
 
5:08 PM
but hey, if it helps, the number of inputs is finite
 
I'll keep prodding away. ;-)
 
I could see that coming
you will eventually have to accept your fate
 
Well, I suppose I could sort them in-memory.
Then pick the first from each sub-range.
 
how would the sorting look like ?
And I highly doubt that our imaginary c++ beginner would know such thing also
 
Pretty much this:
Input = 2 3 2 3 5
Start recursion:
input 2.
select 2, compare to 3.
In order.
select 3, compare to 2.
std::cin.push_back(3);
 
5:17 PM
yeah but How would you code that I wonder ?
cin.push_back is a thing ?
 
It's almost night here. I'll get back to you recharged! Muahahaha!
Yes. Try it out. ;-)
 
Hahaha ok , sleep well
 
Sorry, its std::cin.putback(3 -> char);
push_back is a vector hangover.
 
5:45 PM
hey guys, used1[9][9] = {0}, is this a 9x9 array all 0s?
 
5:56 PM
int num = board[i][j] - '0' - 1, k = i / 3 * 3 + j / 3;
what does the '0' do?
 
the '0' is just to offset by the ASCII value for 0
 
word it doesnt seem to be in the leetcode problem
 
people commonly use it to do a fast conversion between user-input to digits when they can know that the input is all digits
 
@PeterT actually im not sure what this means
 
when you get user input it most of the time starts out as char* and then gets converted
when the user inputs a 0 you don't get the int value for 0, but the ASCII '0'
 
6:08 PM
hmm doesnt seem relevant
 
this is simplified of course, nowadays we have wchar and all kinds of non-ASCII encodings
 
leetcode.com/problems/valid-sudoku you can see the input here
 
yeah the input is strings
not integers
 
so what is board[i][j] - '0' for "."?
 
int a = (int)'0'; std::cout << a; will print 48
presumably you what it to be 0
oh, you meant for the character '.'? I guess probably -2
but you probably shouldn't use it for that
 
 
3 hours later…
9:12 PM
Hey guys, I'm doing a C++ course and one (of the many) questions we should answer this week is: 'when using placement new, or in the context of unrestricted unions, explicit destructor calls are encountered. Explain why code using such explicit destructor calls for objects of a class Derived, which was derived from Base doesn't have to call explicitly the Bases class's destructor.

I have been thinking/googling about this for quite a while but I'm unsure how to proceed. Could someone hint me in the right direction or link any related articles/questions I should read?
 
is "Because the derived destructor automatically calls the base destructor" all the're looking for?
https://en.cppreference.com/w/cpp/language/destructor

> For both user-defined or implicitly-defined destructors, after the body of the destructor is executed, the compiler calls the destructors for all non-static non-variant members of the class, in reverse order of declaration, then it calls the destructors of all direct non-virtual base classes in reverse order of construction (which in turn call the destructors of their members and their base classes, etc), and then, if this object is of most-derived class, it calls the destructors of all virtual bases.
 
So but why would this be special for unrestricted unions/placement new? The first part of the question (no posted) already asked me to explain why the destructors are called in reversed order (of construction) so there must be something else?
 
The only special thing about it is that it's common to explicitly call the destructors in that case
otherwise I don't get what would be special about that case
Which is why they presumably grouped together placement-new and unions
those two are not otherwise related
 
Ok thanks, and could you tell me why it is common to explicitly call the destructor in these two cases?
 
well, not to be reductive but, because it doesn't get called automatically by the compiler
in the case of placement new because allocation/deallocation and contruction/destruction are decoupled and in the case of unions because the compiler doesn't know the type
 
9:27 PM
Ah ok thank you very much, makes sense now.. must be what they're aiming for, I was kinda searching for something more 'extreme'..
 
well I'm not completely sure about the unrestricted union reason, it might just be used when switching the type it contains, instead of at destruction time. Never used them much
 

« first day (1245 days earlier)      last day (1604 days later) »