[Fit] Purpose and Use Cases
Hello, Before the formal review begins I would really like to understand the purpose of Boost.FIT It isn't clear to me from the documentation what are the real world use cases? What can't be done today (for example composition) with simple C++11 lambdas? I'd love to see several real world examples and use cases of Boost.FIT - because at least for me I don't really understand why it is useful. Artyom
It isn't clear to me from the documentation what are the real world use cases?
Well, I go over some simple use cases in quick start guide, maybe its not
entirely clear. As the Fit library is a collection of generic utilities
related to functions, there is many useful cases with the library, but a key
point of many of these utilities is that they can solve these problems with
much simpler constructs than whats traditionally been done with
metaprogramming.
Initialization
--------------
The `BOOST_FIT_STATIC_FUNCTION` will help initialize function objects at
global scope, and will ensure that it is initialized at compile-time and (on
platforms that support it) will have a unique address across translation
units, thereby reducing executable bloat and potential ODR violations.
In addition, `BOOST_FIT_STATIC_LAMBDA_FUNCTION` allows initializing a lambda
in the same manner. This allows for simple and compact function definitions
when working with generic lambdas and function adaptors.
Of course, the library can still be used without requiring global function
objects for those who prefer to avoid them will still find the library
useful.
Conditional overloading
-----------------------
Take a look at this example of defining a `stringify` function from
stackoverflow here:
http://stackoverflow.com/questions/30189926/metaprograming-failure-of-functi...
The user would like to write `stringify` to call `to_string` where
applicable
and fallback on using `sstream` ot convert to a string. Most of the top
answers usually involve some amount of metaprogramming using either `void_t`
or `is_detected`. However, with the Fit library it can simply be written
like
this:
BOOST_FIT_STATIC_LAMBDA_FUNCTION(stringify) = conditional(
[](auto x) BOOST_FIT_RETURNS(to_string(x)),
[](auto x)
BOOST_FIT_RETURNS(static_cast
What can't be done today (for example composition) with simple C++11 lambdas?
First, its not a replacement for lambdas, but rather it builds on top of lambdas(and function objects) in C++, especially in C++14. Some of the limitations of lambdas in C++11 of course, is that they are not generic, and they don't support constexpr(not even in C++14). The Fit library provides a small lambda emulation using the `lazy` adaptor(like what is done with `std::bind` or Boost.Lambda) with the main purpose to support some simple `constexpr` lambda expressions. Of course, it is not a full emulation like what is done in Boost.Lambda or Boost.Phoenix. However, I have found that in practice emulated-lambda expressions are generally only useful for small simple expressions.
I'd love to see several real world examples and use cases of Boost.FIT because at least for me I don't really understand why it is useful.
Well hopeful between this and the quick start guide, you can see some of the usefulness of the library. Let me know if you have more questions. Paul
On Tue, Feb 16, 2016 at 6:39 PM, Paul Fultz II
It isn't clear to me from the documentation what are the real world use cases?
Well, I go over some simple use cases in quick start guide, maybe its not entirely clear. As the Fit library is a collection of generic utilities related to functions, there is many useful cases with the library, but a key point of many of these utilities is that they can solve these problems with much simpler constructs than whats traditionally been done with metaprogramming.
[snip lots] Paul, this is good stuff. Please add it to the documentation! Zach
On 2/16/16 4:39 PM, Paul Fultz II wrote:
It isn't clear to me from the documentation what are the real world use cases?
Well, I go over some simple use cases in quick start guide, maybe its not entirely clear. As the Fit library is a collection of generic utilities related to functions, there is many useful cases with the library, but a key point of many of these utilities is that they can solve these problems with much simpler constructs than whats traditionally been done with metaprogramming.
Initialization -------------- <snip>
Looks like you invested a lot of effort into the answer. I'm wonderin if the return on your investment wouldn't have been better had you enhanced the documentation with it then just responded with a pointer to the new documentation. My personal view is that the main obstacle to many libraries passing review is that the sparse documentation makes them hard to understand and review. Robert Ramey
participants (4)
-
Artyom Beilis
-
Paul Fultz II
-
Robert Ramey
-
Zach Laine