« first day (1466 days earlier)      last day (1393 days later) » 

10:13 AM
whats the difference between indexing and searching in this context?
(and yes i have googled indexing)
 
nwp
Indexing: "Give me the nth element"
Searching: "Give me the element with value n"
 
indexing is when you know the index and want to get the element
 
@ratchetfreak perfect
 
searching is when you know the element and want to access it in the data structure
 
surprisingly noone has said it as clearly on google search
 
nwp
11:08 AM
Is there some trick to get at the memory of a lambda?
I have something like this:
struct S {
    S() {
        QObject::connect(button, &QPushButton::connect, [this] { print(data); });
    }
    std::string data;
};
The problem with that is that the S which this points to may or may not exist by the time the lambda is called which is a problem. I can't just pass data by value because it changes throughout S's lifetime and the lambda needs to print the current data. I feel like the correct way to express this is to make it [content = data] () mutable { print(content); } and inside of S update lambda.content as necessary.
That way the lambda will always have the current data and if S goes out of scope that's fine. The problem is I don't know how to write lambda.content = "foobar"; in valid C++. Making it a std::shared_ptr feels like overkill.
 
11:23 AM
struct S {
    S() {
        std::unique_ptr<std::string> string = std::make_unique<std::string>();
        data = string.get();
        QObject::connect(button, &QPushButton::connect, [data = std::move(string)] { print(data); });
    }
    std::string *data;
};
@nwp ^ still an unneeded indirection though
though given that the lambda getting copied/moved around the indirection may be necessary
 
 
1 hour later…
nwp
12:34 PM
That sounds reasonable, thanks.
 

« first day (1466 days earlier)      last day (1393 days later) »