Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

scottk IntelligentSolutions com

@scottk IntelligentSolutions com
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Generic C++ object/structure swap
    S scottk IntelligentSolutions com

    I developed a simple object swap template. I simply do a binary swap of the class/structure contents. Yet I know that the developers of the STL libraries do not implement swaps in this way. Their implementation will make copies (via a copy constructor) and then use an assignment operator - "operator=()". The reason I want to do swaps in this manner is because of the obvious efficiencies. For instance, if I wanted to swap two branches of two very large tree structures, the copy and assignment operations become prohibative. My question is in what instances does the code below NOT work? template void ObjectSwap(_Ty &obj1, _Ty &obj2) { // Don't swap on the same object if (&obj1 != &obj2) { char tmp[sizeof(_Ty)]; // create a memory buffer size_t sz = sizeof(_Ty); memcpy((void *) tmp, (const void *) &obj1, sz); memcpy((void *) &obj1, (const void *) &obj2, sz); memcpy((void *) &obj2, (const void *) tmp, sz); } } Scott K

    C / C++ / MFC c++ question data-structures performance
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups