• Jason Rhinelander's avatar
    Add movable cast support to type casters · 813d7e86
    Jason Rhinelander authored
    This commit allows type_casters to allow their local values to be moved
    away, rather than copied, when the type caster instance itself is an rvalue.
    
    This only applies (automatically) to type casters using
    PYBIND11_TYPE_CASTER; the generic type type casters don't own their own
    pointer, and various value casters (e.g. std::string, std::pair,
    arithmetic types) already cast to an rvalue (i.e. they return by value).
    
    This updates various calling code to attempt to get a movable value
    whenever the value is itself coming from a type caster about to be
    destroyed: for example, when constructing an std::pair or various stl.h
    containers.  For types that don't support value moving, the cast_op
    falls back to an lvalue cast.
    
    There wasn't an obvious place to add the tests, so I added them to
    test_copy_move_policies, but also renamed it to drop the _policies as it
    now tests more than just policies.
    813d7e86
test_copy_move.cpp 7.45 KB