mapping: Use member equality operators and document

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2023-07-04 11:07:51 +02:00
parent 1c54745b3b
commit 44975a016f

View File

@ -18,12 +18,43 @@ namespace stdex
T from; // index in source string T from; // index in source string
T to; // index in destination string T to; // index in destination string
///
/// Constructs a zero to zero mapping
///
inline mapping() : from(0), to(0) {} inline mapping() : from(0), to(0) {}
///
/// Constructs an id mapping
///
/// \param[in] x Mapping from and to value
///
inline mapping(_In_ T x) : from(x), to(x) {} inline mapping(_In_ T x) : from(x), to(x) {}
///
/// Constructs a mapping
///
/// \param[in] _from Mapping from value
/// \param[in] _to Mapping to value
///
inline mapping(_In_ T _from, _In_ T _to) : from(_from), to(_to) {} inline mapping(_In_ T _from, _In_ T _to) : from(_from), to(_to) {}
friend bool operator ==(_In_ stdex::mapping<T> const& a, _In_ stdex::mapping<T> const& b) noexcept { return a.from == b.from && a.to == b.to; } ///
friend bool operator !=(_In_ stdex::mapping<T> const& a, _In_ stdex::mapping<T> const& b) noexcept { return !(a == b); } /// Are mappings identical?
///
/// \param[in] other Other mapping to compare against
///
/// \returns true if mappings are identical or false otherwise
///
inline bool operator==(const mapping& other) const { return from == other.from && to == other.to; }
///
/// Are mappings different?
///
/// \param[in] other Other mapping to compare against
///
/// \returns true if mappings are different or false otherwise
///
inline bool operator!=(const mapping& other) const { return !operator==(other); }
}; };
template <class T, class _Alloc = std::allocator<mapping<T>>> template <class T, class _Alloc = std::allocator<mapping<T>>>