stdex
Additional custom or not Standard C++ covered algorithms
Loading...
Searching...
No Matches
mapping.hpp
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2023-2024 Amebis
4*/
5
6#pragma once
7
8#include "compat.hpp"
9#include <vector>
10
11namespace stdex
12{
16 template <class T>
17 struct mapping {
18 T from; // index in source string
19 T to; // index in destination string
20
24 mapping() : from(0), to(0) {}
25
31 mapping(_In_ T x) : from(x), to(x) {}
32
39 mapping(_In_ T _from, _In_ T _to) : from(_from), to(_to) {}
40
48 bool operator==(const mapping& other) const { return from == other.from && to == other.to; }
49
57 bool operator!=(const mapping& other) const { return !operator==(other); }
58
66 mapping operator+(_In_ const mapping& other) const
67 {
68 return mapping(from + other.from, to + other.to);
69 }
70 };
71
72 template <class T, class AX = std::allocator<mapping<T>>>
73 using mapping_vector = std::vector<mapping<T>, AX>;
74}
Maps index in source string to index in destination string.
Definition mapping.hpp:17
mapping(T x)
Constructs an id mapping.
Definition mapping.hpp:31
bool operator==(const mapping &other) const
Are mappings identical?
Definition mapping.hpp:48
mapping()
Constructs a zero to zero mapping.
Definition mapping.hpp:24
bool operator!=(const mapping &other) const
Are mappings different?
Definition mapping.hpp:57
mapping operator+(const mapping &other) const
Adds two mappings by components.
Definition mapping.hpp:66
mapping(T _from, T _to)
Constructs a mapping.
Definition mapping.hpp:39