[C++-sig] strange behavior with respect to numeric and Boolean overloads
Roman Yakovenko
roman.yakovenko at gmail.com
Tue Mar 17 06:40:14 CET 2009
On Mon, Mar 16, 2009 at 8:30 PM, Matthew Scouten (TT)
<Matthew.Scouten at tradingtechnologies.com> wrote:
> I read the linked page, but this still feels like a bug to me. Or at least a wart. Like I said, the order sensitivity I can live with, because that only effects me. But the int vs bool problem is really obnoxious. C++ can tell an int from a bool, Python can tell an int from a bool, but library between them is discarding this information.
>
> I agree that the best solution (from a purely technical view point) would be to rename the functions in the underlying c++ library, but I do not have control over that library and they have good reason to serve c++ users first and to resist interface breaking changes. From a UI viewpoint, the function is called foo. It foos the data that you pass to it. Having functions foo_int and foo_bool is not good style in either c++ or python.
May be you've got me wrong. I suggest to expose the function under
different names( aliases ) and than to create small function in
Python, which calls the desired one:
void foo( bool );
void foo( int );
def( "_foo_bool", (void *(bool) )( foo ) );
def( "_foo_int", (void *(int) )( foo ) );
Python code:
def foo( arg ):
if isinstance( arg, int ):
_foo_int( arg )
else:
_foo_bool( arg )
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list