YSTest: tuple.hpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

tuple.hpp
浏览该文件的文档.
1 /*
2 © 2013-2016, 2018-2019 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_tuple_hpp_
29 #define YB_INC_ystdex_tuple_hpp_ 1
30
31 #include "apply.hpp" // for <tuple>, "apply.hpp", std::tuple_element_t,
32 // std::tuple_element, std::tuple, index_sequence, integral_constant, size_t_;
33
34 namespace ystdex
35 {
36
37 inline namespace cpp2014
38 {
39
45 #if __cpp_lib_tuple_element_t >= 201402L
46 using std::tuple_element_t;
47 #else
48 template<size_t _vIdx, typename _type>
49 using tuple_element_t = _t<std::tuple_element<_vIdx, _type>>;
50 #endif
51
52
53 } // inline namespace cpp2014;
54
55
57
58 namespace vseq
59 {
60
61 template<typename... _types>
62 struct seq_size<std::tuple<_types...>>
63 : std::tuple_size<std::tuple<_types...>>::type
64 {};
65
66
67 template<typename... _types, size_t... _vIdxSeq>
68 struct project<std::tuple<_types...>, index_sequence<_vIdxSeq...>>
69 {
70 private:
72 using tuple_type = std::tuple<_types...>;
73
74 public:
75 using type = std::tuple<tuple_element_t<_vIdxSeq, tuple_type>...>;
76 };
77
78
79 template<typename _tInt, _tInt... _vSeq1, _tInt... _vSeq2>
80 struct vec_add<std::tuple<integral_constant<_tInt, _vSeq1>...>,
81 std::tuple<integral_constant<_tInt, _vSeq2>...>>
82 {
83 using type = std::tuple<integral_constant<_tInt, _vSeq1 + _vSeq2>...>;
84 };
85
86
87 template<typename _tInt, _tInt... _vSeq1, _tInt... _vSeq2>
88 struct vec_subtract<std::tuple<integral_constant<_tInt, _vSeq1>...>,
89 std::tuple<integral_constant<_tInt, _vSeq2>...>>
90 {
91 using type = std::tuple<integral_constant<_tInt, _vSeq1 - _vSeq2>...>;
92 };
93
94 } // namespace vseq;
96
97
105 static yconstexpr const auto tuple_not_found(size_t(-1));
107
108
109 namespace details
110 {
111
112 template<class _tSize, class _tIndex>
113 using index_conv = size_t_<_tSize::value == _tIndex::value
114 ? tuple_not_found : _tIndex::value>;
115
116 } // namespace details;
117
124 template<typename, class>
125 struct tuple_find;
126
127 template<typename _type, class _tTuple>
128 struct tuple_find<_type, const _tTuple> : tuple_find<_type, _tTuple>
129 {};
130
131 template<typename _type, class _tTuple>
132 struct tuple_find<_type, volatile _tTuple> : tuple_find<_type, _tTuple>
133 {};
134
135 template<typename _type, class _tTuple>
136 struct tuple_find<_type, const volatile _tTuple> : tuple_find<_type, _tTuple>
137 {};
138
139 template<typename _type, typename... _types>
140 struct tuple_find<_type, std::tuple<_types...>>
141 : details::index_conv<vseq::seq_size<std::tuple<_types...>>,
142 vseq::find<std::tuple<_types...>, _type>>
143 {};
144
145 template<typename _type, typename _type1, typename _type2>
146 struct tuple_find<_type, std::pair<_type1, _type2>>
147 : tuple_find<_type, std::tuple<_type1, _type2>>
148 {};
150
151
152 } // namespace ystdex;
153
154 #endif
155
ystdex::details::index_conv
size_t_< _tSize::value==_tIndex::value ? tuple_not_found :_tIndex::value > index_conv
Definition: tuple.hpp:114
ystdex::vseq::seq_size
取序列元素数。
Definition: variadic.hpp:527
ystdex::tuple_not_found
static const auto tuple_not_found(size_t(-1))
表示没有找到的索引。
ystdex::cpp2014::tuple_element_t
_t< std::tuple_element< _vIdx, _type > > tuple_element_t
Definition: tuple.hpp:49
ystdex::vseq::vec_add
序列作为向量的加法。
Definition: variadic.hpp:898
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
ystdex::vseq::vec_subtract< std::tuple< integral_constant< _tInt, _vSeq1 >... >, std::tuple< integral_constant< _tInt, _vSeq2 >... > >::type
std::tuple< integral_constant< _tInt, _vSeq1 - _vSeq2 >... > type
Definition: tuple.hpp:91
ystdex::vseq::project< std::tuple< _types... >, index_sequence< _vIdxSeq... > >::type
std::tuple< tuple_element_t< _vIdxSeq, tuple_type >... > type
Definition: tuple.hpp:75
ystdex::vseq::project
投影操作。
Definition: variadic.hpp:773
ystdex::size_t_
integral_constant< size_t, _vInt > size_t_
Definition: integral_constant.hpp:103
std
Definition: optional.h:982
ystdex::vseq::vec_subtract
序列作为向量的减法。
Definition: variadic.hpp:902
ystdex::vseq::vec_add< std::tuple< integral_constant< _tInt, _vSeq1 >... >, std::tuple< integral_constant< _tInt, _vSeq2 >... > >::type
std::tuple< integral_constant< _tInt, _vSeq1+_vSeq2 >... > type
Definition: tuple.hpp:83
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: meta.hpp:45
ystdex::vseq::project< std::tuple< _types... >, index_sequence< _vIdxSeq... > >::tuple_type
std::tuple< _types... > tuple_type
Definition: tuple.hpp:72
ystdex::cpp2014::integer_sequence
Definition: integer_sequence.hpp:53
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
apply.hpp
元组应用操作。
ystdex::tuple_find
查找类型对应的索引位置，若不存在则为 tuple_not_found 。
Definition: tuple.hpp:125