[{"data":1,"prerenderedAt":201},["ShallowReactive",2],{"lesson-copies-and-moves":3,"lesson-navigation":180},{"id":4,"title":5,"body":6,"description":145,"extension":146,"label":147,"lessonId":148,"meta":149,"minutes":150,"navigation":151,"order":152,"path":153,"quiz":154,"seo":177,"slug":148,"stem":178,"__hash__":179},"lessons\u002Flessons\u002Fcopies-and-moves.md","Moving is not a magic speed spell.",{"type":7,"value":8,"toc":140},"minimark",[9,14,23,38,67,78,82,93,99,103,109,114,136],[10,11,13],"h2",{"id":12},"the-mess","The mess",[15,16,17,18,22],"p",{},"You ask for faster code. The AI adds ",[19,20,21],"code",{},"std::move"," everywhere. No benchmark, just aggressive punctuation. Performance engineering has apparently become a religion.",[15,24,25,26,30,31,34,35,37],{},"A ",[27,28,29],"strong",{},"copy"," follows the type's copy behavior. A ",[27,32,33],{},"move"," may transfer resources. ",[19,36,21],{}," itself is just a cast that allows move-aware operations to be selected. Writing “MOVE” on a box doesn't carry your sofa.",[39,40,45],"pre",{"className":41,"code":42,"language":43,"meta":44,"style":44},"language-cpp shiki shiki-themes github-light github-dark","std::string draft = \"ship it\";\nstd::string published = std::move(draft);\n\u002F\u002F Assuming draft is empty? That's a guess wearing a lab coat.\n","cpp","",[19,46,47,55,61],{"__ignoreMap":44},[48,49,52],"span",{"class":50,"line":51},"line",1,[48,53,54],{},"std::string draft = \"ship it\";\n",[48,56,58],{"class":50,"line":57},2,[48,59,60],{},"std::string published = std::move(draft);\n",[48,62,64],{"class":50,"line":63},3,[48,65,66],{},"\u002F\u002F Assuming draft is empty? That's a guess wearing a lab coat.\n",[15,68,69,70,73,74,77],{},"Here ",[19,71,72],{},"published"," receives the previous text. ",[19,75,76],{},"draft"," remains valid, but its value is unspecified. Empty isn't promised.",[10,79,81],{"id":80},"the-fix","The fix",[15,83,84,85,88,89,92],{},"Don't assume the old contents survive, either. You can assign a new value or check ",[19,86,87],{},"empty()","; calling ",[19,90,91],{},"front()"," requires a nonempty string. For user-written types, check their contract.",[15,94,95,96,98],{},"Returning by value may already avoid copies. Adding ",[19,97,21],{}," to a named local return can inhibit named return value optimization. Yes, your optimization can sabotage an optimization. Very on-brand.",[10,100,102],{"id":101},"ask-your-ai","Ask your AI",[104,105,106],"blockquote",{},[15,107,108],{},"Which operations copy, move, or allow copy elision? Check every moved-from use. Justify performance changes with measurements.",[15,110,111],{},[27,112,113],{},"“It has move in the name” is not a benchmark.",[15,115,116,117,124,125,124,130,135],{},"Receipts: ",[118,119,123],"a",{"href":120,"rel":121},"https:\u002F\u002Feel.is\u002Fc++draft\u002Flib.types.movedfrom",[122],"nofollow","Moved-from objects"," · ",[118,126,129],{"href":127,"rel":128},"https:\u002F\u002Feel.is\u002Fc++draft\u002Fforward",[122],"Move helpers",[118,131,134],{"href":132,"rel":133},"https:\u002F\u002Feel.is\u002Fc++draft\u002Fclass.copy.elision",[122],"Copy elision",".",[137,138,139],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":44,"searchDepth":57,"depth":57,"links":141},[142,143,144],{"id":12,"depth":57,"text":13},{"id":80,"depth":57,"text":81},{"id":101,"depth":57,"text":102},"Your AI added std::move everywhere. The benchmark? Vibes, apparently.","md","COPIES & MOVES","copies-and-moves",{},"2",true,"5","\u002Flessons\u002Fcopies-and-moves",[155,162,169],{"prompt":156,"options":157,"answer":57,"explanation":161},"What does std::move itself actually do?",[158,159,160],"Transfers the resource immediately.","Destroys the source.","Casts an expression so move-aware operations can be selected.","The selected operation does the work; it can still copy. The cast is a permission slip, not a moving company.",{"prompt":163,"options":164,"answer":51,"explanation":168},"After moving from a string, is it guaranteed empty?",[165,166,167],"Yes: that is what moving means.","No: valid, but its value is unspecified here.","No: it is guaranteed unchanged.","Check preconditions before using it. Assuming empty is still assuming. A confident comment adds no guarantees.",{"prompt":170,"options":171,"answer":175,"explanation":176},"The AI adds std::move to every return. Your response?",[172,173,174],"Check semantics, copy elision, and actual measurements.","Approve: explicit moves always beat copies.","Keep them: redundant moves cannot hurt.",0,"Moving a named local return can inhibit NRVO. You can make code slower with extra effort. A proud engineering tradition.",{"title":5,"description":145},"lessons\u002Fcopies-and-moves","vA4RXv2hZ-4tDOL1HucmVPNu5bhLL9ssVv1hR7J4usI",[181,185,188,192,196,197],{"lessonId":182,"slug":182,"title":183,"order":184},"ownership","Someone has to clean up.","1",{"lessonId":186,"slug":186,"title":187,"order":150},"lifetime","Your pointer outlived its welcome.",{"lessonId":189,"slug":189,"title":190,"order":191},"references-and-pointers","Borrowed doesn’t mean immortal.","3",{"lessonId":193,"slug":193,"title":194,"order":195},"raii","Make cleanup someone’s actual job.","4",{"lessonId":148,"slug":148,"title":5,"order":152},{"lessonId":198,"slug":198,"title":199,"order":200},"undefined-behavior","“It worked” is not a warranty.","6",1789406997109]