Boost logo

Boost :

Subject: Re: [boost] [local_function] any interest in a LocalFunction library?
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-09-12 16:12:51


On Sun, Aug 22, 2010 at 11:09 AM, Lorenzo Caminiti
<lorcaminiti_at_[hidden]> wrote:
> Hello all,
>
> Is there interest in a library that implements local functions for C++?

BTW, I just realized that I never mentioned it before but
Boost.LocalFunction also supports default values for unbound
parameters.

For example, the unbound `offset` parameter of the `line()` local
function below is optional (its default value is `0`):

#include <contract/detail/local_function.hpp>
#include <iostream>

struct c {
    c(): y_(0.0) {}

    void f(double x) {
        CONTRACT_DETAIL_LOCAL_FUNCTION(
        (double) (line)(
                (int)(slope)
                (int)(offset)(default)(0) // Has default value.
                (const bound)((&x))
                (bound)((this))
            )
        ) {
            double y = slope * x + offset;
            return this_->y_ = y;
        } CONTRACT_DETAIL_LOCAL_FUNCTION_END(line)

        std::cout << line(2) << std::endl; // Print `20`.
        std::cout << line(2, 100) << std::endl; // Print `120`.
    }

private:
    double y_;
};

int main() {
    c cc;
    cc.f(10);
    return 0;
}

--
Lorenzo

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