YSTest: mixin.hpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

mixin.hpp
浏览该文件的文档.
1 /*
2 © 2014-2016 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_mixin_hpp_
29 #define YB_INC_ystdex_mixin_hpp_ 1
30
31 #include "tuple.hpp" // for for "tuple.hpp", std::tuple, exclude_self_t,
32 // std::get, index_sequence_for, tuple_element_t;
33 #include "utility.hpp" // for classify_value_t;
34
35 namespace ystdex
36 {
37
39
40
44 template<class... _tBases>
45 class mixin : public _tBases...
46 {
47 public:
48 using tuple_type = std::tuple<_tBases...>;
49
50 yconstfn
51 mixin() = default;
52 template<typename _tParam,
53 yimpl(typename = exclude_self_t<mixin, _tParam>)>
54 yconstfn
55 mixin(_tParam&& arg)
56 : _tBases(yforward(arg))...
57 {}
58 template<typename _tParam1, typename _tParam2, typename... _tParams>
59 yconstfn
60 mixin(_tParam1&& arg1, _tParam2&& arg2, _tParams&&... args)
61 : mixin(std::forward_as_tuple(yforward(arg1), yforward(arg2),
62 yforward(args)...))
63 {}
64 template<typename... _tParams>
65 yconstfn
66 mixin(const std::tuple<_tParams...>& tp,
67 yimpl(enable_if_t<(sizeof(tp), sizeof...(_tBases) == 1)>* = {}))
68 : mixin(std::get<0>(tp))
69 {}
70 template<typename... _tParams>
71 yconstfn
72 mixin(std::tuple<_tParams...>&& tp,
73 yimpl(enable_if_t<(sizeof(tp), sizeof...(_tBases) == 1)>* = {}))
74 : mixin(std::get<0>(std::move(tp)))
75 {}
76 template<typename... _tParams>
77 yconstfn
78 mixin(const std::tuple<_tParams...>& tp,
79 yimpl(enable_if_t<(sizeof(tp), sizeof...(_tBases) > 1)>* = {}))
80 : mixin(index_sequence_for<_tParams...>(), tp)
81 {}
82 template<typename... _tParams>
83 yconstfn
84 mixin(std::tuple<_tParams...>&& tp,
85 yimpl(enable_if_t<(sizeof(tp), sizeof...(_tBases) > 1)>* = {}))
86 : mixin(index_sequence_for<_tParams...>(), std::move(tp))
87 {}
88 template<size_t... _vSeq, typename... _tParams>
89 yconstfn
90 mixin(index_sequence<_vSeq...>, const std::tuple<_tParams...>& tp)
91 : _tBases(yforward(std::get<_vSeq>(tp)))...
92 {}
93 template<size_t... _vSeq, typename... _tParams>
94 yconstfn
95 mixin(index_sequence<_vSeq...>, std::tuple<_tParams...>&& tp)
96 : _tBases(yforward(std::get<_vSeq>(tp)))...
97 {}
98 yconstfn
99 mixin(const mixin&) = default;
100 yconstfn
101 mixin(mixin&&) = default;
102
103 tuple_type
104 to_tuple() const
105 {
106 return this->template to_tuple(index_sequence_for<_tBases...>());
107 }
108 template<size_t... _vSeq>
109 tuple_type
110 to_tuple(index_sequence<_vSeq...>) const
111 {
112 return tuple_type(
113 static_cast<const tuple_element_t<_vSeq, tuple_type>&>(*this)...);
114 }
115 };
116
117
123 template<typename... _types>
124 using wrap_mixin_t = mixin<classify_value_t<_types>...>;
126
127 } // namespace ystdex;
128
129 #endif
130
ystdex::mixin::mixin
mixin(index_sequence< _vSeq... >, std::tuple< _tParams... > &&tp)
Definition: mixin.hpp:95
ystdex::mixin::to_tuple
tuple_type to_tuple(index_sequence< _vSeq... >) const
Definition: mixin.hpp:110
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: type_traits.hpp:350
ystdex::mixin::mixin
mixin(_tParam1 &&arg1, _tParam2 &&arg2, _tParams &&...args)
Definition: mixin.hpp:60
utility.hpp
实用设施。
ystdex::mixin::mixin
mixin(const std::tuple< _tParams... > &tp, enable_if_t<(sizeof(tp), sizeof...(_tBases)==1)> *={})
Definition: mixin.hpp:66
ystdex::exclude_self_t
enable_if_t<!is_same< _tClass &, decay_t< _tParam > & >::value, _type > exclude_self_t
移除选择类类型的特定重载避免构造模板和复制/转移特殊成员函数冲突。
Definition: type_traits.hpp:708
ystdex::mixin::mixin
mixin(index_sequence< _vSeq... >, const std::tuple< _tParams... > &tp)
Definition: mixin.hpp:90
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:256
ystdex::mixin::mixin
mixin()=default
std
Definition: memory.hpp:1100
ystdex::mixin::mixin
mixin(const std::tuple< _tParams... > &tp, enable_if_t<(sizeof(tp), sizeof...(_tBases) > 1)> *={})
Definition: mixin.hpp:78
ystdex
特性测试宏。
Definition: ydef.h:796
tuple.hpp
元组类型和操作。
ystdex::mixin::tuple_type
std::tuple< _tBases... > tuple_type
Definition: mixin.hpp:48
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:654
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:969
ystdex::mixin::mixin
mixin(std::tuple< _tParams... > &&tp, enable_if_t<(sizeof(tp), sizeof...(_tBases)==1)> *={})
Definition: mixin.hpp:72
ystdex::mixin::to_tuple
tuple_type to_tuple() const
Definition: mixin.hpp:104
ystdex::mixin
混入对象。
Definition: mixin.hpp:45
ystdex::cpp2014::index_sequence_for
make_index_sequence< sizeof...(_types)> index_sequence_for
Definition: integer_sequence.hpp:237
ystdex::mixin::mixin
mixin(_tParam &&arg)
Definition: mixin.hpp:55
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
ystdex::mixin::mixin
mixin(std::tuple< _tParams... > &&tp, enable_if_t<(sizeof(tp), sizeof...(_tBases) > 1)> *={})
Definition: mixin.hpp:84