Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualÁlvaro

Posted 22 May 2013 - 11:20 AM

Oh, here's an alternative that a lot of people won't like, but I am starting to like more and more:

 

bool operator<(const Date &input) const {
  return year  != input.year  ? year  < input.year
       : month != input.month ? month < input.month
       :                        day   < input.day;
}

 

What I like about it is that it's as easy to read as a if-elseif-else construction, but it is clear from the beginning that the only thing we are doing is returning a value.


#2Álvaro

Posted 22 May 2013 - 11:19 AM

Oh, here's an alternative that a lot of people won't like, but I am starting to like more and more:

 

bool operator<(const Date &input) const {
  return year != input.year ? year < input.year
         : month != input.month ? month < input.month
         : day < input.day;
}

 

What I like about it is that it's as easy to read as a if-elseif-else construction, but it is clear from the beginning that the only thing we are doing is returning a value.


#1Álvaro

Posted 22 May 2013 - 11:19 AM

Oh, here's an alternative that a lot of people won't like, but I am starting to like more and more:

bool operator<(const Date &input) const {
  return year != input.year ? year < input.year
         : month != input.month ? month < input.month
        : day < input.day;
}

 

What I like about it is that it's as easy to read as a if-elseif-else construction, but it is clear from the beginning that the only thing we are doing is returning a value.


PARTNERS