Skip to content

Add boolean cast operator #3

@tsmanner

Description

@tsmanner

A boolean cast operator for ConditionalOStream may help make it easier to easily support optionally calling functions which take a std::ostream as an argument.

void myFunction(std::ostream &os) {
  os << "myFunction called!\n";
}

int main() {
  ConditionalOStream cstream { std::cout };
  if (cstream) {
    myFunction(*cstream.mOStream);
  }
  return 0;
}

Or, if it also has a get method for the ostream reference:

void myFunction(std::ostream &os) {
  os << "myFunction called!\n";
}

int main() {
  ConditionalOStream cstream { std::cout };
  if (cstream) {
    myFunction(cstream.get());
  }
  return 0;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions