Is it possible to get functionality similar to .NET LINQ in C ++?

Is it possible to get functionality similar to .NET LINQ in C ++? Will it require an extension of the language, or can it be done using some very smart macros? Or even with a tool like Qt moc (meta object compiler)? Are there existing LINQ implementations for C ++, and if so, what are they?

+3
source share
3 answers

Check out CLinq ( here and here ) or Linq ++ ( here ). Also try p-stade ( here ); however, it uses STL and does not have the same interface as LINQ, but it is quite complete.

+6

Linq ++ 11, linq- :

std::vector<int> 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);

from, where select Boost. :

auto r = numbers 
        | boost::adaptors::filtered([](int x) { return x > 2; }) 
        | boost::adaptors::transformed([](int x) { return x * x; });
+2

, .NET LINQ ++? , , ?

++ , - , LINQ.

LINQ- , :

  • DSL.
  • -

DSL ++ (, Boost.Spirit, DSL- , Haskell). boost::phoenix. ++ ( F++, ). - ++ .

- - LINQ- ++ , , LINQ .NET. , , .:)

, Qt moc ( )?

. ++, ?;)

Are there any existing LINQ implementations for C ++, and if so, what are they?

Several attempts have been made in this direction (as another gentleman pointed out here). None of them come close to the “real” LINQ, but they are still worth a look at it. :)

EDIT:
Apparently, I made a mistake in the “practical” bit. Look at the p-stade link in Yasin's answer, which is a great example of what can be achieved through clever use of powerful C ++ abstractions. :-)

+1
source

Source: https://habr.com/ru/post/1764312/


All Articles