-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_palind.hpp
64 lines (54 loc) · 1.14 KB
/
is_palind.hpp
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
// algocpp/string/is_palind.hpp
//
// This file is part of algocpp and is copyrighted by algocpp.
// If used, it must comply with the MIT License.
#ifndef ALGOCPP_STRING_ISPALIND
#define ALGOCPP_STRING_ISPALIND
#include <string>
#include <locale>
#include <algocpp/string/wconvert.hpp>
namespace algocpp
{
namespace string
{
namespace base
{
template <typename T>
inline bool base_is_palind(T s) noexcept
{
for (unsigned long long i = 0; i < (unsigned long long)(s.size() / 2); i++)
{
if (s[i] != s[s.size() - i - 1])
{
return false;
}
}
return true;
}
}
inline bool is_palind(std::u32string s) noexcept
{
return base::base_is_palind(s);
}
inline bool is_palind(std::string s) noexcept
{
return base::base_is_palind(s);
}
inline bool is_palind(std::u16string s) noexcept
{
return base::base_is_palind(s);
}
inline bool is_palind(std::wstring s) noexcept
{
return base::base_is_palind(s);
}
// C++20
#if __cplusplus >= 202002LL
inline bool is_palind(std::u8string s) noexcept
{
return base::base_is_palind(s);
}
#endif
}
}
#endif // ALGOCPP_STRING_ISPALIND