YSTest: mixin.hpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

mixin.hpp
浏览该文件的文档.
1 /*
2 © 2014-2016, 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_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, yimpl(typename
65 = enable_if_t<(sizeof...(_tBases) == sizeof...(_tParams))>)>
66 yconstfn
67 mixin(const std::tuple<_tParams...>& tp)
68 : mixin(index_sequence_for<_tParams...>(), tp)
69 {}
70 template<typename... _tParams, yimpl(typename
71 = enable_if_t<(sizeof...(_tBases) == sizeof...(_tParams))>)>
72 yconstfn
73 mixin(std::tuple<_tParams...>&& tp)
74 : mixin(index_sequence_for<_tParams...>(), std::move(tp))
75 {}
76 template<size_t... _vSeq, typename... _tParams>
77 yconstfn
78 mixin(index_sequence<_vSeq...>, const std::tuple<_tParams...>& tp)
79 : _tBases(yforward(std::get<_vSeq>(tp)))...
80 {}
81 template<size_t... _vSeq, typename... _tParams>
82 yconstfn
83 mixin(index_sequence<_vSeq...>, std::tuple<_tParams...>&& tp)
84 : _tBases(yforward(std::get<_vSeq>(tp)))...
85 {}
86 yconstfn
87 mixin(const mixin&) = default;
88 yconstfn
89 mixin(mixin&&) = default;
90
91 tuple_type
92 to_tuple() const
93 {
94 return this->template to_tuple(index_sequence_for<_tBases...>());
95 }
96 template<size_t... _vSeq>
97 tuple_type
98 to_tuple(index_sequence<_vSeq...>) const
99 {
100 return tuple_type(
101 static_cast<const tuple_element_t<_vSeq, tuple_type>&>(*this)...);
102 }
103 };
104
105
111 template<typename... _types>
112 using wrap_mixin_t = mixin<classify_value_t<_types>...>;
114
115 } // namespace ystdex;
116
117 #endif
118
ystdex::mixin::tuple_type
std::tuple< _tBases... > tuple_type
Definition: mixin.hpp:48
ystdex::mixin::mixin
mixin(index_sequence< _vSeq... >, std::tuple< _tParams... > &&tp)
Definition: mixin.hpp:83
ystdex::cpp2014::tuple_element_t
_t< std::tuple_element< _vIdx, _type > > tuple_element_t
Definition: tuple.hpp:49
ystdex::mixin::mixin
mixin(std::tuple< _tParams... > &&tp)
Definition: mixin.hpp:73
ystdex::cpp2014::index_sequence_for
make_index_sequence< sizeof...(_types)> index_sequence_for
Definition: integer_sequence.hpp:308
tuple.hpp
元组类型和操作。
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: meta.hpp:199
ystdex::mixin::mixin
mixin(mixin &&)=default
ystdex::mixin::mixin
mixin(_tParam1 &&arg1, _tParam2 &&arg2, _tParams &&... args)
Definition: mixin.hpp:60
ystdex::mixin
混入对象。
Definition: mixin.hpp:46
ystdex::mixin::mixin
mixin()=default
ystdex::mixin::mixin
mixin(const mixin &)=default
CHRLib::args
YB_ATTR_nodiscard _tParams && args
Definition: CharacterProcessing.h:649
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
std
Definition: optional.h:982
ystdex::mixin::mixin
mixin(_tParam &&arg)
Definition: mixin.hpp:55
utility.hpp
实用设施。
ystdex::exclude_self_t
enable_if_t<!is_same_param< _tSelected, _tParam >::value, _type > exclude_self_t
排除选择类型的特定参数的重载。
Definition: meta.hpp:865
ystdex::mixin::mixin
mixin(const std::tuple< _tParams... > &tp)
Definition: mixin.hpp:67
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::cpp2014::integer_sequence
Definition: integer_sequence.hpp:53
ystdex::mixin::mixin
mixin(index_sequence< _vSeq... >, const std::tuple< _tParams... > &tp)
Definition: mixin.hpp:78
ystdex::mixin::to_tuple
tuple_type to_tuple(index_sequence< _vSeq... >) const
Definition: mixin.hpp:98
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:413
ystdex::mixin::to_tuple
tuple_type to_tuple() const
Definition: mixin.hpp:92
NPL::get
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(NPL ref get()
Definition: NPLA.h:1737
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
NPL::_tParam
_tParam
Definition: NPLA.h:2367