Anton Bachin 0f63667106 Overloaded stream operators.
To avoid paying the huge penalty of including iostream and string for
users that don't need those headers, and to avoid creating a second,
optional header file, I resorted to defining the operators as templates
to prevent type checking until the user tries to actually use them. The
stream types and strings are wrapped in a metafunction that depends on
the template parameter. This is basically a hack, but it seems to work.
2015-06-11 23:05:46 -05:00

30 lines
571 B
C++

#include <cxxtest/TestSuite.h>
#include <iostream>
#include <enum.h>
ENUM(Compiler, int, GCC, Clang, MSVC)
class StreamOperatorTests : public CxxTest::TestSuite {
public:
void test_output()
{
std::stringstream stream;
stream << +Compiler::GCC;
TS_ASSERT_EQUALS(strcmp(stream.str().c_str(), "GCC"), 0);
}
void test_input()
{
std::stringstream stream("Clang");
Compiler compiler = Compiler::GCC;
stream >> compiler;
TS_ASSERT_EQUALS(compiler, +Compiler::Clang);
}
};