boost::python中copy_ctor_mutates_rhs的相关测试程序

115 篇文章 ¥59.90 ¥99.00
这篇博客介绍如何利用boost::python::detail::copy_ctor_mutates_rhs函数检测C++类在使用boost::python时,copy构造函数是否修改了右值对象。文中提供了一个示例程序,展示了如何创建测试并确保copy构造函数不会改变状态。

boost::python中copy_ctor_mutates_rhs的相关测试程序

在使用boost::python库时,我们可能会遇到一些问题,比如copy构造函数是否会修改右值对象的值。为了解决这个问题,我们可以使用boost::python::detail::copy_ctor_mutates_rhs函数来检查copy构造函数是否会改变rhs对象的状态。

下面是一个简单的示例程序,用于演示如何使用boost::python::detail::copy_ctor_mutates_rhs函数来测试copy构造函数是否会改变rhs对象的状态。该程序定义了一个名为"Foo"的C++类和相应的Python包装器,其中包括一个copy构造函数。

#include <boost/python.hpp>

using namespace boost::python;

class Foo
{
public:
    Foo() : m_data(0) {}
    Foo(const Foo& other) { m_data = other.m_data + 1; }

    int GetData() const { return m_data; }

private:
    int m_data;
};

BOOST_PYTHON_MODULE(example)
{
    class_<Foo>("Foo")
        .def(init<>())
        .def(init<const Foo&>())
        .def("GetData", &Foo::
[ { "__type__": "cc.SceneAsset", "_name": "entry", "scene": { "__id__": 1 } }, { "__type__": "cc.Scene", "_name": "New Node", "_active": false, "autoReleaseAssets": true, "_children": [ { "__id__": 2 }, { "__id__": 22 }, { "__id__": 30 } ], "_anchorPoint": { "__type__": "cc.Vec2", "x": 0, "y": 0 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 ] }, "_id": "2d2f792f-a40c-49bb-a189-ed176a246e49" }, { "__type__": "cc.Node", "_name": "Canvas", "_id": "a5esZu+45LA5mBpvttspPD", "_children": [ { "__id__": 3 }, { "__id__": 5 }, { "__id__": 8 }, { "__id__": 10 } ], "_components": [ { "__id__": 18 }, { "__id__": 19 }, { "__id__": 20 }, { "__id__": 21 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 375, 667, 0, 0, 0, 0, 1, 1, 1, 1 ] }, "_parent": { "__id__": 1 } }, { "__type__": "cc.Node", "_name": "Main Camera", "_parent": { "__id__": 2 }, "_components": [ { "__id__": 4 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 } }, { "__type__": "cc.Camera", "_cullingMask": -31, "_clearFlags": 4, "_depth": -1, "node": { "__id__": 3 } }, { "__type__": "cc.Node", "_name": "Main Camera", "_parent": { "__id__": 2 }, "_components": [ { "__id__": 6 }, { "__id__": 7 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 } }, { "__type__": "cc.Camera", "_cullingMask": -2, "_clearFlags": 7, "_depth": -2, "node": { "__id__": 5 } }, { "__type__": "05b01LKIy1MpJ/22zpE6jci", "node": { "__id__": 5 } }, { "__type__": "cc.Node", "_name": "background", "_parent": { "__id__": 2 }, "_components": [ { "__id__": 9 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1650 } }, { "__type__": "cc.Sprite", "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "node": { "__id__": 8 } }, { "__type__": "cc.Node", "_name": "AIControl", "_parent": { "__id__": 2 }, "_children": [ { "__id__": 11 }, { "__id__": 14 } ], "_components": [ { "__id__": 16 }, { "__id__": 17 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 } }, { "__type__": "cc.Node", "_name": "block", "_parent": { "__id__": 10 }, "_components": [ { "__id__": 12 }, { "__id__": 13 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "node": { "__id__": 11 } }, { "__type__": "cc.BlockInputEvents", "node": { "__id__": 11 } }, { "__type__": "cc.Node", "_name": "模拟鼠标点", "_active": false, "_parent": { "__id__": 10 }, "_components": [ { "__id__": 15 } ], "_contentSize": { "__type__": "cc.Size", "width": 80, "height": 80 } }, { "__type__": "cc.Sprite", "_sizeMode": 0, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "_spriteFrame": { "__uuid__": "f9d4a564-eab2-4b30-807f-44ebc6c3c030" }, "node": { "__id__": 14 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "node": { "__id__": 10 } }, { "__type__": "71c49BSgP9IR7Zj4hKWyzrQ", "blockNode": { "__id__": 11 }, "shuBiaoDian": { "__id__": 14 }, "node": { "__id__": 10 } }, { "__type__": "cc.Canvas", "_fitWidth": true, "_fitHeight": false, "_designResolution": { "__type__": "cc.Size", "width": 750, "height": 1334 }, "node": { "__id__": 2 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "node": { "__id__": 2 } }, { "__type__": "46eeftVLAxEyrbvMwaNsA2p", "node": { "__id__": 2 } }, { "__type__": "da803qpn0xMgrpoqN4fnvfq", "_name": "scene_root", "node": { "__id__": 2 } }, { "__type__": "cc.Node", "_name": "New Node", "_id": "eb9Em8CmRJbLAnaaIWi6pZ", "_parent": { "__id__": 1 }, "_children": [ { "__id__": 23 } ], "_components": [ { "__id__": 28 }, { "__id__": 29 } ], "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 375, 667, 0, 0, 0, 0, 1, 1, 1, 1 ] } }, { "__type__": "cc.Node", "_name": "$node_img", "_children": [ { "__id__": 24 } ], "_components": [ { "__id__": 26 }, { "__id__": 27 } ], "_color": { "__type__": "cc.Color", "a": 255, "b": 0, "g": 0, "r": 0 }, "_contentSize": { "__type__": "cc.Size", "width": 750, "height": 1334 }, "_parent": { "__id__": 22 } }, { "__type__": "cc.Node", "_name": "New Label", "_parent": { "__id__": 23 }, "_components": [ { "__id__": 25 } ], "_contentSize": { "__type__": "cc.Size", "width": 180, "height": 40.32 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 275.821, -642.446, 0, 0, 0, 0, 1, 1, 1, 1 ] } }, { "__type__": "cc.Label", "_string": "加载中。。。", "_fontSize": 30, "_lineHeight": 32, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "node": { "__id__": 24 }, "_N$string": "加载中。。。" }, { "__type__": "cc.Sprite", "_sizeMode": 0, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "_spriteFrame": { "__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91" }, "node": { "__id__": 23 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "_originalWidth": 100, "_originalHeight": 100, "node": { "__id__": 23 } }, { "__type__": "cc.Widget", "_alignFlags": 45, "node": { "__id__": 22 } }, { "__type__": "71237pk2XpDzaXDhWTLOlQW", "auto_ui": { "__type__": "LodingGuodu_UIBindings", "node_img": { "__id__": 23 } }, "node": { "__id__": 22 } }, { "__type__": "cc.Node", "_name": "New Button", "_active": false, "_id": "a9wI4OoQ5E8Z4gjcWqiUNS", "_children": [ { "__id__": 31 } ], "_components": [ { "__id__": 36 }, { "__id__": 37 }, { "__id__": 38 }, { "__id__": 40 } ], "_contentSize": { "__type__": "cc.Size", "width": 100, "height": 80 }, "_trs": { "__type__": "TypedArray", "ctor": "Float64Array", "array": [ 64.436, 49.714, 0, 0, 0, 0, 1, 1, 1, 1 ] }, "_parent": { "__id__": 1 } }, { "__type__": "cc.Node", "_name": "Background", "_objFlags": 512, "_parent": { "__id__": 30 }, "_children": [ { "__id__": 32 } ], "_components": [ { "__id__": 34 }, { "__id__": 35 } ], "_contentSize": { "__type__": "cc.Size", "width": 100, "height": 80 } }, { "__type__": "cc.Node", "_name": "Label", "_objFlags": 512, "_parent": { "__id__": 31 }, "_components": [ { "__id__": 33 } ], "_color": { "__type__": "cc.Color", "a": 255, "b": 0, "g": 0, "r": 0 }, "_contentSize": { "__type__": "cc.Size", "width": 100, "height": 40 } }, { "__type__": "cc.Label", "_string": "查看内存", "_fontSize": 20, "_enableWrapText": false, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$overflow": 1, "_N$cacheMode": 1, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "node": { "__id__": 32 }, "_N$string": "查看内存" }, { "__type__": "cc.Sprite", "_type": 1, "_sizeMode": 0, "_materials": [ { "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" } ], "_spriteFrame": { "__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952" }, "node": { "__id__": 31 } }, { "__type__": "cc.Widget", "alignMode": 0, "_alignFlags": 45, "_originalWidth": 100, "_originalHeight": 40, "node": { "__id__": 31 } }, { "__type__": "cc.Button", "_N$transition": 2, "_N$normalColor": { "__type__": "cc.Color", "a": 255, "b": 230, "g": 230, "r": 230 }, "_N$pressedColor": { "__type__": "cc.Color", "a": 255, "b": 200, "g": 200, "r": 200 }, "_N$disabledColor": { "__type__": "cc.Color", "a": 200, "b": 120, "g": 120, "r": 120 }, "_N$normalSprite": { "__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952" }, "_N$pressedSprite": { "__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a" }, "_N$hoverSprite": { "__uuid__": "f0048c10-f03e-4c97-b9d3-3506e1d58952" }, "_N$disabledSprite": { "__uuid__": "29158224-f8dd-4661-a796-1ffab537140e" }, "_N$target": { "__id__": 31 }, "node": { "__id__": 30 } }, { "__type__": "54bdek3CLtOK7ESMMaON2u0", "node": { "__id__": 30 } }, { "__type__": "cc.Button", "clickEvents": [ { "__id__": 39 } ], "node": { "__id__": 30 } }, { "__type__": "cc.ClickEvent", "_componentId": "54bdek3CLtOK7ESMMaON2u0", "handler": "getImageMemory", "target": { "__id__": 30 } }, { "__type__": "54bdek3CLtOK7ESMMaON2u0", "node": { "__id__": 30 } } ]这个是我的项目入口吗
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值