Skip to content

should we add meta continuations to brigand? #242

@odinthenerd

Description

@odinthenerd

What are meta continuations?
The basic concept is that rather than having templated structs which contain both algorithm and the data being worked one uses a templated struct for the algorithms only which provides a nested template which works on the data. This pattern allows for better memoization of algorithms and faster work on data due to passing by alias rather than instantiating a type.

Advantages:
Algorithms can be composed at zero cost. In fact since we can make optimizations to composed algorithms, for example when unpacking the same list twice as is the case in partition. The ability to compose algorithms in this way allows for many more algorithms to be implemented in terms of other algorithms.
For example the algorithm filter is just a transform and then a join and then a "listify" (listify is a contination which makes a list from the input parameters) but if we swap out the last step with a "count" (count is a continuation wrapper around sizeof...(Ts)) then we have a count_if. This kind of composition would be far slower with other paradigms than the hand written equivalent count_if but with continuation style this becomes a viable solution.
The real advantage I see is that the user profits from this composability as well. Initial use of this in kvasir::bit has shown that the ability to compose arbitrary algorithms can make a 10 fold improvement in the speed of complex calculations.

Disadvantages:
Although this pattern does work on clang 3.0+ GCC 4.7+ and MSVC2017 I just can't get it to work on MSVC2015.
Surprisingly I can't think of anything which would be broken if we swapped out all of brigands guts for kvasir::mpl's guts (basically everything in namespace mpl::c). We can implement brigands sequence type agnostic behavior easily since kvasir::mpl does not use any lists under the hood in most algorithms any way and the last listification step could be configured to be the type of the sequence which brigands front end matched. Brigand lambdas could also be wrapped up in a continuation and just work as a predicate in kvasir::mpl algorithms.
That being said I've been coding too long to believe there will not be some weird shit that only comes to light after we are 90% done with porting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions