Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualAndy Gainey

Posted 28 July 2014 - 08:55 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:
Class::Class()
{
  std::fill(array, array + 2, false);
}
 
At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.

#4Andy Gainey

Posted 28 July 2014 - 08:54 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:

Class::Class()
{
  std::fill(array, array + 2, false);
}

At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.


#3Andy Gainey

Posted 28 July 2014 - 08:53 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:

Class::Class()
{
  std::fill(array, array + 2, false);
}

At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.


#2Andy Gainey

Posted 28 July 2014 - 08:53 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:

Class::Class()
{
  std::fill(array, array + 2, false);
}

At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.


#1Andy Gainey

Posted 28 July 2014 - 08:53 AM

std::fill() would be a standard and clear way to specify intent when initializing an array:

Class::Class()
{
  std::fill(array, array + 2, false);
}

At the same time, I wonder if a two-element array is actually appropriate, rather than two separately named bools.  If you have multiple two-element arrays, it might be cleaner to wrap one element of each into a struct, and then just have a single two-element array of the struct.  Each instance of the struct could then have its own default constructor that would initialize the bool to false, and any other variables to their proper defaults also.


PARTNERS