Anonymous
This is straight up gaslighting
Anonymous
:/ the second paragraph is still wrong. Output iterators have nothing to do with streams and operator<< (other than std::ostream_iterator being an output iterator, but that still is about assignment, not <<) Forward iterators are still not output iterators by default, as seen from the godbolt example. the const iterator was a forward iterator, but since assignment was invalid to the dereferenced vector, it was not an output iterator. the normal iterator was both a forward and an output iterator. I intentionally chose std::vector<std::vector<int>> because then operator<< won't exist for sure.
Andrew
anyone know open gl?
Anonymous
I did not even mention tags Support ≠ guarantee. Guarantee is only available when the forward iterator is also an output iterator (forward iterator + output iterator == mutable forward iterator). This guarantee is what my initial question was and what I was talking about repeatedly. I never changed that. You didn't address the stream and << parts
Anonymous
Yes that was my mistake.
Anonymous
Forward iterator is not much more (i assume by "much more" you mean superset) than output iterator. It's different. Since not all forward iterators are output iterators.
Anonymous
That is agreeable
Anonymous
*x = value; should work for some forward iterator x
I did provide this and others where it was clear i wanted to assign to *x
Anonymous
Well
Anonymous
------o------ I hope everyone's popcorn is finished by now
Anonymous
I get that when someone says anything other than an input iterator, mutability is often assumed. I was talking about std::output_iterator specifically because i did not want to make the assumption and joining the std::output_iterator concept provided the guarantee without the need to make the assumption.
Anonymous
But i know how to do that with type traits already. I specifically wanted the concepts
Anonymous
So asked that
Ahmed
Guys i have a question When i am writing a code in c++ Should i right at the top of my code Using namespace std? Many people just write std::cout every time in things like that instead
Dima
write std:: explicitly
Dima
Duplicates may occur
Ahmed
Okay but i am using simple programs can u specify what does duplicates mean because i have read about this topic and i donot get what they mean with duplicate
vinícius*
but not on header files, as the namespace use propagates
vinícius*
a slightly better option is to use using std:: vector and so on
Ahmed
Okay i got it. Thanks
Ishikawa
Could someone kindly tell me why string and int variables stored in 24 and 4 bits respectively? I'm fairly new to programming.
Ishikawa
*variables are stored in
Ishikawa
Also *bytes, not bits
Lakshmanan
Hi
Ammar
Could someone kindly tell me why string and int variables stored in 24 and 4 bits respectively? I'm fairly new to programming.
std::string is not a primitive data type. It is a class, like a struct. A class can contain properties. The size of it depends on its properties. Why is int 4 bytes, because it is 32 bit integer, meaning it requires 4 bytes to store the value. Some aliases you need to know: char = int8_t is 8 bit integer, so it is 1 byte. short = int16_t is 16 bit integer, so it is 2 bytes. int = int32_t is 32 bit integer, so it is 4 bytes.
Ammar
lil correction: char is uint8_t
uint8_t is unsigned char actually.
Ishikawa
Yeah binary. But won't one character be stored in one byte regardless of what it is.
Vlad
lil correction: char is uint8_t
char signess is implementation defined
Vlad
Same deal as 100 vs one hundred sticks to represent the number
Ishikawa
Ishikawa
Ammar
Yeah binary. But won't one character be stored in one byte regardless of what it is.
1 character is indeed stored in one byte. But this: int x = 1000; Does not mean the memory stores 4 chars that contain '1', '0', '0', '0'.
Ishikawa
How can 10000 be stored between 548825435840 and 548825435844 ? (Five bytes in 4 bytes' memory) ?
Vlad
How can 10000 be stored between 548825435840 and 548825435844 ? (Five bytes in 4 bytes' memory) ?
It is not '1','0', '0', '0', '0'
Ishikawa
It is not '1','0', '0', '0', '0'
Yeah, I understand it is not binary 1 0 0 0 0, buy either way it each of them should take 1 byte, 5 bytes in total isn't it. Take 20000 otherwise.
Ammar
How can 10000 be stored between 548825435840 and 548825435844 ? (Five bytes in 4 bytes' memory) ?
int x =10000; in binary representation is 00000000000000000010011100010000 It takes 32 bits (count the binary digits, leading zero may not be written, but it is still stored in memory). That means in your physical memory (RAM) stores 00000000000000000010011100010000 at some location. 32 bits is 4 bytes. That is why integer 4 bytes.
Vlad
And oddly enough integer which is 32 bits can store 2^32 different states
Ammar
@Ishikawa I think you should learn computer organization and architecture first. It is the fundamental of your above question.
Ishikawa
Ammar
No no no, it assumes "10000" as chars, not integer.
Ishikawa
Please explain a lil bit more
Vlad
Even more so it fits in just two bytes
Vlad
Please explain a lil bit more
Think about 2 based positioned number system.
Vlad
Where each bit is 2 to the power of the bit's order
Ammar
Your converter works like this: Convert '1' to ASCII number, convert the number to binary. Convert '0' to ASCII number, convert the number to binary. Convert '0' to ASCII number, convert the number to binary. Convert '0' to ASCII number, convert the number to binary. Convert '0' to ASCII number, convert the number to binary. Char is 8 bit, that is why you get 40 bits.
Vlad
0b1101 = 1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 = 8 + 4 + 0 + 1 = 13
Ammar
Search for "Number Base Conversion" on YouTube and watch it.
Ishikawa
I know that conversion. I just could not thik that way and converted each byte separately. Thank you very much kind people.
Ishikawa
But again, how do string variables store more than 24 characters?
Ammar
But again, how do string variables store more than 24 characters?
std::string is a class, it has dynamic allocator that allows you to store chars dynamically. For example: std::string x; x = "Hello World"; Internally, x holds a pointer to the heap (this is where the "Hello World" stored). When there is a read/write operation to the string value, it uses the pointer to read/write the value.
Ammar
It actually has a complex way to do that internally. That is just a simple illustration.
Ammar
std::string x; x = "Hello World"; In this case, sizeof(x) is only the size of the class. Not the length of the string stored.
Ishikawa
Got it. Thanks again. 😁😁
Ammar
typedef basic_string<char> string; So string is an alias for basic_string<char>.
Ammar
This is how basic_string class implemented https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/basic_string.h
Raj
Anyone solve this please
Ammar
Anyone solve this please
Does that even compile?
Raj
No it will not compile but tell me the logic
User404
@ammarfaizi2 Ah, I see, you are a man of culture as well.