YSTest: tuple.hpp 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
tuple.hpp
浏览该文件的文档.
1 /*
2 © 2013-2014 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 "../ydef.h"
32 #include "type_op.hpp"
33 #include "variadic.hpp"
34 #include <tuple>
35
36 namespace ystdex
37 {
38
43 template<size_t _vIdx, typename _type>
44 using tuple_element_t = typename std::tuple_element<_vIdx, _type>::type;
45
46
48
49 namespace details
50 {
51
52 template<class, class, class>
53 struct tuple_element_convertible;
54
55 template<class _type1, class _type2>
56 struct tuple_element_convertible<_type1, _type2, variadic_sequence<>>
57 : true_type
58 {};
59
60 template<typename... _types1, typename... _types2, size_t... _vSeq,
61 size_t _vHead>
62 struct tuple_element_convertible<std::tuple<_types1...>, std::tuple<_types2...>,
63 variadic_sequence<_vHead, _vSeq...>>
64 {
65 static_assert(sizeof...(_types1) == sizeof...(_types2),
66 "Mismatched sizes of tuple found.");
67
68 private:
69 using t1 = std::tuple<_types1...>;
70 using t2 = std::tuple<_types2...>;
71
72 public:
73 static yconstexpr bool value = std::is_convertible<
74 sequence_element_t<_vHead, t1>, sequence_element_t<_vHead, t2>>::value
75 && tuple_element_convertible<t1, t2, variadic_sequence<_vSeq...>>
76 ::value;
77 };
78
79 } // namespace details;
80
81
82 template<typename... _tFroms, typename... _tTos>
83 struct is_covariant<std::tuple<_tFroms...>, std::tuple<_tTos...>>
84 : integral_constant<bool, details::tuple_element_convertible<
85 std::tuple<_tFroms...>, std::tuple<_tTos...>,
86 make_natural_sequence_t<sizeof...(_tTos)>>::value>
87 {};
88
89
90 template<typename... _tFroms, typename... _tTos>
91 struct is_contravariant<std::tuple<_tFroms...>, std::tuple<_tTos...>>
92 : integral_constant<bool, details::tuple_element_convertible<
93 std::tuple<_tTos...>, std::tuple<_tFroms...>,
94 make_natural_sequence_t<sizeof...(_tTos)>>::value>
95 {};
96
97
98 template<typename... _types1, typename... _types2>
99 struct sequence_cat<std::tuple<_types1...>, std::tuple<_types2...>>
100 {
101 using type = std::tuple<_types1..., _types2...>;
102 };
103
104
105 template<size_t _vIdx, typename... _types>
106 struct sequence_element<_vIdx, std::tuple<_types...>>
107 : std::tuple_element<_vIdx, std::tuple<_types...>>
108 {};
109
110
111 template<typename... _types, size_t... _vIdxSeq>
112 struct sequence_project<std::tuple<_types...>, variadic_sequence<_vIdxSeq...>>
113 {
114 using type
115 = std::tuple<tuple_element_t<_vIdxSeq, std::tuple<_types...>>...>;
116 };
117
118
119 template<typename... _types>
120 struct sequence_reverse<std::tuple<_types...>>
121 {
122 private:
123 using tuple_type = std::tuple<_types...>;
124
125 public:
126 using type = sequence_project_t<tuple_type, sequence_reverse_t<
127 make_natural_sequence_t<std::tuple_size<tuple_type>::value>>>;
128 };
130
131
133 template<typename _tHead, typename... _tTail>
134 struct sequence_split<std::tuple<_tHead, _tTail...>>
135 {
136 using type = _tHead;
137 using tail = std::tuple<_tTail...>;
138 };
139
140 } // namespace ystdex;
141
142 #endif
143
ystdex::sequence_project_t
typename sequence_project< _tSeq, _tIdxSeq >::type sequence_project_t
Definition: variadic.hpp:165
ystdex::tuple_element_t
typename std::tuple_element< _vIdx, _type >::type tuple_element_t
Definition: tuple.hpp:44
variadic.hpp
C++ 变长参数相关操作。
ystdex::sequence_element
取序列元素。
Definition: variadic.hpp:121
ystdex::sequence_split< std::tuple< _tHead, _tTail...> >::type
_tHead type
Definition: tuple.hpp:136
ystdex::details::tuple_element_convertible< std::tuple< _types1...>, std::tuple< _types2...>, variadic_sequence< _vHead, _vSeq...> >::t1
std::tuple< _types1...> t1
Definition: tuple.hpp:69
ystdex::sequence_reverse< std::tuple< _types...> >::type
sequence_project_t< tuple_type, sequence_reverse_t< make_natural_sequence_t< std::tuple_size< tuple_type >::value >>> type
Definition: tuple.hpp:127
ystdex::sequence_reverse_t
typename sequence_reverse< _tSeq >::type sequence_reverse_t
Definition: variadic.hpp:187
ystdex::variadic_sequence
变长参数标记的整数序列。
Definition: variadic.hpp:42
ystdex::is_covariant
判断指定类型之间是否协变。
Definition: type_op.hpp:379
ystdex::sequence_split< std::tuple< _tHead, _tTail...> >::tail
std::tuple< _tTail...> tail
Definition: tuple.hpp:137
ystdex::sequence_cat< std::tuple< _types1...>, std::tuple< _types2...> >::type
std::tuple< _types1..., _types2...> type
Definition: tuple.hpp:101
ystdex::sequence_cat
合并序列。
Definition: variadic.hpp:101
ystdex::sequence_split
拆分序列。
Definition: variadic.hpp:78
ystdex::sequence_reverse< std::tuple< _types...> >::tuple_type
std::tuple< _types...> tuple_type
Definition: tuple.hpp:123
ystdex::details::tuple_element_convertible< std::tuple< _types1...>, std::tuple< _types2...>, variadic_sequence< _vHead, _vSeq...> >::t2
std::tuple< _types2...> t2
Definition: tuple.hpp:70
ystdex::sequence_element_t
typename sequence_element< _vIdx, _tSeq >::type sequence_element_t
Definition: variadic.hpp:124
ystdex::sequence_project
投影操作。
Definition: variadic.hpp:162
ystdex::is_contravariant
判断指定类型之间是否逆变。
Definition: type_op.hpp:389
ystdex::sequence_project< std::tuple< _types...>, variadic_sequence< _vIdxSeq...> >::type
std::tuple< tuple_element_t< _vIdxSeq, std::tuple< _types...>>...> type
Definition: tuple.hpp:115
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
type_op.hpp
C++ 类型操作。
ystdex::details::tuple_element_convertible
Definition: tuple.hpp:53
ystdex::sequence_reverse
取逆序列。
Definition: variadic.hpp:184
ystdex::make_natural_sequence_t
typename make_natural_sequence< _vN >::type make_natural_sequence_t
Definition: variadic.hpp:240