c++ - Adding member field for 3rd library type -


i dealing library contain type (let rectangle) follow:

namespace some_lib{     struct rectangle{         int x;         int y;         int width;         int height;     }; } 

i have vector of rectangles (very huge vector maybe 10^9 rectangle) , want compute area of rectangles , use in many places of program.

i want compute once of course. should store somewhere. can not edit struct. suggested solution:

namespace my_own_program{     struct rectangle_wrapper{         some_lib::rectangle rect;         int area;         operator some_lib::rectangle() const { return rect; }     }; } 

now can store area in structure , if want pass vector library process on it, have casting while copying vector.

i feel method rubbish. solved problem of computing areas casting in each time need process in library seems horrible.

my question:

how can achieve in more better way?

well, if stuck using library , have pass vector many times, i'd suggest creating "shadow vector" holds area each rectangle @ index i. depends on how vector used though. if have high churn rate, not way go, shouldn't use vector in first place anyway.

you can wrap both vectors in custom class use in code access rectangles , pass vector library.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -