Created
December 6, 2012 17:16
-
-
Save nadinengland/4226218 to your computer and use it in GitHub Desktop.
StringBool class useful for debugging when you want to know whether or not it was an int or bool.
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
// | |
// StringBool.hpp | |
// StringBool, Textual Cohesion Bool | |
// | |
// Created by Thomas Nadin on 06/12/2012. | |
// Useful for debugging when you want to know whether or not it was an int or bool. | |
// | |
#ifndef TNADIN_STRING_BOOL_HPP | |
#define TNADIN_STRING_BOOL_HPP | |
#include <iostream> | |
class StringBool { | |
bool value_; | |
public: | |
StringBool(bool value) { | |
value_ = value; | |
} | |
std::string to_string() const { | |
return value_ ? "true" : "false"; | |
} | |
operator bool() const { | |
return value_; | |
} | |
operator std::string() const { | |
return to_string(); | |
} | |
bool operator == (const StringBool& other) const { | |
return value_ == other.value_; | |
} | |
}; | |
std::ostream& operator << (std::ostream& stream, const StringBool& string_bool) { | |
return stream << string_bool.to_string(); | |
} | |
typedef StringBool BOOL; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment