Boost logo

Boost :

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

On Mon, Sep 13, 2010 at 5:33 PM, Pierre Morcello
<pmorcell-cppfrance_at_[hidden]> wrote:
> Concerning the 'default' values that you proposed, it is an interesting idea, though I am not sure I would have a use for it.

Here's an example of how default parameters might be useful (together
with recursion):

#include <contract/detail/local_function.hpp>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

int main () {
    std::vector<int> v;
    std::ostringstream factorials;

    (int) (factorial)(
    ) {
        int result = 0;

        if (n < 2 ) result = 1;
        else result = n * factorial(n - 1, true); // Recursive call.

        if (!recursion) factorials << result << " ";
        return result;

    std::for_each(v.begin(), v.end(), factorial);
    std::cout << factorials.str() << std::endl;

    return 0;

However, in general, default parameters are used to overload a
function API. Therefore, I think they make much more sense when used
in the public API as supposed in local functions which are in nature
part of the implementation.

(BTW, I just got the code above to work. It required quite a bit of
re-work to get the template parameter trick to function together with
default parameters...)


Boost list run by bdawes at, gregod at, cpdaniel at, john at