I search for a VS2010 compatable C++ linq library with C# LINQ dot sintax. meaning something like: from(...).where(...).orderBy.firstOrDefault();
I googled and found this so answer LINQ libraries collection/mess:
orderBy
orderBy
Others I found not using dot notation.. btw pfultz2/Linq seems to provide orderBy and first yet its SQL like LINQ sintax and Limitations make it something I am not looking for=(
So Is ther any opensource C++ LINQ library with dot notation, orderBy and firstOrDefault?
Well, I will not give you the reply you want, but it will be a reply anyway :-)
LINQ is thought for C# mainly. I think your use case should be for translating C# code into C++, but I think that the effective way in C++ is to use Boost.Range.
Boost.Range reuses the c++ standard library in a way that is easy to do query on data:
operator |
. They are evaluated lazily, just as in LINQ.std::min, std::max, std::all_of, std::any_of, std::none_of
in the adapted ranges.An example I wrote the other day is how to reverse words in a string. The solution was something like this:
using string_range = boost::iterator_range<std::string::const_iterator>;
struct submatch_to_string_range {
using result_type = string_range;
template <class T>
string_range operator()(T const & s) const {
return string_range(s.first, s.second);
}
};
string sentence = "This is a sentence";
auto words_query = sentence |
ba::tokenized(R"((\w+))") |
ba::transformed(submatch_to_string_range{}) |
ba::reversed;
vector<string_range> words(words_query.begin(), words_query.end());
for (auto const & w : words)
cout << words << endl;
I highly recommend you to base your queries upon this library, since this is going to be supported for a very long time and I think it will be the future. You can do same style of queries.
It would be nice if this library could be extended with things like | max
and | to_vector
to avoid naming the vector directly and copying, but I think that as a query language, right now, it's more than acceptable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With