YSTest: array.hpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

array.hpp
浏览该文件的文档.
1 /*
2 © 2012-2015, 2018 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_array_hpp_
29 #define YB_INC_ystdex_array_hpp_ 1
30
31 #include "utility.hpp" // for yforward, decay_copy;
32 #include "type_op.hpp" // for common_nonvoid_t;
33 #include <array> // for std::array;
34 #include <algorithm> // for std::copy_n;
35 #include <memory> // for std::addressof;
36 #include <iterator> // for std::make_move_iterator;
37
38 namespace ystdex
39 {
40
52 template<typename _type = void, typename... _tParams>
53 using common_array_t = std::array<common_nonvoid_t<_type, decay_t<_tParams>...>,
54 sizeof...(_tParams)>;
55
56
58 template<typename _type = void, typename... _tParams>
59 yconstfn common_array_t<_type, _tParams...>
60 cast_array(_tParams&&... args)
61 {
62 return {{decay_copy(common_nonvoid_t<_type, _tParams...>(args))...}};
63 }
64
66 template<typename _type = void, typename... _tParams>
67 yconstfn common_array_t<_type, _tParams...>
68 forward_as_array(_tParams&&... args)
69 {
70 return {{yforward(args)...}};
71 }
72
77 template<typename _type = void, typename... _tParams>
78 yconstfn common_array_t<_type, _tParams...>
79 make_array(_tParams&&... args)
80 {
81 return {{decay_copy(args)...}};
82 }
84
90 template<typename _type, size_t _vN, typename _tSrc>
91 yconstfn std::array<_type, _vN>
92 to_array(const _tSrc& src)
93 {
94 return std::array<_type, _vN>(src);
95 }
96 template<typename _type, size_t _vN>
97 yconstfn std::array<_type, _vN>
98 to_array(const std::array<_type, _vN>& src)
99 {
100 return src;
101 }
102 template<typename _type, size_t _vN, typename _tSrcElement>
103 inline std::array<_type, _vN>
104 to_array(const _tSrcElement(&src)[_vN])
105 {
106 std::array<_type, _vN> arr;
107
108 std::copy_n(std::addressof(src[0]), _vN, std::addressof(arr[0]));
109 return arr;
110 }
111 template<typename _type, size_t _vN, typename _tSrcElement>
112 inline std::array<_type, _vN>
113 to_array(_tSrcElement(&&src)[_vN])
114 {
115 std::array<_type, _vN> arr;
116
117 std::copy_n(std::make_move_iterator(std::addressof(src[0])), _vN,
118 std::addressof(arr[0]));
119 return arr;
120 }
122 template<typename _type, size_t _vN, typename _tSrcElement>
123 inline std::array<_type, _vN>
124 to_array(std::initializer_list<_tSrcElement> il)
125 {
126 std::array<_type, il.size()> arr;
127
128 std::copy_n(std::make_move_iterator(il.begin()),
129 std::min(_vN, il.size()), std::addressof(arr[0]));
130 return arr;
131 }
133
134 } // namespace ystdex;
135
136 #endif
137
ystdex::cpp2014::min
const _type & min(const _type &a, const _type &b, _fComp comp=less< _type >())
取较小的元素。
Definition: algorithm.hpp:614
ystdex::common_array_t
std::array< common_nonvoid_t< _type, decay_t< _tParams >... >, sizeof...(_tParams)> common_array_t
取指定类型和参数类型推断的 std::array 实例。
Definition: array.hpp:54
ystdex::make_array
common_array_t< _type, _tParams... > make_array(_tParams &&... args)
构造指定参数初始化的 std::array 对象。
Definition: array.hpp:79
ystdex::common_nonvoid_t
cond_or_t< is_void< _type >, _type, common_type_t, _types... > common_nonvoid_t
取公共非空类型：若第一参数为非空类型则为第一参数，否则从其余参数推断。
Definition: type_op.hpp:274
ystdex::cast_array
common_array_t< _type, _tParams... > cast_array(_tParams &&... args)
构造指定参数转换初始化的 std::array 对象。
Definition: array.hpp:60
CHRLib::args
YB_ATTR_nodiscard _tParams && args
Definition: CharacterProcessing.h:649
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
ystdex::decay_copy
enable_if_convertible_t< _type, decay_t< _type >, decay_t< _type > > decay_copy(_type &&arg)
退化复制。
Definition: utility.hpp:114
YSLib::Drawing::src
src
Definition: YGDI.h:442
ystdex::to_array
std::array< _type, _vN > to_array(const _tSrc &src)
转换指定参数为 std::array 对象。
Definition: array.hpp:92
type_op.hpp
C++ 类型操作。
utility.hpp
实用设施。
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::addressof
enable_if_t< has_no_overloaded_addressof< _type >::value, _type * > addressof(_type &r)
尝试对非重载 operator& 提供 constexpr 的 std::addressof 替代。
Definition: addressof.hpp:131
ystdex::forward_as_array
common_array_t< _type, _tParams... > forward_as_array(_tParams &&... args)
转移指定参数至 std::array 对象。
Definition: array.hpp:68
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073