Overloading the << operator.

Outside Class definition.

std::ostream& operator<<(std::ostream& os, const QualifierEnum qe) {
    switch(qe) {
        case QualifierEnum::Pass: os << ""; break;
        case QualifierEnum::Fail: os << "-"; break;
        case QualifierEnum::SoftFail: os << "~"; break;
        case QualifierEnum::Neutral: os << "?"; break;
    return os;

Within a Class definition.

Header File

class Sample {
    friend std::ostream& operator<<(std::ostream& os, Qualifier const &qualifier);

Here we use friend to prevent the compiler from complaining about the number of arguments.

Source File

std::ostream& operator<<(std::ostream& os, Qualifier const& qualifier) {
    if (qualifier.is_pass()) return os << "";
    return os << static_cast<char>(qualifier._value);

Rust: Move from binary to library and Add Documentation Examples that are tested.

In the previous article in this series I went through some basics of documenting your rust code. I had hoped to be able to take advantage of another nice feature of rust. That being the fact that code examples are actually tested by rust. I will go through the changes I had to make for this to work.

[Read More]