1#ifndef NE_STL_INCLUDENE_STL_BIND_H
2#define NE_STL_INCLUDENE_STL_BIND_H
32template <
int32_t index>
34namespace placeholders {
46 template <
typename... TArgs>
52 template <int32_t I,
typename T,
typename... TArgs>
54 if (!std::is_base_of<argc_placeholders_base, T>::value) {
62template <
typename TR,
typename TC,
typename TF,
typename TCaptured>
64 template <
typename R,
typename C,
typename... TArgs,
typename TUP, int32_t... Index_1,
typename TUP2, int32_t... Index_2>
71 return (obj->*f)(nstd::tuple_get<Index_1>(tup)..., nstd::tuple_get<Index_2>(tup2)...);
73 template <
typename R,
typename C,
typename... TArgs,
typename... Ts_1,
typename... Ts_2>
77 template <
typename R,
typename C,
typename... TArgs,
typename TUP, int32_t... Index_1,
typename TUP2, int32_t... Index_2>
84 return (obj->*f)(nstd::tuple_get<Index_1>(tup)..., nstd::tuple_get<Index_2>(tup2)...);
86 template <
typename R,
typename C,
typename... TArgs,
typename... Ts_1,
typename... Ts_2>
95 template <
typename... TParams>
99 if constexpr (
sizeof...(params) > 0) {
105 template <
typename... TParams>
109 if constexpr (
sizeof...(params) > 0) {
120template <
typename R,
typename C,
typename... Args,
typename... Params>
122 static_assert(std::is_base_of<nstd::weak_semantics_supporter, C>::value,
"nstd::_weak_semantics_supporter should be base of C");
125template <
typename R,
typename C,
typename... Args,
typename... Params>
126bind_t<R, C, R (C::*)(Args...)
const,
nstd::tuple<Params...>>
bind(R (C::*f)(Args...)
const, C* obj, Params... params) {
127 static_assert(std::is_base_of<nstd::weak_semantics_supporter, C>::value,
"nstd::_weak_semantics_supporter should be base of C");
133template <
typename R,
typename... Args>
136 template <
typename T>
138 template <
typename _R,
typename... _Args>
139 struct _function<_R(_Args...)> {
144 template <
typename Functor>
146 return (*fn)(args...);
148 template <
typename Functor>
149 static void construct_fn(Functor* construct_dst, Functor* construct_src) {
150 new (construct_dst) Functor(*construct_src);
152 template <
typename Functor>
156 memory::safe_delete_container_element(
reinterpret_cast<char*&
>(f));
164 , construct_f(nullptr)
169 , construct_f(nullptr)
172 template <
typename Functor>
174 : invoke_f(reinterpret_cast<
invoke_fn_t>(invoke_fn<Functor>))
175 , construct_f(reinterpret_cast<
construct_fn_t>(construct_fn<Functor>))
176 , data_size(sizeof(Functor)) {
177 this->data_ptr = nstd::make_shared<vector<char>>();
179 this->data_ptr->resize(data_size);
180 this->construct_f((
char*)this->data_ptr->data(),
reinterpret_cast<char*
>(
const_cast<Functor*
>(&f)));
183 : invoke_f(rhs.invoke_f)
184 , construct_f(rhs.construct_f)
185 , data_ptr(rhs.data_ptr)
186 , data_size(rhs.data_size) {}
188 this->invoke_f = rhs.invoke_f;
189 this->construct_f = rhs.construct_f;
190 this->data_size = rhs.data_size;
191 this->data_ptr = rhs.data_ptr;
194 template <
typename Functor>
196 this->invoke_f =
reinterpret_cast<invoke_fn_t>(invoke_fn<Functor>);
197 this->construct_f =
reinterpret_cast<construct_fn_t>(construct_fn<Functor>);
198 this->data_size =
sizeof(Functor);
199 this->data_ptr = nstd::make_shared<vector<char>>();
201 this->data_ptr->resize(data_size);
202 this->construct_f((
char*)this->data_ptr->data(),
reinterpret_cast<char*
>(
const_cast<Functor*
>(&f)));
206 this->invoke_f =
nullptr;
207 this->construct_f =
nullptr;
208 this->data_ptr =
nullptr;
215 inline bool operator==(
const _function& other)
const {
return this->data_ptr == other.data_ptr; }
216 inline bool operator!=(
const _function& other)
const {
return !this->operator==(other); }
217 inline operator bool()
const {
return this->data_ptr !=
nullptr; }
219 if (this->data_ptr.get() !=
nullptr)
220 return this->invoke_f((
char*)this->data_ptr.get()->data(), args...);
227 if (this->data_ptr !=
nullptr)
228 return this->invoke_f((
char*)this->data_ptr.get()->data(), args...);
244 : deref_notify(_deref_notify) {}
246 if (deref_notify !=
nullptr)
256 template <
typename Functor>
263 : __function_(rhs.__function_)
264 , __ref_flag_(rhs.__ref_flag_) {
268 this->__function_ = rhs.__function_;
269 this->__ref_flag_ = rhs.__ref_flag_;
272 template <
typename Functor>
274 this->__function_ = f;
275 this->__ref_flag_ =
nullptr;
279 this->__function_ =
nullptr;
280 this->__ref_flag_ =
nullptr;
286 inline bool operator==(
const function& other)
const {
return this->__function_ == other.__function_; }
288 inline operator bool()
const {
return this->__function_ !=
nullptr; }
290 if (this->__function_ !=
nullptr)
291 return this->__function_(args...);
298 if (this->__function_ !=
nullptr)
299 return this->__function_.operator()(args...);
307 _function<R(Args...)> __function_{
nullptr};
314struct _is_std_function;
317template <
typename... TArgs>
318struct _Has_std_function;
319class _Is_std_function {
320 template <
class TCheck>
321 friend struct traits::_is_std_function;
322 template <
typename... TArgs>
323 friend struct _Has_std_function;
325 static constexpr bool _v() {
326 return _v((T*)(
nullptr));
328 template <
class TR,
class... Args>
333 static constexpr bool _v(T* p) {
337template <
typename... TArgs>
338struct _Has_std_function {};
341template <
typename T,
typename... TArgs>
342struct _Has_std_function<T, TArgs...>
343 :
nstd::conditional<_Is_std_function::_v<typename nstd::remove_cr<T>::type>(), nstd::true_type, _Has_std_function<TArgs...>>::type {};
347struct _is_std_function
348 :
public nstd::conditional<detail::_Is_std_function::_v<typename nstd::remove_cr<T>::type>(), nstd::true_type, nstd::false_type>::type {};
351using _has_std_function = detail::_Has_std_function<T...>;
Definition: ne_stl_continuous_container.h:15
Definition: ne_stl_smart_ptr.h:30
Definition: ne_stl_smart_ptr.h:146
static _argc_placeholder< 7 > _7
Definition: ne_stl_bind.h:41
static _argc_placeholder< 8 > _8
Definition: ne_stl_bind.h:42
static _argc_placeholder< 5 > _5
Definition: ne_stl_bind.h:39
static _argc_placeholder< 9 > _9
Definition: ne_stl_bind.h:43
static _argc_placeholder< 6 > _6
Definition: ne_stl_bind.h:40
static _argc_placeholder< 3 > _3
Definition: ne_stl_bind.h:37
static _argc_placeholder< 1 > _1
Definition: ne_stl_bind.h:35
static _argc_placeholder< 4 > _4
Definition: ne_stl_bind.h:38
static _argc_placeholder< 2 > _2
Definition: ne_stl_bind.h:36
Definition: ne_stl_any.h:7
void(*)(TElement *&) element_delete_fun_t
Definition: ne_stl_memory.h:13
traits::_is_all_standard_layout< T... > is_all_standard_layout
Definition: ne_stl_type_traits.h:86
bind_t< R, C, R(C::*)(Args...), nstd::tuple< Params... > > bind(R(C::*f)(Args...), C *obj, Params... params)
Definition: ne_stl_bind.h:121
struct nstd::_weak_semantics_supporter weak_semantics_supporter
nstd::shared_ptr< T > make_shared(TArgs &&... args)
Definition: ne_stl_smart_ptr.h:209
typename int_sequence_gen< N >::type sequence_t
Definition: ne_stl_tuple.h:24
struct nstd::_weak_flag weak_flag
traits::_is_std_function< T > is_std_function
Definition: ne_stl_bind.h:356
tuple< Type... > make_tuple(const Type &... args)
Definition: ne_stl_tuple.h:66
traits::_has_std_function< T... > has_std_function
Definition: ne_stl_bind.h:358
unsigned char bool
Definition: stdbool.h:25
Definition: ne_stl_bind.h:33
Definition: ne_stl_type_traits.h:9
Definition: ne_stl_bind.h:11
Definition: ne_stl_bind.h:13
nstd::weak_ptr< nstd::weak_flag > get_weak_flag()
Definition: ne_stl_bind.h:15
_weak_semantics_supporter()
Definition: ne_stl_bind.h:14
nstd::shared_ptr< nstd::weak_flag > shared_obj_
Definition: ne_stl_bind.h:18
Definition: ne_stl_bind.h:31
Definition: ne_stl_bind.h:63
bind_t(TF f, TC *obj, const TCaptured ¶ms, const nstd::weak_ptr< nstd::weak_flag > &weak_flag)
Definition: ne_stl_bind.h:90
TR operator()(TParams... params)
Definition: ne_stl_bind.h:96
static R bind_t_call_(R(C::*f)(TArgs...) const, C *obj, const TUP &tup, nstd::int_sequence< Index_1... >, const TUP2 &tup2, nstd::int_sequence< Index_2... >)
Definition: ne_stl_bind.h:78
TR operator()(TParams... params) const
Definition: ne_stl_bind.h:106
static R bind_t_call_(R(C::*f)(TArgs...), C *obj, const TUP &tup, nstd::int_sequence< Index_1... >, const TUP2 &tup2, nstd::int_sequence< Index_2... >)
Definition: ne_stl_bind.h:65
TF functor_
Definition: ne_stl_bind.h:116
TCaptured captured_params_
Definition: ne_stl_bind.h:118
TC * obj_
Definition: ne_stl_bind.h:115
nstd::weak_ptr< nstd::weak_flag > weak_flag_
Definition: ne_stl_bind.h:117
static R bind_t_call(R(C::*f)(TArgs...), C *obj, const nstd::tuple< Ts_1... > &tup, const nstd::tuple< Ts_2... > &tup2)
Definition: ne_stl_bind.h:74
static R bind_t_call(R(C::*f)(TArgs...) const, C *obj, const nstd::tuple< Ts_1... > &tup, const nstd::tuple< Ts_2... > &tup2)
Definition: ne_stl_bind.h:87
Definition: ne_stl_type_traits.h:33
bool operator==(const _function &other) const
Definition: ne_stl_bind.h:215
_function & operator=(std::nullptr_t)
Definition: ne_stl_bind.h:205
~_function()
Definition: ne_stl_bind.h:212
typename result_traits< _R >::type result_type
Definition: ne_stl_bind.h:140
invoke_fn_t invoke_f
Definition: ne_stl_bind.h:234
void(*)(char *) destroy_fn_t
Definition: ne_stl_bind.h:143
_function(const _function &rhs)
Definition: ne_stl_bind.h:182
bool operator!=(const _function &other) const
Definition: ne_stl_bind.h:216
static void construct_fn(Functor *construct_dst, Functor *construct_src)
Definition: ne_stl_bind.h:149
_function()
Definition: ne_stl_bind.h:162
static result_type invoke_fn(Functor *fn, _Args... args)
Definition: ne_stl_bind.h:145
void(*)(char *, char *) construct_fn_t
Definition: ne_stl_bind.h:142
_R operator()(_Args... args)
Definition: ne_stl_bind.h:218
_R operator()(_Args... args) const
Definition: ne_stl_bind.h:226
std::size_t data_size
Definition: ne_stl_bind.h:237
_function & operator=(const _function &rhs)
Definition: ne_stl_bind.h:187
_function(std::nullptr_t)
Definition: ne_stl_bind.h:167
bool operator!=(std::nullptr_t) const
Definition: ne_stl_bind.h:214
_R(*)(char *, _Args...) invoke_fn_t
Definition: ne_stl_bind.h:141
bool operator==(std::nullptr_t) const
Definition: ne_stl_bind.h:213
static void destroy_fn(Functor *&f)
Definition: ne_stl_bind.h:153
_function & operator=(const Functor &f)
Definition: ne_stl_bind.h:195
_function(const Functor &f)
Definition: ne_stl_bind.h:173
construct_fn_t construct_f
Definition: ne_stl_bind.h:235
nstd::shared_ptr< functor_container > data_ptr
Definition: ne_stl_bind.h:236
~_ref_flag()
Definition: ne_stl_bind.h:245
_ref_flag(const deref_notify_t &_deref_notify)
Definition: ne_stl_bind.h:243
deref_notify_t deref_notify
Definition: ne_stl_bind.h:249
R operator()(Args... args) const
Definition: ne_stl_bind.h:297
function & operator=(std::nullptr_t)
Definition: ne_stl_bind.h:278
~function()
Definition: ne_stl_bind.h:283
function()
Definition: ne_stl_bind.h:254
bool operator!=(const function &other) const
Definition: ne_stl_bind.h:287
function(std::nullptr_t)
Definition: ne_stl_bind.h:255
bool operator!=(std::nullptr_t) const
Definition: ne_stl_bind.h:285
bool operator==(const function &other) const
Definition: ne_stl_bind.h:286
function & operator=(const function &rhs)
Definition: ne_stl_bind.h:267
R operator()(Args... args)
Definition: ne_stl_bind.h:289
bool operator==(std::nullptr_t) const
Definition: ne_stl_bind.h:284
function & operator=(const Functor &f)
Definition: ne_stl_bind.h:273
function(const Functor &f, const deref_notify_t &deref_notify=nullptr)
Definition: ne_stl_bind.h:257
function(const function &rhs)
Definition: ne_stl_bind.h:262
Definition: ne_stl_bind.h:132
Definition: ne_stl_tuple.h:12
Definition: ne_stl_bind.h:26
R type
Definition: ne_stl_bind.h:27
Definition: ne_stl_tuple.h:28
Definition: ne_stl_bind.h:45
static void get_i(int32_t &count)
Definition: ne_stl_bind.h:53
static int32_t count(const nstd::tuple< TArgs... > &)
Definition: ne_stl_bind.h:47
static void get_i(int32_t &count)
Definition: ne_stl_bind.h:60
Definition: ne_stl_tuple.h:26
Definition: ne_stl_bind.h:22
T value
Definition: ne_stl_bind.h:23