No, no, use boost::bind!!! (Which I think is identical to std::bind in C++11)
It's already an elegant way to make something that looks like a no-argument
function but which wraps a function call and its arguments.
For example, if you have a template that looks like this:
template <class FUNC> void mytemplate (FUNC f) { f(); }
that obviously just calls function (or functor) f with no arguments. But say
you want to call mytempalate using
myfunction (a, b, c);
the mytemplate is not set up to handle 3-argument functions, but bind comes to
the rescue. Just:
mytemplate (boost::bind (myfunction, a, b, c));
That's all. Easy!
On Jun 20, 2012, at 9:38 PM, Chris Foster wrote:
>
> I suggest a "closure" class to pass along the arguments such as the ROI
> for over.
>
> class ExecuteOver
> {
> ImageBuf& m_R;
> const ImageBuf& m_A;
> const ImageBuf& m_B;
> ROI m_roi;
>
> ExecuteOver(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi)
> : m_R(R), m_A(A), m_B(B), m_roi(roi) {}
>
> void exec(const ROI& parallelBlock)
> {
> /* over_impl does dispatch based on types of R,A,B */
> over_impl(m_R, m_A, m_B, m_roi, parallelBlock);
> }
> };
>
> And hence, schematically,
>
> template<typename ClosureT>
> bool parallel_image(ClosureT& closure)
> {
> parallel_for(parallelBlock in /*block up the domain somehow*/)
> {
> closure.exec(parallelBlock);
> }
> }
>
> Note: the above is very rough and ready off the top of my head, but
> hopefully the basic idea will work.
>
>> I started thinking/working on "contrast" and having all the type
>> specialization functions and parallel_image repeating in imagebufalgo.cpp
>> causes a real mess. Imagine 20 more algorithms and for each such functions.
>
> Agreed, we need to deal with this issue. However, Larry seems keen to
> do this more incrementally after we get an initial over()
> implementation working and I do prefer incremental development.
> (Caveat: Given the code specialization bloat we've been discussing, it
> might not be a good idea to go with Larry's type dispatch method.)
>
> ~Chris
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
--
Larry Gritz
[email protected]
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org