[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mapper functions for 3.1
From: |
John W. Eaton |
Subject: |
Re: mapper functions for 3.1 |
Date: |
Sat, 16 Feb 2008 14:35:20 -0500 |
On 16-Feb-2008, David Bateman wrote:
| I see one issue with the charNDArray class. There the typedef for all
| the mapper functions are the same (i.e. int (*) (int)) but the return
| type of the mapper method itself might be different (cf isalpha to
| tolower). This is likely to cause issue with your scheme, and is in fact
| why the charNDArray mapper methods have different maps (dmap, smap,
| bmap) in my patch.. I'm not sure how to deal with that in your scheme,
| other than keeping the map names different. So you'll end up with 6
| different mapper methods in the Array<T> class at least.
I think this can be handled by using something like the following.
Add
template <typename CT, typename RT, typename PT>
class functor_with_conversion
{
private:
typedef typename fcn_ptr<RT, PT>::TYPE fcn_ptr_type;
fcn_ptr_type fptr;
public:
functor_with_conversion (fcn_ptr_type p) : fptr (p) { }
CT operator () (PT arg) { return CT (fptr (arg)); }
};
template <typename CT, typename RT, typename PT>
functor_with_conversion<CT, RT, PT>
func_ptr_with_conversion (RT (*f) (PT))
{
return functor_with_conversion<CT, RT, PT> (f);
}
to Array.h (or some other header specifically for these functor
classes) and then keep the declarations
typedef int (*mapper) (int);
boolNDArray bmap (mapper fcn) const;
NDArray dmap (mapper fcn) const;
charNDArray smap (mapper fcn) const;
in chNDArray.h and use
boolNDArray
charNDArray::bmap (mapper fcn) const
{
return MArrayN<char>::map<bool> (func_ptr_with_conversion<bool> (fcn));
}
NDArray
charNDArray::dmap (mapper fcn) const
{
return MArrayN<char>::map<double> (func_ptr (fcn));
}
charNDArray
charNDArray::smap (mapper fcn) const
{
return MArrayN<char>::map<char> (func_ptr_with_conversion<char> (fcn));
}
in chNDArray.cc. There might be a slick way to combine the functor
and functor_with_conversion classes using default template parameters
but I don't see it at the moment.
jwe
- Re: mapper functions for 3.1, (continued)
- Re: mapper functions for 3.1, David Bateman, 2008/02/13
- Re: mapper functions for 3.1, David Bateman, 2008/02/13
- Re: mapper functions for 3.1, John W. Eaton, 2008/02/13
- Re: mapper functions for 3.1, David Bateman, 2008/02/14
- Re: mapper functions for 3.1, John W. Eaton, 2008/02/14
- Using C++ exceptions in liboctave (was: Re: mapper functions for 3.1), John W. Eaton, 2008/02/14
- Using C++ exceptions in liboctave (was: Re: mapper functions for 3.1), John W. Eaton, 2008/02/14
- Re: mapper functions for 3.1, David Bateman, 2008/02/15
- Re: mapper functions for 3.1, John W. Eaton, 2008/02/16
- Re: mapper functions for 3.1, David Bateman, 2008/02/16
- Re: mapper functions for 3.1,
John W. Eaton <=
- Re: mapper functions for 3.1, John W. Eaton, 2008/02/16
- Re: mapper functions for 3.1, David Bateman, 2008/02/17
- Re: mapper functions for 3.1, John W. Eaton, 2008/02/18
- Re: mapper functions for 3.1, John W. Eaton, 2008/02/20