[C++-sig] problems with lvalue_from_pytype

David Abrahams dave at boost-consulting.com
Sat Nov 23 04:07:35 CET 2002


Mark Russell <mrussell8081 at pacbell.net> writes:

> David,
>
> As I understand the situation from your last reply:
>
> snip...
>
> As I wrote several messages ago:
>
>> So if you want to convert to HWND, your converter's execute function
>> must return a reference to the type that HWND points to
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> <from several messages ago>
>
> So if you want to convert to HWND, your converter's
> execute function must return a reference to the type that HWND points
> to (remove_pointer<HWND>::type& if your compiler supported partial
> specialization, which it doesn't).
>
>>
>> struct convertNoddy {
>> 	static HWND& execute(PyObject& o) {
>> 		static long magic = call_method<long>(&o, "getMagicNum");
>> 		static HWND hmagic = reinterpret_cast<HWND>(magic);
>> 		return hmagic;
>> 	}
>> };
>
> I cannot simply cast the int to an HWND I have to use an mpl construct that
> describes the returned type.  

??? No, that's why I asked you to:

>> find out what the real type of the pointee is on your own

And didn't you just tell me that:

>> An HWND is a pointer to an HWND__ struct defined as follows:
>>
>> struct HWND__ { int unused; };
>> typedef struct HWND__* HWND

So, ask yourself:

    1. what type does HWND point to? 
    2. Can you form a reference to that type?
    3. Given an HWND__*, how can you get a HWND__&?

OK, I'll spell it out for you:

    static HWND__& execute(PyObject& o) { ... return *hmagic; }

> I have read your paper on mpl and looked through the refs--very
> interesting and I will want to explore this more but I can't workout
> how to return this.  If vc supported partial specialization I take
> it that I could do the following:
>
>> 		return remove_pointer<HWND>::type&hmagic;

Uh, that's sort of like saying 

    return int&x;

which wouldn't be legal C++ anyway.

> But since it doesn't I need to find a work around.  It this correct?

I think you're making this too complicated. If you don't see the
answer at this point, please re-read the thread very carefully.






More information about the Cplusplus-sig mailing list