c++ - How to avoid duplicate code -


as shown in pictures, 2 pieces of code same slight differences. each duplicate might create trouble, if encounter such situations, how supposed solve them?

example 1

example 2

it depends on case.

in general add function knows both ways , return value need in every case.

so in case like

bool myfuction(bool condition, int i, int k) {   if(condition == true)   {     return (i + min_size + k < ck_size);    }   else   {     return (i - min_size - k >= ck_size);   } } 

now can call myfunction(..)

the bool condition condition wether decide use first or second way.


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 -