1#ifndef MSTL_CORE_ALGORITHM_TYPE_ERASE_HPP__
2#define MSTL_CORE_ALGORITHM_TYPE_ERASE_HPP__
13#include <initializer_list>
28template <
typename Container>
29MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
30decltype(
auto)
begin(Container& cont)
31noexcept(
noexcept(cont.begin())) {
41template <
typename Container>
42MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
43decltype(
auto)
end(Container& cont)
44noexcept(
noexcept(cont.end())) {
54template <
typename Container>
55MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
56decltype(
auto)
begin(
const Container& cont)
57noexcept(
noexcept(cont.begin())) {
67template <
typename Container>
68MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
69decltype(
auto)
end(
const Container& cont)
70noexcept(
noexcept(cont.end())) {
81template <
typename T,
size_t Size>
82MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
83T*
begin(T (&arr)[Size])
noexcept {
95template <
typename T,
size_t Size>
96MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
97T*
end(T (&arr)[Size])
noexcept {
107template <
typename Container>
108MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
109decltype(
auto)
cbegin(
const Container& cont)
noexcept(
noexcept(cont.cbegin())) {
110 return cont.cbegin();
119template <
typename Container>
120MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
121decltype(
auto)
cend(
const Container& cont)
noexcept(
noexcept(cont.cend())) {
132template <
typename T,
size_t Size>
133MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
134const T*
cbegin(T (&arr)[Size])
noexcept {
146template <
typename T,
size_t Size>
147MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
148const T*
cend(T (&arr)[Size])
noexcept {
158template <
typename Container>
159MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
160decltype(
auto)
rbegin(Container& cont)
noexcept(
noexcept(cont.rbegin())) {
161 return cont.rbegin();
170template <
typename Container>
171MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
172decltype(
auto)
rend(Container& cont)
noexcept(
noexcept(cont.rend())) {
182template <
typename Container>
183MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
184decltype(
auto)
rbegin(
const Container& cont)
noexcept(
noexcept(cont.rbegin())) {
185 return cont.rbegin();
194template <
typename Container>
195MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
196decltype(
auto)
rend(
const Container& cont)
noexcept(
noexcept(cont.rend())) {
207template <
typename T,
size_t Size>
208MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
220template <
typename T,
size_t Size>
221MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
233MSTL_NODISCARD
constexpr
245MSTL_NODISCARD
constexpr
256template <
typename Container>
257MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
258decltype(
auto)
crbegin(
const Container& cont)
noexcept(
noexcept(cont.crbegin())) {
259 return cont.crbegin();
268template <
typename Container>
269MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
270decltype(
auto)
crend(
const Container& cont)
noexcept(
noexcept(cont.crend())) {
281template <
typename T,
size_t Size>
282MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
294template <
typename T,
size_t Size>
295MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
306template <
typename Container>
307MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
308decltype(
auto)
size(
const Container& cont)
noexcept(
noexcept(cont.size())) {
319template <
typename T,
size_t Size>
320MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
321size_t size(T (& arr)[Size])
noexcept {
332MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
333size_t size(std::initializer_list<T> lls)
noexcept {
343template <
typename Container>
344MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
345decltype(
auto)
ssize(
const Container& cont)
noexcept(
noexcept(cont.size())) {
357template <
typename T,
size_t Size>
358MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
370MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
381template <
typename Container>
382MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
383bool empty(
const Container& cont)
noexcept(
noexcept(cont.empty())) {
394MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
396 return ptr !=
nullptr;
406MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
407bool empty(std::initializer_list<T> lls)
noexcept {
408 return lls.size() == 0;
417template <
typename Container>
418MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
419decltype(
auto)
data(Container& cont)
420noexcept(
noexcept(cont.data())) {
430template <
typename Container>
431MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
432decltype(
auto)
data(
const Container& cont)
433noexcept(
noexcept(cont.data())) {
444template <
typename T,
size_t Size>
445MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
446T*
data(T (& arr)[Size])
noexcept {
457MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
469MSTL_NODISCARD MSTL_ALWAYS_INLINE
constexpr
470const T*
data(std::initializer_list<T> lls)
noexcept {
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
typename make_signed< T >::type make_signed_t
make_signed的便捷别名
typename common_type< Types... >::type common_type_t
common_type的便捷别名
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr bool empty(const Container &cont) noexcept(noexcept(cont.empty()))
检查容器是否为空
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) ssize(const Container &cont) noexcept(noexcept(cont.size()))
获取容器的有符号大小
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) rend(Container &cont) noexcept(noexcept(cont.rend()))
获取const容器的反向起始迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) end(Container &cont) noexcept(noexcept(cont.end()))
获取容器的结束迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) size(const Container &cont) noexcept(noexcept(cont.size()))
获取容器的大小
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) cend(const Container &cont) noexcept(noexcept(cont.cend()))
获取const容器的const结束迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) begin(Container &cont) noexcept(noexcept(cont.begin()))
获取容器的起始迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) crbegin(const Container &cont) noexcept(noexcept(cont.crbegin()))
获取const容器的const反向起始迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) cbegin(const Container &cont) noexcept(noexcept(cont.cbegin()))
获取const容器的const起始迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) rbegin(Container &cont) noexcept(noexcept(cont.rbegin()))
获取容器的反向起始迭代器
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr decltype(auto) crend(const Container &cont) noexcept(noexcept(cont.crend()))
获取const容器的const反向结束迭代器