Skip to content

Instantly share code, notes, and snippets.

@klmr
Created December 10, 2012 14:04
Show Gist options
  • Save klmr/4250731 to your computer and use it in GitHub Desktop.
Save klmr/4250731 to your computer and use it in GitHub Desktop.
C++11 enum classes boilerplate
enum class dna_strand : char {
positive = '+',
negative = '-'
};
std::ostream& operator <<(std::ostream& out, dna_strand strand) {
return out << static_cast<char>(strand);
}
std::istream& operator >>(std::istream& in, dna_strand& strand) {
char ch{};
if (not in >> ch)
return in;
if (ch == '+')
strand = dna_strand::positive;
else if (ch == '-')
strand = dna_strand::negative;
else
in.setstate(std::ios::failbit);
return in;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment