« first day (732 days earlier)      last day (2345 days later) » 

03:07
https://stackoverflow.com/questions/13061979/shared-ptr-to-an-array-should-it-be-used

Does this mean that I use shared_ptr to manage dynamic array directly just like unique_ptr with C++11? shared_ptr<int[]> p1(new int[10]);

1.No need to supply a custom deleter any more.
2.Can access array elements using [] operator.
03:26
@Rick More or less, yeah. Shared ownership is pretty rare though--99+% of the time that you might consider this, you'll be better off with vector.
I see. Thank you sir.
03:40
@Rick ...and don't call me sir. I work for a living! :-)
;D
I wanna ask a dumb question.

Example code from this page:en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr, I see

    std::shared_ptr<Foo> sh5(new Foo, [](auto p) {
           std::cout << "Call delete from lambda...\n";
           delete p;
        });
I was wondering where does the `auto p` comes from and couldn't find a clue from the page. But later on I checked on http://www.cplusplus.com/reference/memory/shared_ptr/shared_ptr/, it's clear by saying:


Deleter object to be used to release the owned object.
This shall be a callable object taking a pointer to T as argument for its functional call (where T is shared_ptr's template parameter).
Did I miss something from cppreference or it just simply not mention that on the page?
Sorry if I do not format the message well. I sent them out by mistake before formatting them well.
03:58
Note the documentation on overloads 4-5
It says there: "Uses the specified deleter d as the deleter. The expression d(ptr) must be well formed, have well-defined behavior and not throw any exceptions. The construction of d and of the stored deleter from d must not throw exceptions."
Yes. I've seen that
"The expression d(ptr) must be well formed, have well-defined behavior and not throw any exceptions."
It says exactly the same stuff as the cplusplus.com, although it doesn't say that the intent of the deleter is to release the owned object
I think it's heavily implied
Oh it says it lower down under Parameters: "d - a deleter to use to destroy the object"
All the same information is there, but it might be harder to understand
Yes, I also saw that too.
So, where does the p parameter of the lambda come from? If you piece these pieces of information together, the lambda is the deleter, and it is called like d(ptr), so the p parameter of the lambda is the ptr being managed by the shared_ptr
True. But in fact it's sometimes not straightforward like cplusplus.com. I mean, as you said, "piece the information", "heavily implied".
04:07
Yeah, cppreference has a higher barrier to entry. It's excellent if you already somewhat know the material, but it takes quite a bit of work if you don't.
It also has a certain way of phrasing things that's perfectly clear once you get used to it, and somewhat confusing before then
Indeed. There's a highly voted post is talking bad of cplusplus.com. So mainly I forcedmyself to read cppreference. But sometimes it just not as friendly as cplusplus.com for exmaple like this. So most of times I am checking between these two sites.
Thank you for your patience :D
 
8 hours later…
12:07
Hi everyone. Maybe someone can help me.
I asked a question two days ago who was marked as duplicate but I don't think the link to the already answered question answers to my question.
There are two options : I don't understand the already existing answers or my question have not to be a duplicate.
What do you think about that?
Here is my question : https://stackoverflow.com/questions/51289782/how-a-callback-function-can-modify-an-object-member
Thanks!
Hi everyone. Maybe someone can help me.
I asked a question two days ago who was marked as duplicate but I don't think the link to the already answered question answers to my question.
There are two options : I don't understand the already existing answers or my question have not to be a duplicate.
What do you think about that?
Here is my question : https://stackoverflow.com/questions/51289782/how-a-callback-function-can-modify-an-object-member
Thanks!
it there a way in the external API to get a context pointer in the callback?
something like void* userdata in the parameter list of the callback or a function to get it from the api
No, not with this function.
then you will be forced to use a global for it
with all the implications of it
That's bad because it's a multithread application.
which api is it (if you can say)
those context pointers sometimes get hidden
12:20
It's a private API of my company used by multiple applications we develop.
create an issue saying that you need a context pointer in that place
I will.
But we agree to say it's impossible to do what I want without modify the signature of the function (unless if I use globals)?
Ok. Thanks you!
 
1 hour later…
13:37
1 message moved from Lounge<C++>
@Pierre They're trying to tell you that your example could look something vaguely like this: wandbox.org/permlink/2osPpO4HNIIPH3o8
Hi everyone,
Can anyone recommend me a tool to visualise which functions are defined / declared in what C / C++ / CUDA files? Don't need to see program flow or anything, just where the definitions live, to help in refactoring some code with gross duplication/overlap.
(I've also asked this in the C lounge, I hope that's allowed)
nwp
nwp
13:53
Compile the files and dump symbols? It doesn't work on static identifiers, but maybe it's a start.
I've been playing with nm, but thought it'd be better to find an existing tool than make the probably millionth script to do this :P
I do use Doxygen to generate doc, just can't quite figure how to get it to display what I want
What about ctags? It's a code indexer. It creates an index which declaration lives in which file (and i think it can also track definitions). It's stone old, but there are still modern maintained versions (universal ctags)
Sam
Sam
In my application, i've made a few ofstream objects to log variables values to an output at various times.. The amount of data I want to output to files is growing and therefore making the number of logger objects at a given time grow. Is there some time of alternative to log to individual files without having to create now objects each time? I suppose I'm going to have to have some sought of unique object for each file...
I'll give that a look, thanks!
nwp
nwp
14:10
@Sam You could use __FILE__ to decide which logger instance / log file you use.
Sam
Sam
hmmm, let me look at this
14:55
@JerryCoffin I totally understand that. My point is I can't change the signature of Transfert so this answer doesn't fix to my problem.
@Pierre If you can't change its signature, then it can't invoke a member function.
That's the same conclusion we got to with @ratchetfreak.
15:29
@Pierre So, if you really insist on doing this, you could invoke the member function indirectly through a free function. You'd have to do something on the order of setting up the pointer to the member function, and a pointer to the correct object instance as globals, then pass the address of that free function to your transfert. That may not be the worst idea ever, but I'd work pretty hard to avoid it.
15:42
@JerryCoffin I prefer to not use globals in this case because if there are two (or more) threads who want to use the Transfert function at the same time, one of them has to wait the complete file tranfer of the other one before it can use the globals.

« first day (732 days earlier)      last day (2345 days later) »