k06a / boolinq

Simplest C++ header-only LINQ template library
MIT License
628 stars 79 forks source link

copy assgin #44

Open vanehu opened 4 years ago

vanehu commented 4 years ago

Hello! Every next call do a copy, how to pass a ref value?

Example:

struct test_t {
    std::string v1;
    int         v2;
};
constexpr std::size_t benchmarkVectorSize{ 1000000 };
std::vector<test_t> vecCpp(benchmarkVectorSize);

srand(0xDEADBEEF);

for (unsigned i = 0; i < benchmarkVectorSize; i++) {
    const auto x = rand();
    vecCpp[i].v2 = x;
    vecCpp[i].v1 = std::to_string(x);
}
boolinq::from(vecCpp).for_each([](test_t a) {
    a.v1;
    int iii = 02;
});

every for_each make object copy about 2 times how to aviod this, and how can i change value in for_each ops;

I want this work well:

boolinq::from(vecCpp).for_each([](test_t &a) {
    a.v1 = "123"
});
Gargony commented 3 years ago

@vanehu what about this?

for (auto & it : boolinq::from(vecCpp)) {
    it.v1 = "123";
}
k06a commented 2 years ago

I do not see any way to have non-const refs to items. This issue is related to this one: https://github.com/k06a/boolinq/issues/22