Boost proto vs C #

First, I wonder if both "features" have the same goal. Secondly, if yes (or only partially yes), is there any significant restriction in the boost impulse C # Expression Tree

thanks

+4
source share
3 answers

I am the author of Boost.Proto, and I just recently discovered C # expression trees. AFAICT, they are similar in intentions, but different both in implementation and in scope.

C # has language support for capturing a LINQ expression as a dynamically typed tree. This is used by LINQ consumers to optimize query scores. A query against an in-memory data structure would be a simple assessment using LINQ extension methods, but one would be more optimally executed using a LINQ expression at run time, evaluating a T-SQL string and passing it to the SQL server for remote execution. As of now, C # expression trees are best suited for such optimization tasks.

Boost.Proto OTOH has a slightly wider coverage. Proto expression trees are statically typed, which allows complex transformations and code generation at compile time. More importantly, Proto provides tools for introspecting and transforming trees and creating custom code from them. This may be useful for optimization, but also for providing expressions of completely different subject semantics. Therefore, Proto is more accurately perceived as an integrated set of tools for specific languages.

The same could be done with C # expression trees, but AFAIK there is currently no infrastructure for tree conversion and code generation. The ability to generate runtime code on .NET makes this feature compelling. Maybe some entrepreneurial developer (you?) Would be ready to write Proto # on top of C # expression trees. :-)

+5
source

They partially overlap in that they can both be used for DSL recording. Boost proto is built around the idea of โ€‹โ€‹building an embedded DSL in C ++, which is converted to C ++ and compiled at compile time. C # expression trees will be more related to writing an external DSL (or any interpreter). Therefore, boost :: Proto is a modification and extension of C ++, and expression trees are about writing code in a new language, and not changing C #.

+1
source

Actually you wanted to ask? I do not understand your question.

Their goals do not match because C ++ and CLR are very different.

In C ++, you cannot accept arbitrary code and work with it as an expression. You do not have a Reflection mechanism.

An expression is a RunTime function, and Boost Proto is a compile-time library.

-2
source

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


All Articles