
I am refactoring code that looks something like this: if (op == LN::FILTER_IN || op == LN::FILTER_NOT_IN) { where += handle_set_operation(column, type, format, op, expr_set); } else if (op == LN::FILTER_RANGE) { where += handle_range_operation(column, type, format, op, expr_set); } else if (op == LN::FILTER_NULL || op == LN::FILTER_NOT_NULL) { where += handle_null_operation(column, op); } ... This would obviously be handled better with a map of some sort (has to map int to function). The problem here is that some functions have more arguments than others, precluding the possibility of uniform type for the function value of the map. I cannot just go and change the function sig to include dummy values ('cause it's a dumb idea). This situation made me think of boost.function/boost.bind, which allows to effectively shorten the function parameter list by binding some of the args. so given int f(int a, int b) { return a + b; } bind(f, _1, 5)(x); is equivalent to f(x, 5); and by extension bind(f, _1, _2, _0)(x, y, z) would be equivalent to f(x, y) thoughts? thanks. This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.

Max Khesin <MKhesin <at> liquidnet.com> writes:
I am refactoring code that looks something like this:
if (op == LN::FILTER_IN || op == LN::FILTER_NOT_IN) { where += handle_set_operation(column, type, format, op, expr_set); } else if (op == LN::FILTER_RANGE) { where += handle_range_operation(column, type, format, op, expr_set); } else if (op == LN::FILTER_NULL || op == LN::FILTER_NOT_NULL) { where += handle_null_operation(column, op); } ...
I assume that you somewhere have a switch/case or multiple if/else if implementing dispatch on "where", before the above code is executed. If so, then this looks like the implementation of a state machine.
This would obviously be handled better with a map of some sort (has to map int to function). The problem here is that some functions have more arguments than others, precluding the possibility of uniform type for the function value of the map. I cannot just go and change the function sig to include dummy values ('cause it's a dumb idea). This situation made me think of boost.function/boost.bind, which allows to effectively shorten the function parameter list by binding some of the args.
It seems that would be possible, but I think (given that I'm right about the state machine nature of your code) there are better ways to implement this. You might want to have a look at boost::fsm: Docs only: http://boost-sandbox.sf.net/libs/fsm Code, examples and docs zipped: http://boost-sandbox.sf.net/fsm.zip Regards, Andreas

Andreas Huber wrote: [snip]
This would obviously be handled better with a map of some sort (has to map int to function). The problem here is that some functions have more arguments than others, precluding the possibility of uniform type for the function value of the map. I cannot just go and change the function sig to include dummy values ('cause it's a dumb idea). This situation made me think of boost.function/boost.bind, which allows to effectively shorten the function parameter list by binding some of the args. I admit I'm not familiar with this, but another method used to simulate a virtual function table with different arg lists was discussed in comp.std.c++ under subjects headings:
From: brangdon@cix.co.uk (Dave Harris) Newsgroups: comp.std.c++ Subject: Re: Proposal for Interfaces (version 3.0) Date: Mon, 26 Apr 2004 16:59:05 +0000 (UTC) From: dave@boost-consulting.com (David Abrahams) Newsgroups: comp.std.c++ Subject: Re: Proposal: interfaces [repost] Date: Mon, 26 Apr 2004 01:53:05 +0000 (UTC)

Daniel Wallin wrote:
Max Khesin wrote: [snip]
and by extension bind(f, _1, _2, _0)(x, y, z) would be equivalent to f(x, y)
I don't get it, what is _0 here? AFAICT
bind(f, _1, _2)(x, y, z)
is already the equivalent of
f(x, y)
ok, I guessed that I was missing something. Thanks Daniel, I'll go check it out!
participants (5)
-
Andreas Huber
-
Daniel Wallin
-
Larry Evans
-
Max Khesin
-
Maxim Khesin