File: common.hpp

package info (click to toggle)
rapidfuzz-cpp 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,480 kB
  • sloc: cpp: 30,893; python: 63; makefile: 26; sh: 8
file content (75 lines) | stat: -rw-r--r-- 1,612 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once

template <typename T>
class BidirectionalIterWrapper {
public:
    using difference_type = typename T::difference_type;
    using value_type = typename T::value_type;
    using pointer = typename T::pointer;
    using reference = typename T::reference;
    using iterator_category = std::bidirectional_iterator_tag;

    BidirectionalIterWrapper() : iter()
    {}

    BidirectionalIterWrapper(T iter_) : iter(iter_)
    {}

    bool operator==(const BidirectionalIterWrapper& i) const
    {
        return iter == i.iter;
    }

    bool operator!=(const BidirectionalIterWrapper& i) const
    {
        return !(*this == i);
    }

    BidirectionalIterWrapper operator++(int)
    {
        BidirectionalIterWrapper cur(iter);
        ++iter;
        return cur;
    }
    BidirectionalIterWrapper operator--(int)
    {
        BidirectionalIterWrapper cur(iter);
        --iter;
        return cur;
    }

    BidirectionalIterWrapper& operator++()
    {
        ++iter;
        return *this;
    }
    BidirectionalIterWrapper& operator--()
    {
        --iter;
        return *this;
    }

    const value_type& operator*() const
    {
        return *iter;
    }

private:
    T iter;
};

template <typename Iter>
constexpr auto make_bidir(Iter iter) -> BidirectionalIterWrapper<Iter>
{
    return BidirectionalIterWrapper<Iter>(iter);
}

template <typename T, typename = rapidfuzz::rf_enable_if_t<std::is_same<T, char>::value>>
std::basic_string<T> str_multiply(std::basic_string<T> a, size_t b)
{
    std::basic_string<T> output;
    while (b--)
        output += a;

    return output;
}