Boost logo

Boost :

Subject: Re: [boost] [review][Fit] Review of Fit starts today : September 8 - September 17
From: Edward Diener (eldiener_at_[hidden])
Date: 2017-09-17 00:40:01


On 9/16/2017 7:53 PM, P F via Boost wrote:
>
>> On Sep 16, 2017, at 2:31 PM, Edward Diener via Boost <boost_at_[hidden]> wrote:
>>
>> On 9/16/2017 2:14 PM, P F via Boost wrote:
>>>
>>>> 5) I do not understand the purpose of the pipable adaptor. What is the point of using it ? It is mentioned as an alternative to Unified Call Syntax but, while I understand the latter, I do not understandable how pipable allows "extension methods", which is a large part of the purpose of UFCS.
>>> That is, you want to add an extension method to a class so it can be called as `x.f(y)`. With UFCS, you can just declare a free function called as `f(x, y)` and then call it as `x.f(y)`, with the Fit library you would declare the function as pipable and then call it as `x | f(y)`.
>>
>> Let us suppose I have a class:
>>
>> struct X { some member functions etc. };
>>
>> Then I want to add a member function to class X with a prototype called void f(int) so I can call it as an extension method without modifying X. With UFCS in effect I create the free function:
>>
>> void f(X px,int py) { some implementation }
>>
>> and now if I have:
>>
>> X x;
>>
>> I can call:
>>
>> x.f(3); // Works with UFCS support
>>
>> successfully. Could you please show me the equivalent code that uses pipable in this same scenario ?
>
> You could define `f` like this(using a lambda for simplification):
>
> BOOST_FIT_STATIC_LAMBDA_FUNCTION(f) = boost::fit::pipable([](X px,int py) { some implementation });
>
> And then you can call it like this:
>
> X x;
> x | f(3); // Calls f as f(x, 3)

OK. Thanks !

BTW I do not recall seeing anywhere in the doc where you mention that
Fit constructs are in the boost::fit namespace.

> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk