
On Thu, Nov 18, 2004 at 10:35:08PM +0000, Daniel James wrote:
Jonathan Wakely wrote:
Could you supply an extra arg to the macro, specifying whether to define the nullary overload for the cases where it is wanted and valid ?
Yep, or maybe minimum, maximum parameter arguments. Although, if the macro gets complex enough to invoke, it'll probably be better just to write it out manually. For example, your tolower test becomes:
#include <string> #include <algorithm> #include <cctype>
struct { template <class T> T operator()(T x) { return std::tolower(x); } } tolower_visitor;
int main() { std::string s("FNORD"); std::transform(s.begin(), s.end(), s.begin(), tolower_visitor); }
Which is perhaps better since it has the correct return type.
Indeed. It was the chance to avoid exactly that wrapper functor that interested me in your macro - but as you say, if the macro ends up taking many arguments it's simpler to explicitly define the functor. regards, jon -- "A sympathetic Scot summed it all up very neatly in the remark, 'You should make a point of trying every experience once, excepting incest and folk dancing.'" - Sir Arnold Bax