YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
mixin.hpp
浏览该文件的文档.
1 /*
2  © 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_mixin_hpp_
29 #define YB_INC_ystdex_mixin_hpp_ 1
30 
31 #include "tuple.hpp" // for std::tuple, ystdex::make_natural_sequence_t,
32 // ystdex::tuple_element_t
33 #include "utility.hpp" // for ../ydef.h, ystdex::classify_value_t;
34 
35 namespace ystdex
36 {
37 
39 
40 /*
41 \brief 混入对象。
42 \warning 非显式虚析构;是否为多态类取决于参数。
43 */
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,
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...(_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...(_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...(_tBases) > 1)>* = {}))
80  : mixin(make_natural_sequence_t<sizeof...(_tParams)>(), tp)
81  {}
82  template<typename... _tParams>
83  yconstfn
84  mixin(std::tuple<_tParams...>&& tp,
85  yimpl(enable_if_t<(sizeof...(_tBases) > 1)>* = {}))
86  : mixin(make_natural_sequence_t<sizeof...(_tParams)>(), std::move(tp))
87  {}
88  template<size_t... _vSeq, typename... _tParams>
89  yconstfn
90  mixin(variadic_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(variadic_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
107  to_tuple(make_natural_sequence_t<sizeof...(_tBases)>());
108  }
109  template<size_t... _vSeq>
110  tuple_type
112  {
113  return tuple_type(
114  static_cast<const tuple_element_t<_vSeq, tuple_type>&>(*this)...);
115  }
116 };
117 
118 
119 namespace details
120 {
121 
122 template<class, class>
124 
125 template<size_t... _vSeq, typename... _types>
126 struct wrap_mixin_helper<variadic_sequence<_vSeq...>, std::tuple<_types...>>
127 {
128  using type = mixin<
129  classify_value_t<tuple_element_t<_vSeq, std::tuple<_types...>>>...>;
130 };
131 
132 } // namespace details;
133 
134 
140 template<typename... _types>
142  make_natural_sequence_t<sizeof...(_types)>, std::tuple<_types...>>::type;
144 
145 } // namespace ystdex;
146 
147 #endif
148 
实用设施。
mixin(const std::tuple< _tParams...> &tp, enable_if_t<(sizeof...(_tBases) > 1)> *={})
Definition: mixin.hpp:78
typename std::tuple_element< _vIdx, _type >::type tuple_element_t
Definition: tuple.hpp:44
yconstfn const string _tParams && args
Definition: Loader.h:111
mixin(variadic_sequence< _vSeq...>, const std::tuple< _tParams...> &tp)
Definition: mixin.hpp:90
mixin(std::tuple< _tParams...> &&tp, enable_if_t<(sizeof...(_tBases) > 1)> *={})
Definition: mixin.hpp:84
mixin(variadic_sequence< _vSeq...>, std::tuple< _tParams...> &&tp)
Definition: mixin.hpp:95
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
#define yimpl(...)
实现标签。
Definition: ydef.h:177
typename details::wrap_mixin_helper< make_natural_sequence_t< sizeof...(_types)>, std::tuple< _types...>>::type wrap_mixin_t
包装为混入类。
Definition: mixin.hpp:142
mixin(const std::tuple< _tParams...> &tp, enable_if_t< sizeof...(_tBases)==1 > *={})
Definition: mixin.hpp:66
变长参数标记的整数序列。
Definition: variadic.hpp:42
tuple_type to_tuple(variadic_sequence< _vSeq...>) const
Definition: mixin.hpp:111
mixin(_tParam1 &&arg1, _tParam2 &&arg2, _tParams &&...args)
Definition: mixin.hpp:60
元组类型和操作。
tuple_type to_tuple() const
Definition: mixin.hpp:104
conditional_t< std::is_class< _type >::value, _type, boxed_value< _type >> classify_value_t
包装非类类型为类类型。
Definition: utility.hpp:244
std::tuple< _tBases...> tuple_type
Definition: mixin.hpp:48
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:463
enable_if_t<!is_same< _tClass &, remove_rcv_t< _tParam > & >::value, _type > exclude_self_ctor_t
移除选择类类型的特定重载避免构造模板和复制/转移构造函数冲突。
Definition: type_op.hpp:766
mixin(_tParam &&arg)
Definition: mixin.hpp:55
mixin()=default
typename enable_if< _bCond, _type >::type enable_if_t
Definition: type_op.hpp:274
mixin(std::tuple< _tParams...> &&tp, enable_if_t< sizeof...(_tBases)==1 > *={})
Definition: mixin.hpp:72
typename make_natural_sequence< _vN >::type make_natural_sequence_t
Definition: variadic.hpp:240