4

Given C++ gained lambdas with C++11, will there be any LINQ like higher order function library officially supported later? Or is there already such a library used in production quality code?

Obviously I'm not expecting the SQL-like expression tree based LINQ query syntax in C++. I am talking about the lambda based one. So, no new language feature in needed in C++'11, just a library will do.

4
  • With LINQ you mean LINQ to Objects? Or did you mean the whole LINQ incl. XML and SQL? Commented Aug 16, 2011 at 7:48
  • @mbx Yes. I mean LINQ-to-objects only. Commented Aug 16, 2011 at 9:05
  • btw, SQL-like expression tree based LINQ query syntax is not something impossible in C++, stuff like boost::proto let people write DSEL now Commented Apr 8, 2012 at 23:20
  • 3
    I'm voting to close this question as off-topic because it's asking us to predict the future. Commented Dec 26, 2015 at 15:33

3 Answers 3

2

LINQ-to-objects is already supported in the Standard library and has been since it's inception. The syntax is just a bit different- it was never intended to emulate SQL and has way too many iterators in it. You can make it more reminiscent without too big a hassle.

Edit: When actually attempting to make it more reminiscent without too big a hassle, I determined that it actually could be a significant hassle. It is, however, still completely possible.

4
  • The syntax is just a bit different is that a euphemism?! Commented Aug 16, 2011 at 11:09
  • @mbx: No, that's how it is. And as my post demonstrates, it's trivial to alter that syntax. Commented Aug 16, 2011 at 11:30
  • 4
    You might want to explain how to actually use this? Commented Aug 16, 2011 at 11:46
  • 1
    Yeah, I realized that it wasn't exactly a finished product. Commented Aug 16, 2011 at 12:07
1

Notes : For C++2011 there is not such functionality. Fortunately, the next C++ should include a filesystem library (see boost::filesystem) so you can guess that such a database library will not be standardized soon.

There are several (and some recent) discussions on the boost mailing list about such library. Several people are pointing to potential boost-like libraries like SOCI and CPPDB.

Also, I don't see how lambdas can help for such a functionality. Lambdas are still code, not EDSL constructs.

1
  • I didn't Linq-to-sql with Linq. It was about the lambda based method chaining. Commented Nov 2, 2011 at 6:41
0

There's ODB which is interesting.

see the sample code from the ODB wikipedia entry that searches for all people called Doe younger than 30 (age and last are DB columns, directly mapped to a class, this is done by the ODB compiler to it always keeps automatically generated classes in sync with the DB schema, without having to modify a DB->code mapping definition file or assembly). I like it because of that, having had to maintain an Entity Framework assembly.

 transaction t(db.begin ()); result r(db.query<person>(query::last == "Doe" && query::age < 30)); for (result::iterator i (r.begin ()); i != r.end (); ++i) { cout << "Hello, " << i->first () << endl; } t.commit (); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.