Skip to main content
deleted 32 characters in body
Source Link
Yuushi
  • 11k
  • 2
  • 30
  • 66

You can utilize std::transform here (I'll assume C++11 for the lambda):

int main()
{
    std::vector<uint8_t> first_list = {0x01, 0x10, 0x32, 0x1A};
    std::vector<uint8_t> second; 
    std::transform(first_list.begin(), first_list.end(), std::back_inserter(second),
                   [](uint8_t u) { return ~u; });
    for(uint8_t it : second) {}

}

You also don't need to make a copy of the first vector to do this; better to simply use push_back (or back_inserter here, since we're working with iterators).

You can utilize std::transform here (I'll assume C++11 for the lambda):

int main()
{
    std::vector<uint8_t> first_list = {0x01, 0x10, 0x32, 0x1A};
    std::vector<uint8_t> second; 
    std::transform(first_list.begin(), first_list.end(), std::back_inserter(second),
                   [](uint8_t u) { return ~u; });
    for(uint8_t it : second) {

}

You also don't need to make a copy of the first vector to do this; better to simply use push_back (or back_inserter here, since we're working with iterators).

You can utilize std::transform here (I'll assume C++11 for the lambda):

int main()
{
    std::vector<uint8_t> first_list = {0x01, 0x10, 0x32, 0x1A};
    std::vector<uint8_t> second; 
    std::transform(first_list.begin(), first_list.end(), std::back_inserter(second),
                   [](uint8_t u) { return ~u; });
}

You also don't need to make a copy of the first vector to do this; better to simply use push_back (or back_inserter here, since we're working with iterators).

Source Link
Yuushi
  • 11k
  • 2
  • 30
  • 66

You can utilize std::transform here (I'll assume C++11 for the lambda):

int main()
{
    std::vector<uint8_t> first_list = {0x01, 0x10, 0x32, 0x1A};
    std::vector<uint8_t> second; 
    std::transform(first_list.begin(), first_list.end(), std::back_inserter(second),
                   [](uint8_t u) { return ~u; });
    for(uint8_t it : second) {

}

You also don't need to make a copy of the first vector to do this; better to simply use push_back (or back_inserter here, since we're working with iterators).