1#ifndef NEFORCE_CORE_ALGORITHM_TYPE_ERASE_HPP__
2#define NEFORCE_CORE_ALGORITHM_TYPE_ERASE_HPP__
12#include <initializer_list>
14NEFORCE_BEGIN_NAMESPACE__
28template <
typename Container>
29NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
30begin(Container& cont)
noexcept(
noexcept(cont.begin())) {
40template <
typename Container>
41NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
end(Container& cont)
noexcept(
noexcept(cont.end())) {
51template <
typename Container>
52NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
53begin(
const Container& cont)
noexcept(
noexcept(cont.begin())) {
63template <
typename Container>
64NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
65end(
const Container& cont)
noexcept(
noexcept(cont.end())) {
76template <
typename T,
size_t Size>
77NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr T*
begin(T (&arr)[Size])
noexcept {
89template <
typename T,
size_t Size>
90NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr T*
end(T (&arr)[Size])
noexcept {
100template <
typename Container>
101NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
102cbegin(
const Container& cont)
noexcept(
noexcept(cont.cbegin())) {
103 return cont.cbegin();
112template <
typename Container>
113NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
114cend(
const Container& cont)
noexcept(
noexcept(cont.cend())) {
125template <
typename T,
size_t Size>
126NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr const T*
cbegin(T (&arr)[Size])
noexcept {
138template <
typename T,
size_t Size>
139NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr const T*
cend(T (&arr)[Size])
noexcept {
149template <
typename Container>
150NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
151rbegin(Container& cont)
noexcept(
noexcept(cont.rbegin())) {
152 return cont.rbegin();
161template <
typename Container>
162NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
rend(Container& cont)
noexcept(
noexcept(cont.rend())) {
172template <
typename Container>
173NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
174rbegin(
const Container& cont)
noexcept(
noexcept(cont.rbegin())) {
175 return cont.rbegin();
184template <
typename Container>
185NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
186rend(
const Container& cont)
noexcept(
noexcept(cont.rend())) {
197template <
typename T,
size_t Size>
209template <
typename T,
size_t Size>
242template <
typename Container>
243NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
244crbegin(
const Container& cont)
noexcept(
noexcept(cont.crbegin())) {
245 return cont.crbegin();
254template <
typename Container>
255NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
256crend(
const Container& cont)
noexcept(
noexcept(cont.crend())) {
267template <
typename T,
size_t Size>
279template <
typename T,
size_t Size>
290template <
typename Container>
291NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
292size(
const Container& cont)
noexcept(
noexcept(cont.size())) {
303template <
typename T,
size_t Size>
304NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr size_t size(T (&arr)[Size])
noexcept {
315NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr size_t size(std::initializer_list<T> lls)
noexcept {
325template <
typename Container>
326NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
327ssize(
const Container& cont)
noexcept(
noexcept(cont.size())) {
339template <
typename T,
size_t Size>
340NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr ptrdiff_t ssize(T (&arr)[Size])
noexcept {
351NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr ptrdiff_t ssize(std::initializer_list<T> lls)
noexcept {
361template <
typename Container>
362NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr bool empty(
const Container& cont)
noexcept(
noexcept(cont.empty())) {
373NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr bool empty(
const T* ptr)
noexcept {
374 return ptr !=
nullptr;
384NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr bool empty(std::initializer_list<T> lls)
noexcept {
385 return lls.size() == 0;
394template <
typename Container>
395NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
data(Container& cont)
noexcept(
noexcept(cont.data())) {
405template <
typename Container>
406NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr decltype(
auto)
407data(
const Container& cont)
noexcept(
noexcept(cont.data())) {
418template <
typename T,
size_t Size>
419NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr T*
data(T (&arr)[Size])
noexcept {
430NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr T*
data(T* ptr)
noexcept {
441NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE
constexpr const T*
data(std::initializer_list<T> lls)
noexcept {
447NEFORCE_END_NAMESPACE__
typename make_signed< T >::type make_signed_t
make_signed的便捷别名
typename common_type< Types... >::type common_type_t
common_type的便捷别名
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) rbegin(Container &cont) noexcept(noexcept(cont.rbegin()))
获取容器的反向起始迭代器
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) crend(const Container &cont) noexcept(noexcept(cont.crend()))
获取const容器的const反向结束迭代器
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) rend(Container &cont) noexcept(noexcept(cont.rend()))
获取const容器的反向起始迭代器
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) begin(Container &cont) noexcept(noexcept(cont.begin()))
获取容器的起始迭代器
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) end(Container &cont) noexcept(noexcept(cont.end()))
获取容器的结束迭代器
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr bool empty(const Container &cont) noexcept(noexcept(cont.empty()))
检查容器是否为空
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) size(const Container &cont) noexcept(noexcept(cont.size()))
获取容器的大小
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) cbegin(const Container &cont) noexcept(noexcept(cont.cbegin()))
获取const容器的const起始迭代器
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) ssize(const Container &cont) noexcept(noexcept(cont.size()))
获取容器的有符号大小
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) cend(const Container &cont) noexcept(noexcept(cont.cend()))
获取const容器的const结束迭代器
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) data(Container &cont) noexcept(noexcept(cont.data()))
获取容器的底层数据指针
NEFORCE_NODISCARD NEFORCE_ALWAYS_INLINE constexpr decltype(auto) crbegin(const Container &cont) noexcept(noexcept(cont.crbegin()))
获取const容器的const反向起始迭代器