YSTest: tuple.hpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

tuple.hpp
浏览该文件的文档.
1 /*
2 © 2013-2015 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 "integer_sequence.hpp" // for "integer_sequence.hpp", vseq::defer,
32 // index_sequence;
33 #include <tuple>
34
35 namespace ystdex
36 {
37
38 inline namespace cpp2014
39 {
40
46 #if __cpp_lib_tuple_element_t >= 201402 || __cplusplus > 201103L
47 using std::tuple_element_t;
48 #else
49 template<size_t _vIdx, typename _type>
50 using tuple_element_t = _t<std::tuple_element<_vIdx, _type>>;
51 #endif
52
53
54 } // inline namespace cpp2014;
55
56
58
59 namespace vseq
60 {
61
62 template<typename... _types>
63 struct seq_size<std::tuple<_types...>>
64 : std::tuple_size<std::tuple<_types...>>::type
65 {};
66
67
68 template<typename... _types, size_t... _vIdxSeq>
69 struct project<std::tuple<_types...>, index_sequence<_vIdxSeq...>>
70 {
71 private:
73 using tuple_type = std::tuple<_types...>;
74
75 public:
76 #if YB_IMPL_MSCPP
77 using type = std::tuple<typename
79 std::tuple_element<_vIdxSeq, tuple_type>::type...>;
80 #else
81 using type = std::tuple<tuple_element_t<_vIdxSeq, tuple_type>...>;
82 #endif
83 };
84
85
86 template<typename _tInt, _tInt... _vSeq1, _tInt... _vSeq2>
87 struct vec_add<std::tuple<integral_constant<_tInt, _vSeq1>...>,
88 std::tuple<integral_constant<_tInt, _vSeq2>...>>
89 {
90 using type = std::tuple<integral_constant<_tInt, _vSeq1 + _vSeq2>...>;
91 };
92
93
94 template<typename _tInt, _tInt... _vSeq1, _tInt... _vSeq2>
95 struct vec_subtract<std::tuple<integral_constant<_tInt, _vSeq1>...>,
96 std::tuple<integral_constant<_tInt, _vSeq2>...>>
97 {
98 using type = std::tuple<integral_constant<_tInt, _vSeq1 - _vSeq2>...>;
99 };
100
101 } // namespace vseq;
103
104
110 static yconstexpr const auto tuple_not_found(size_t(-1));
112
113
114 namespace details
115 {
116
117 template<class _tSize, class _tIndex>
118 using index_conv = integral_constant<size_t,
119 _tSize::value == _tIndex::value ? tuple_not_found : _tIndex::value>;
120
121 } // namespace details;
122
129 template<typename, class>
130 struct tuple_find;
131
132 template<typename _type, class _tTuple>
133 struct tuple_find<_type, const _tTuple> : tuple_find<_type, _tTuple>
134 {};
135
136 template<typename _type, class _tTuple>
137 struct tuple_find<_type, volatile _tTuple> : tuple_find<_type, _tTuple>
138 {};
139
140 template<typename _type, class _tTuple>
141 struct tuple_find<_type, const volatile _tTuple> : tuple_find<_type, _tTuple>
142 {};
143
144 template<typename _type, typename... _types>
145 struct tuple_find<_type, std::tuple<_types...>>
146 : details::index_conv<vseq::seq_size<std::tuple<_types...>>,
147 vseq::find<std::tuple<_types...>, _type>>
148 {};
149
150 template<typename _type, typename _type1, typename _type2>
151 struct tuple_find<_type, std::pair<_type1, _type2>>
152 : tuple_find<_type, std::tuple<_type1, _type2>>
153 {};
155
156
157 } // namespace ystdex;
158
159 #endif
160
ystdex::vseq::vec_add
序列作为向量的加法。
Definition: variadic.hpp:817
ystdex::vseq::vec_subtract
序列作为向量的减法。
Definition: variadic.hpp:821
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:90
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
ystdex::tuple_not_found
static const auto tuple_not_found(size_t(-1))
表示没有找到的索引。
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:98
integer_sequence.hpp
整数序列元编程接口。
platform::size_t
YF_API size_t
Definition: FileIO.h:1262
ystdex::cpp2014::tuple_element_t
_t< std::tuple_element< _vIdx, _type >> tuple_element_t
Definition: tuple.hpp:50
ystdex::cpp2014::index_sequence
integer_sequence< size_t, _vSeq... > index_sequence
Definition: integer_sequence.hpp:63
std
Definition: memory.hpp:1100
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: type_traits.hpp:96
ystdex::vseq::project< std::tuple< _types... >, index_sequence< _vIdxSeq... > >::type
std::tuple< tuple_element_t< _vIdxSeq, tuple_type >... > type
Definition: tuple.hpp:81
ystdex::vseq::project< std::tuple< _types... >, index_sequence< _vIdxSeq... > >::tuple_type
std::tuple< _types... > tuple_type
Definition: tuple.hpp:73
vseq
ystdex::vseq::project
投影操作。
Definition: variadic.hpp:692
ystdex
特性测试宏。
Definition: ydef.h:796
ystdex::vseq::seq_size
取序列元素数。
Definition: variadic.hpp:445
ystdex::tuple_find
查找类型对应的索引位置，若不存在则为 tuple_not_found 。
Definition: tuple.hpp:130
ystdex::details::index_conv
integral_constant< size_t, _tSize::value==_tIndex::value?tuple_not_found:_tIndex::value > index_conv
Definition: tuple.hpp:119