<commit_before>/*
 * Copyright (C) 2016 <NAME>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef DESCENDU_D_H
#define DESCENDU_D_H

#include <array>
#include <ostream>

namespace descendu
{

enum struct spec { absolute, relative };

template<class CharT, class Traits>
auto& operator<<(std::basic_ostream<CharT,Traits>& os, spec s) {
    switch (s) {
        case spec::absolute: os << "absolute"; break;
        case spec::relative: os << "relative"; break;
        default:             os.setstate(std::ios_base::failbit);
    }
    return os;
}

template <typename N, spec S>
struct d2 {
    union {
        const std::array<N,2> v;
        struct { const N x, y; };
    };

    d2(N x, N y): x(x), y(y) {}
    d2(const std::array<N,2>& o) : v(o.v) {}

    bool operator==(const d2& o) { return x == o.x && y == o.y; }

    bool operator!=(const d2& o) { return !(operator==(o)); }
};

// At least one operand must be spec::relative
template <typename N1, typename N2, spec Result>
auto operator+(const d2<N1,Result>& a, const d2<N2,spec::relative>& b) {
    return d2<decltype(a.x+b.x),Result>(a.x+b.x, a.y+b.y);
}

// At least one operand must be spec::relative
template <typename N1, typename N2, spec Result>
auto operator-(const d2<N1,Result>& a, const d2<N2,spec::relative>& b) {
    return d2<decltype(a.x-b.x),Result>(a.x-b.x, a.y-b.y);
}

template<class CharT, class Traits, typename N, spec Spec>
auto& operator<<(std::basic_ostream<CharT,Traits>& os, const d2<N,Spec>& p) {
    return os << '[' << Spec << ':' << p.x << ',' << p.y << ']';
};

}

#endif<commit_msg>Non-member comparison<commit_after>/*
 * Copyright (C) 2016 <NAME>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef DESCENDU_D_H
#define DESCENDU_D_H

#include <array>
#include <ostream>

namespace descendu
{

enum struct spec { absolute, relative };

template<class CharT, class Traits>
auto& operator<<(std::basic_ostream<CharT,Traits>& os, spec s) {
    switch (s) {
        case spec::absolute: os << "absolute"; break;
        case spec::relative: os << "relative"; break;
        default:             os.setstate(std::ios_base::failbit);
    }
    return os;
}

template <typename N, spec S>
struct d2 {
    union {
        const std::array<N,2> v;
        struct { const N x, y; };
    };

    d2(N x, N y): x(x), y(y) {}
    d2(const std::array<N,2>& o) : v(o.v) {}
};

template <typename N1, typename N2, spec S>
bool operator==(const d2<N1,S>& a, const d2<N2,S>& b) {
    return a.x == b.x && a.y == b.y;
}

template <typename N1, typename N2, spec S>
bool operator!=(const d2<N1,S>& a, const d2<N2,S>& b) {
    return !(a == b);
}

// At least one operand must be spec::relative
template <typename N1, typename N2, spec Result>
auto operator+(const d2<N1,Result>& a, const d2<N2,spec::relative>& b) {
    return d2<decltype(a.x+b.x),Result>(a.x+b.x, a.y+b.y);
}

// At least one operand must be spec::relative
template <typename N1, typename N2, spec Result>
auto operator-(const d2<N1,Result>& a, const d2<N2,spec::relative>& b) {
    return d2<decltype(a.x-b.x),Result>(a.x-b.x, a.y-b.y);
}

template<class CharT, class Traits, typename N, spec Spec>
auto& operator<<(std::basic_ostream<CharT,Traits>& os, const d2<N,Spec>& p) {
    return os << '[' << Spec << ':' << p.x << ',' << p.y << ']';
};

}

#endif
{'fraction_non_alphanumeric': 0.17579092159559834, 'fraction_numerical': 0.01925722145804677, 'mean_word_length': 3.428745432399513, 'pattern_counts': {'":': 0, '<': 91, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2523347', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1364, 'n_words': 397}