std::reference_wrapper usage

13 views
Skip to first unread message

Loco Jay

unread,
Jul 6, 2015, 2:42:54 AM7/6/15
to cython...@googlegroups.com
Hi,

I would like to use a class from a library which uses std::reference_wrapper and std::ref.
I was not able to find it in libcpp and therefore created a file reference_wrapper.pxd with the following content


cdef extern from "<functional>" namespace "std" nogil:
    cdef cppclass reference_wrapper[T]:
        reference_wrapper()
        reference_wrapper(T& ref)
        reference_wrapper(T&&)
        reference_wrapper(const reference_wrapper[T]&)
        # reference_wrapper& operator=(const reference_wrapper& x)
        # operator T& ()
        T& get()
    reference_wrapper[T] ref(T &t)

include "reference_wrapper.pxd"
def test():
    cdef int a=2
    cdef reference_wrapper[int] refa
    refa = ref(a)

But unfortunately get

    reference_wrapper[T] ref(T &t)
                      ^
------------------------------------------------------------
reference_wrapper.pxd:11:23: unknown type in template argument

Any help to get a basic example working would be very helpful.
Many thanks 

 

Marcel Martin

unread,
Jul 6, 2015, 4:27:06 AM7/6/15
to cython...@googlegroups.com
On 2015-07-05 21:22, Loco Jay wrote:
> reference_wrapper[T] ref(T &t)

I don’t know whether the rest of your code is correct, but I believe
this declaration should be

reference_wrapper[T] ref[T](T &t)

instead.

Marcel

Reply all
Reply to author
Forward
0 new messages