dl
dl_range_sub.h
浏览该文件的文档.
1
12#pragma once
13
15namespace dl::Sub
16{
23template<typename T>
24bool IsSub(const T& a, const T& b)
25{
26 return search(a.begin(), a.end(), b.begin(), b.end()) != a.end();
27}
28
33template<typename T>
34bool IsBegin(const T& a, const T& b)
35{
36 auto iter_a = a.begin();
37 auto iter_b = b.begin();
38 while (iter_b != b.end())
39 {
40 if (iter_a == a.end())
41 return false;
42 if (*iter_b != *iter_a)
43 return false;
44 ++iter_a;
45 ++iter_b;
46 }
47 return true;
48}
49
55template<typename T, typename V>
56T Range(const T& c, const V& a, const V& b)
57{
58 auto iter_a = std::find(c.begin(), c.end(), a);
59 if (iter_a == c.end())
60 return {};
61 ++iter_a;
62 auto iter_b = iter_a;
63
64 while (iter_b != c.end())
65 {
66 if (*iter_b == b)
67 return { iter_a, iter_b };
68 ++iter_b;
69 }
70 return {};
71}
72}
类似子串的操作
Definition: dl_range_sub.h:16
bool IsSub(const T &a, const T &b)
子串匹配
Definition: dl_range_sub.h:24
T Range(const T &c, const V &a, const V &b)
区间匹配
Definition: dl_range_sub.h:56
bool IsBegin(const T &a, const T &b)
子串匹配
Definition: dl_range_sub.h:34