Haskell-like function composition function Much like this question I'm attempting to write in C++ something which can resemble Haskell's (.) function as much as possible, which is basically Chapter 1's second exercise from Bartosz Milewski's Category Theory for Programmers.
This similar question about writing the identity function served as a reference too.
This answer on StackOverflow reassured me that decltype used on lambdas' auto parameters is equivalent to decltype used on template parameters.
And this is what I came up with:
static constexpr struct compose_t {
    template &lt;typename F, typename G&gt;
    constexpr decltype(auto) operator()(F&amp;&amp; f, G&amp;&amp; g) const noexcept {
        return [&amp;f,&amp;g](auto&amp;&amp; x){
            return f(g(std::forward&lt;decltype(x)&gt;(x)));
        };
    }
} compose;

Some thoughts:

operator() takes f and g by reference, and the returned lambda captures them by reference; and I made this choice thinking it should make passing non-stateless callables cheaper, but I'm not sure I made the right choice.  Another reference is this.
Since I'm passing them by reference, I had to choose between const&amp; and &amp;&amp;, and I've basically chosen randomly.
I've not concerned myself with variadics, as I wanted a binary function composition &quot;operator&quot;, in line with Haskell's (.) :: (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c.
I cannot compose compose with something else, because it is binary, whereas the implementation implicitly assumes that F and G be unary. I guess making something like compose(compose,compose) (which is (.).(.) in Haskell) possible would be up to a partial application &quot;facility&quot;.

This is a code where I tried to test it:
#include &lt;cassert&gt;
#include &lt;utility&gt;

// ... the code from above

static constexpr struct changesign_t {
    template&lt;typename T&gt;
    constexpr decltype(auto) operator()(T&amp;&amp; t) const noexcept { return -t; };
} changesign;

int square(int x) { return x*x; }
int twice(int x) { return 2*x; }

int main() {
    assert(compose(square,twice)(3) == 36);
    assert(compose([](int x){ return x*x; },[](int x){ return 2*x; })(3) == 36);
    assert(compose(changesign, compose([](auto x){ return x*x; }, [](auto x){ return 2*x; }))(3) == -36);
}
There's no need to use a struct compose_t to wrap operator(), you can just move operator() out of it and rename it compose():
template &lt;typename F, typename G&gt;
constexpr decltype(auto) compose(F&amp;&amp; f, G&amp;&amp; g) noexcept {
    return [&amp;f,&amp;g](auto&amp;&amp; x){
        return f(g(std::forward&lt;decltype(x)&gt;(x)));
    };
}

Now it is also much closer to the code written in this post you mentioned, except of course you are limited to composing only two unary functions.
Other than that, if you can live with the restrictions you have, I see nothing wrong with your implementation.