Boost logo

Boost :

From: Stjepan Rajko (stipe_at_[hidden])
Date: 2008-08-13 11:30:25


On Wed, Aug 13, 2008 at 8:09 AM, Paul A Bristow <pbristow_at_[hidden]> wrote:
>
> This looks neat and feels C++-ish (rather than IBM JCL - but you're too young to remember that ;-)
>

I'm apparently too young to even know what it is :-)

> Jake Voytko and I concluded similarly when developing Scale Vector Graphics PLotting user interface where there are hundreds of
> possible functions (x_axis_color(red), point_color(green)...).
>

I remember following that discussion.

>
> Chaining calls is convenient because you don't need to remember the order.
> The compile time seemed a little better too compared to Boost.Parameter, and the setup more intuitive (C++y rather than macros).
>
> Since it now clear that named parameters are not going to in the C++ language proper, I believe that this is best idiom to use.
> Despite being unfamiliar, chaining is obvious once you get going with it.
>

As of right now, I have something even better :-)

How about this syntax:

function_taking_both(( label("hello"), size(1) ));

or, if double parens aren't your thing, how about this:

function_taking_both( label("hello") & size(1) );

Even better than the even better syntax, the new implementation
completely separates the fields from the "library". You now do this
to define the fields:

#include <boost/guigl/parameter_pack.hpp>

namespace field {

    struct label
    {
        typedef std::string type;
    };

    struct size
    {
        typedef int type;

        static type default_value()
        {
            return 3;
        }
    };

}

BOOST_PARAMETER_FUNCTION(field::label, label)
BOOST_PARAMETER_FUNCTION(field::size, size)

and you are good to go!!!

New implementation:
http://pastebin.com/f29304ed

New test:
http://pastebin.com/f60120d0d

I need to fix default construction, and extend the number of possible
fields (real quick fixes), but other than that, this should be pretty
usable (minus ironing out little kinks which are to be expected until
it gets used a bit).

Cheers!

Stjepan

PS I hope I can fall asleep now. I woke up at 4am with this idea in
my head, and couldn't get back to sleep. So I got up and implemented
it. At 7am I tried going back to bed, but unfortunately, the idea for
the better solution struck me and I still couldn't fall asleep. So I
got back up and implemented that. Perhaps now...


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