|
Boost : |
Subject: Re: [boost] [local] Help for the Alternatives section
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-05-05 14:03:38
On Thu, May 5, 2011 at 10:53 AM, lcaminiti <lorcaminiti_at_[hidden]> wrote:
[...]
> I have been thinking if I can do something similar to this with
> Boost.Local.
> Given that local classes cannot have template members I can't do too
> much...
> However, I _could_ allow to specify multiple types (but not a generic type)
> for a local function parameter:
>
> void BOOST_LOCAL_FUNCTION_PARAMS(types(int, char) x, types(double,
> std::string, int) y, long z) {
> std::cout << x << y << z << std::endl;
> } BOOST_LOCAL_FUNCTION_NAME(l)
>
> Then I can do:
>
> l(1, 1.2, -1);
> l('a', 1.2, -1);
> l('a', "bcd", -1);
> ... // and all the other parameter type combinations
>
> types(...) could accept a generic number of types but all these types will
> have to be known (and not generic as for templates).
>
[...]
> This is more overloading than polymorphism... bus still:
> 1) Compiles on ISO C++.
> 2) Declares l locally (information hiding).
> 3) Does not repeat l declaration multiple times (avoid code duplication).
> 4) l is """effectively polymorphic""" (in between _many_ quotes :) ) in its
> argument type num as it accepts both doubles and std::strings (but no more
> than these two types :( ). (I will not actually claim that such a local
> function l polymorphic in num's type.)
>
> What do you think?
>
Better than nothing (=strict monomorphicity)! I would assume the types(...)
syntax is only optional, correct?
Not related to the above discussion: Bound variables' types are deduced
using Boost.TypeOf; is it possible right now to explicitly specify their
type?
- Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk