Created
December 10, 2012 14:04
-
-
Save klmr/4250731 to your computer and use it in GitHub Desktop.
C++11 enum classes boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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