Ilia
Hmm I just made it up now
Anonymous
but if I could initilise non-existents with -1 then mp[102] would give me -1.
Mat
I mean suppose: std::map<int,int> mp; mp[102] will give me 0.
Not really. You can check the existence of the key before trying to access it and create the pair if needed
Anonymous
ya but i would need to use find() function and it would give me 0(N) complexity
Anonymous
is there any other way round?
Anonymous
how many time we can know about c++
Anonymous
make expert in c++
Mat
ya but i would need to use find() function and it would give me 0(N) complexity
http://www.cplusplus.com/reference/map/map/operator[]/
Mat
how many time we can know about c++
I think you used time in the wrong way
Anonymous
http://www.cplusplus.com/reference/map/map/operator[]/
does that have what i want? In the first look, didn't seemed like that.
Anonymous
the user-defined initialisation part.
Mat
does that have what i want? In the first look, didn't seemed like that.
If k does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value. Notice that this always increases the container size by one, even if no mapped value is assigned to the element (the element is constructed using its default constructor).
Anonymous
thanks mat p for advice
Anonymous
yes I learnt that
Anonymous
In fact operator[] probably does more than you expect as if a value does not exist for the given key in the map it will insert a new one with the value from the default constructor.
Mat
If you want to construct a personalized elem every time, you'll have to use find i believe
Anonymous
in an SO answer.
Anonymous
Have a look
Anonymous
So, No way other that using the find() function?
Mat
So, No way other that using the find() function?
Yuo can use operator[] to create the default object, then modify it w/ what you need
Anonymous
kindly put the link. I am a noob for that.
Anonymous
😟
Mat
Just access the value once, find out if it's the default one someway and modify it if needed
Anonymous
but if for some value I have explicitely assigned it to the default value, then what should I do to check that. std::map<int,int> mp; mp[102] = 0; In this case, I've already assigned it with the default value. How do I check that?
Ludovic 'Archivist'
but if for some value I have explicitely assigned it to the default value, then what should I do to check that. std::map<int,int> mp; mp[102] = 0; In this case, I've already assigned it with the default value. How do I check that?
I tried to solve that in an implementation of mine by having operator[] return a type that decays to a reference to the value, returning it if present as an optional. Did not work out, changed that all to a get(key, default) and try_get(key) -> optional model
Ludovic 'Archivist'
std::map is not so great if a default value can break stuff
Ludovic 'Archivist'
Any previous implementation of yours present online would help!!
Like I said, it didn't quite work out. Also my implementation was of the unordered_map and not the ordered if that is fine
Anonymous
Oh!!
Jian Yang
I've posted my first tech blog post about TREE DS, where you guys think i can share it with in telegram for people to read and give feedback if they want to?
Jian Yang
Dont mind if im asking fot too much
Jian Yang
For*
Jian Yang
Not here 🤔 idk, try the other programming groups
Thanks man for replying back. Any idea about outside telegram except twitter?
Jian Yang
Facebook&co
Nah, not using that for a very long time. Anyway thanks for your time
Jian Yang
Reddit maybe?
Sounds good, will try that bud
Jian Yang
Anonymous
Done!
Mat
Done!
Cool ✌️
Mat
Wow, that was amazing
Rostin
Did anyone just delete some pics?
Anonymous
Guys am meeting struggles with c language
Anonymous
Don't meta-ask
Okay anyone with a complete guide from beginner to advanced ?
Anonymous
No
Okay bro thanks
Sid Sun
F
Hermann
i stady algorithm and data structure...but i dont idea for do a my project :S...anyone help me?
Anonymous
i stady algorithm and data structure...but i dont idea for do a my project :S...anyone help me?
There is no project on your level of knoweledge with data structures
Hermann
There is no project on your level of knoweledge with data structures
What do I need to study algorithms and data structures if I have no ideas on how to make a project?
Anonymous
Hermann
i thinking implement dinic's algorithm for example... but i dont know
Hermann
First study it
I read the algorithm, but as a project it seems a trivial and not original.
Anonymous
Is there any online c ide that supports file handling?
Anonymous
Hi everybody. Got this joining link from a website (which I currently can't recall). Anyway, I had a weird problem, that I'm not quite understanding. Also, I'm still learning, so this issue might seem noob-ish. When I declare a character array, and get input into the array through the following, char c[1000]; for(int i=0; i<1000 && (c[i]=getchar())!='\n'; ++i); When printing this array as a string, for a certain length, the string seems to be fine, but for others, weird characters get printed. Also unwanted newlines. I'm really not understanding what's happening here
klimi
Then you say print it all
klimi
Which means.... Print what user inputed... And all of that memory that's left
klimi
There are garbage values so that's why you get weird characters and new lines and who knows what
Anonymous
Okay. Thanks. Now I'm going to look into buffers in detail. Thanks 😁
Anonymous
Hello
Anonymous
Hello
Nohello.com
Anonymous
hey
Anonymous
can anyone help me .. i have problem with java code
Anonymous
i cannot corrected the error
Anonymous
it is for my classwork
Anonymous
i cannot find any java group
Mat
You can try OT 🤷‍♂
Dima
#ot