Boost logo

Boost Users :

Subject: Re: [Boost-users] framework for invoking func-ptrs with different argument numbers
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2013-08-17 17:18:55


> Consider the following task: Given a > -) pointer to a function, and > -) an iterator range with elements of type void *, > the function-ptr shall be called with all the elements in the range as > arguments. > > So conceptionally something like this: > > template <typename Func, typename Iter> > void make_call(Func, Iter begin, Iter end) > { > int n = std::distance(begin, end); > (*Func) (*(begin), *(begin + 1), *(begin + 2), ..., *(begin + n - 1)) > } > > The interface (function declaration) here is +- what I want, the > implementation shown of course is dummy-code not working. Does boost > provide a more or less easy way to get this implementation smoothly > done? C++ is 2003 version, so code must be compatible with e.g. VS > 2008.. Note that I would know in principle a way how to do implement it > myself, which involves the creation of a separate class for each number > of arguments, but that's precisely what I want to avoid and I hope that > wheel has already been invented in some boost-library :) Is 'Func' a C-style vararg function, or is it a function object where the number of arguments it takes is known at compile time (perhaps being a choice among a finite number of overloads)? Regards, Nate


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net