In your question noticed saying
In fact I don't necessarily need a new list, I just want to operate on
the subset of the list in subsequent code
Form C++17 one can use std::for_each_n
For example lets square the first N (4) numbers in the list.
Example 1 : Modify in place :
std::list<int> nums{ 1,2,3,4,5,6,7,8 };
//MAKE NOTE OF SENDING ARGUMENT AS A REFERENCE (int& num)
std::for_each_n(nums.begin(), 4, [](int& num) { num = num * num; });
//PRINT
for (auto n : nums)
std::cout << n << " ";
Example 2 : Modify and put them in a different list :
std::list<int> nums2{ 1,2,3,4,5,6,7,8 };
std::list<int> newNums;
//MAKE NOTE OF CAPTURE [&}, newNums EXPOSED INSIDE LAMBDA.
std::for_each_n(nums2.begin(), 4, [&](int num) {newNums.push_back(num * num); });
//PRINT
for (auto n : newNums)
std::cout << n << " ";
Also there is an overload available to specify execution policy, Need to include "execution" header. So the below code executes with parallel execution policy, useful for parallel processing lists huge in size.
std::for_each_n(std::execution::par,nums.begin(), 4, [](int& num) { num = num * num; });