| 1 |
/*************************************************************************************** |
| 2 |
* This file is dedicated to the public domain. If your jurisdiction requires a * |
| 3 |
* specific license: * |
| 4 |
* * |
| 5 |
* Copyright (c) Stephen McDowell, 2017-2024 * |
| 6 |
* License: CC0 1.0 Universal * |
| 7 |
* License Text: https://creativecommons.org/publicdomain/zero/1.0/legalcode * |
| 8 |
**************************************************************************************/ |
| 9 |
/** |
| 10 |
* \file |
| 11 |
* |
| 12 |
* \brief Various operator overloads to ensure the right signature is parsed. |
| 13 |
*/ |
| 14 |
#pragma once |
| 15 |
#include <ostream> |
| 16 |
|
| 17 |
namespace overload { |
| 18 |
/* NOTE: we need to test that signatures with these symbols work in exhale, so they |
| 19 |
* are not being defined in the class (where relevant). This way they are showing |
| 20 |
* up as free-hanging functions. Exhale does not deal with class definitions, but |
| 21 |
* the free-hanging functions are documented. Primary issue is to make sure |
| 22 |
* treatment of operators with `<` and `>` are handled correctly: |
| 23 |
* https://github.com/svenevs/exhale/issues/168 |
| 24 |
*/ |
| 25 |
|
| 26 |
/// A custom type to enable operator overloads with. |
| 27 |
class CustomType { |
| 28 |
public: |
| 29 |
/// Constructor |
| 30 |
CustomType(int v) : value_{v} {} |
| 31 |
/// Copy |
| 32 |
CustomType(const CustomType &other) : value_{other.value_} {} |
| 33 |
/// Move |
| 34 |
CustomType(const CustomType &&other) : value_{other.value_} {} |
| 35 |
|
| 36 |
/// Returns the value. |
| 37 |
int value() const { return value_; } |
| 38 |
|
| 39 |
protected: |
| 40 |
int value_;///< The value of the custom type. |
| 41 |
}; |
| 42 |
|
| 43 |
/// Doing shenanigans to force a template so I can specialize it. |
| 44 |
template <typename Out, typename T> |
| 45 |
Out& operator<<(Out &out, const T &t) { |
| 46 |
return out << t; |
| 47 |
} |
| 48 |
|
| 49 |
/// Specialized operator << for CustomType |
| 50 |
template <> |
| 51 |
std::ostream& operator<< <std::ostream, CustomType>(std::ostream &out, const CustomType& ct); |
| 52 |
|
| 53 |
/// Operator == |
| 54 |
bool operator==(const CustomType &lhs, const CustomType &rhs); |
| 55 |
|
| 56 |
/// Operator != |
| 57 |
bool operator!=(const CustomType &lhs, const CustomType &rhs); |
| 58 |
|
| 59 |
/// Operator < |
| 60 |
bool operator<(const CustomType &lhs, const CustomType &rhs); |
| 61 |
|
| 62 |
/// Operator > |
| 63 |
bool operator>(const CustomType &lhs, const CustomType &rhs); |
| 64 |
|
| 65 |
/// Operator <= |
| 66 |
bool operator<=(const CustomType &lhs, const CustomType &rhs); |
| 67 |
|
| 68 |
/// Operator >= |
| 69 |
bool operator>=(const CustomType &lhs, const CustomType &rhs); |
| 70 |
|
| 71 |
// TODO: operator<=> when you can get proper C++20 support in CI... |
| 72 |
} // namespace overload |