0

I don't really understand Lambda expressions very well. I created a list that takes in a struct "brute";

typedef struct brute{
int entry;
string secWord;
string secHex;
}decrypt;

typedef list<brute*>Unsolved;

I then try to use the for_each to iterate through the list.

char combo[] = {'a','a','b','c');
std::for_each(unsolved.begin(), unsolved.end(),[&combo](int i )
{

});

[&combo} is what I'm trying to capture. I have 3 questions: is "int i" the iterator for the list? How do i access a member that is inside my unsolved list? Lastly do i need to define that my return value should be a char[]?

1 Answer 1

3

std::for_each will expect a unary predicate that takes brute* or brute*&, something of the form

T foo(brute*);

would do. It ignores the return value. So your for_each call using a lambda could have this form:

std::array<char, 4> combo{'a','a','b','c'};
std::for_each(unsolved.begin(), unsolved.end(),[&combo](brute*& b) { .... } );

where I have used an std::array because it has simpler copy/assignment semantics than a plain array.

So, to answer the questions,

is "int i" the iterator for the list?

No

How do i access a member that is inside my unsolved list?

As shown in the example

Lastly do i need to define that my return value should be a char[]?

The return value gets ignored. If you need it then you need another algorithm.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.