[C++-sig] wrapping typedef equivalent types
Neal Becker
ndbecker2 at gmail.com
Thu Oct 20 01:29:48 CEST 2005
David Abrahams wrote:
> Neal Becker <ndbecker2 at gmail.com> writes:
>
>> David Abrahams wrote:
>>
>>> Neal Becker <ndbecker2 at gmail.com> writes:
>>>
>>>> What happens if, using boost::python, I try to wrap 2 type equivalent
>>>> classes?
>>>>
>>>> For example (this is a trivial example):
>>>>
>>>> class_<int>...
>>>> class_<int32_t>...
>>>> where int == int32_t
>>>>
>>>> My real objective is to wrap classes
>>>>
>>>> template<int_t> class X {};
>>>>
>>>> where int_t is
>>>> int (natural int size)
>>>> int32_t (force 32-bit)
>>>> int64_t (force 64-bit)
>>>>
>>>> Can wrapped X<int>, X<int32_t>, X<int64_t> co-exist in the same python
>>>> module?
>>>
>>> No, all wrapped classes have to have different types. You could add a
>>> dummy parameter to X in order to distinguish them.
>>>
>>
>> I don't understand the dummy parameter suggestion. Could you elaborate?
>
> template <class int_t, int bits> class X {};
>
> X<int, 16>
> X<int32_t, 32>
> X<int64_t, 64>
>
> or
>
> template <int bits>
> class X
> {
> typedef boost::int_t<bits>::fast int_t;
> ...
> };
>
>> I found a different solution. I just expose the int32_t and int64_t
>> versions, then use python code to set the equivalence. In python, I
>> write something like:
>>
>> if (intsize() == 4): X = X32
>>
>> I guess there's nothing wrong with that approach :)
>
> Not unless X32 and X64 are trying to be wrappers for the same
> underlying C++ class.
>
Maybe I didn't explain this very well. What I want in python is
Xint
Xint32
Xint64
Where:
Xint32 -> X<int32_t>
Xint64 -> X<int64_t>
Xint -> X<int>
So that Xint is type equivalent to Xint32 or Xint64, depending on the
platform.
More information about the Cplusplus-sig
mailing list