Boost logo

Boost :

Subject: Re: [boost] [local] Help for the Alternatives section
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2011-05-12 12:09:23


lcaminiti wrote:
>
> On Sun, May 8, 2011 at 1:06 PM, Lorenzo Caminiti
> <lorcaminiti_at_[hidden]> wrote:
>> On Sun, May 8, 2011 at 11:22 AM, Mathias Gaunard
>>>
>>> The type erasure appear unnecessary, and this implementation has big
>>> forwarding problems.
>>>
>>> What about
>>
>> Yes, makes sense. Using your suggestion:
>
> Hi all, the following code compiles and runs just fine on GCC but it
> given the error below on MSVC. The error seems to be about a
> conversion to boost::function_base inside Boost.Function...
>
> [...]
>
>

I have implemented local function overloading:

http://svn.boost.org/svn/boost/sandbox/local/libs/local/doc/html/boost_local/Advanced_Topics.html#boost_local.Advanced_Topics.overloading_local_functions

http://svn.boost.org/svn/boost/sandbox/local/boost/local/function/overload.hpp
http://svn.boost.org/svn/boost/sandbox/local/boost/local/aux_/overload_base.hpp

#include <boost/local/function/overload.hpp> // Include header for
overloading.
#include <boost/local/function.hpp>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>

int print_add(int x, int y) {
    std::cout << x << " + " << y << " = ";
    return x + y;
}

int main() {
    char end = '\n';

    void BOOST_LOCAL_FUNCTION_PARAMS(const std::string& item,
            const bind& end) {
        std::cout << item << " (string)" << end;
    } BOOST_LOCAL_FUNCTION_NAME(print_string)

    void BOOST_LOCAL_FUNCTION_PARAMS(const double& item,
            const char* name, default " (double)", const bind& end) {
        std::cout << item << name << end;
    } BOOST_LOCAL_FUNCTION_NAME(print_double)
    
    boost::local::function::overload<
          void (const std::string&)
        , void (const double&) // Overload 1st param type.
        , void (const double&, const char*) // Overload giving default
param.
        , int (int, int) // Overload giving 2 params (from function
pointer).
> print(print_string, print_double, print_double, print_add);

    std::vector<std::string> s(3);
    s[0] = "ab"; s[1] = "cd"; s[2] = "ef";
    std::for_each(s.begin(), s.end(), print); // Call `print_string`
1-param.
    
    std::vector<double> d(2);
    d[0] = 1.2; d[1] = 3.4;
    std::for_each(d.begin(), d.end(), print); // Call `print_double`
1-param.

    print(-1.234, " (real)"); // Call `print_double` 2-params.
    
    std::cout << print(2, 3) << std::endl; // Call `print_add`.

    return 0;
}

--Lorenzo

--
View this message in context: http://boost.2283326.n4.nabble.com/local-Help-for-the-Alternatives-section-tp3408469p3517996.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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