hof icon indicating copy to clipboard operation
hof copied to clipboard

about unpack_sequence customization point

Open viboes opened this issue 10 years ago • 8 comments

I'm not completely against the way you have customized unpack, but I prefer to overload non-member functions than using some kind of traits.

I would preferred if std::experimental::apply could be customizable and so

unpack(f)(product_type) <==> std::tuple::apply(f, product_type)

This has the advantage that the user can use the apply function when it has the function and the product-type.

What about replacing unpack_sequence by an overloaded apply?

Overloading apply has the liability that it is not a high-order function, but we can have an apply_fn that is hof.

viboes avatar Oct 04 '15 17:10 viboes

What about replacing unpack_sequence by an overloaded apply?

That would be confusing since fit::apply calls a function with its parameters and the overload apply unpacks the sequence. I could add an ADL name for unpacking, but I need to think of a good name for it.

pfultz2 avatar Oct 05 '15 07:10 pfultz2

Agreed we may need two different names. As apply is already taken by the standard, maybe we need a name for your apply

viboes avatar Oct 05 '15 21:10 viboes

Using the name apply here has a long history in C++. There are similar constructs in other libraries, such as Boost.MPL, Meta, Boost.Hana and Pstade.Egg. I would prefer to stick with the commonly used name of apply here as it will be familiar with more C++ programmers. Plus, at this point, std::experimental::apply is just a TS and not part of the standard yet.

Also, Fit will already unpack tuples, so there is no need to try and integrate with an apply overload. Plus, I would not choose a simple name like apply for ADL overload because its too easy for things to go wrong with such a simple name(and the fact it used for another purpose in other libraries).

pfultz2 avatar Oct 05 '15 22:10 pfultz2

It is up to you to choose the design of your library. What is the apply signature in Boost.Hana?

viboes avatar Oct 05 '15 23:10 viboes

In Hana, apply is used as apply(f, args...), and it can take an arbitrary Callable object. In other words, it is strictly equivalent to std::invoke. The exact signature of apply is nasty to write here without LaTeX.

ldionne avatar Oct 06 '15 00:10 ldionne

Now that I think about it more. I don't think I will add an ADL customization point, because it makes it harder to detect if a sequence is unpackable. I think I will stick with template specialization for now. It has an extra parameter to use for matching with SFINAE as well, so its easy enough to make it match some user defined function, if the user so wishes.

pfultz2 avatar Oct 06 '15 16:10 pfultz2

Well, thinking about this even more, an ADL customization point could be added, but it would have a different signature. Instead the ADL function would return a function that can unpack the sequence, something like unpacker(sequence)(f). Then this would still make is easy to detect if the sequence is unpackable by checking if unpacker(sequence) is callable. Of course, a better name than unpacker would be nice.

pfultz2 avatar Oct 09 '15 16:10 pfultz2

In addition, one problem with this is approach is that forwarding references can't be used. It might be better to have it called like this: unpacker(sequence)(sequence, f) instead. Although it might seem redundant, it would allow the unpacker to use forwarding reference instead of defining three overloads.

pfultz2 avatar Oct 09 '15 16:10 pfultz2