C++ LINQ-like iterator operations

后端 未结 8 971
执念已碎
执念已碎 2021-02-13 13:40

Having been tainted by Linq, I\'m reluctant to give it up. However, for some things I just need to use C++.

The real strength of linq as a linq-consumer (i.e. to me) li

8条回答
  •  名媛妹妹
    2021-02-13 14:03

    With Boost.Range and Linq in C++11, you can write Linq queries in a very similar way:

    std::vector numbers = { 1, 2, 3, 4 };
    auto r = LINQ(from(x, numbers) where(x > 2) select(x * x));
    for (auto x : r) printf("%i\n", x);
    

    Will output:

    9
    16
    

提交回复
热议问题