Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8d2b4d1

Browse filesBrowse files
committed
Add assignment operators.
1 parent 053f03a commit 8d2b4d1
Copy full SHA for 8d2b4d1

File tree

Expand file treeCollapse file tree

1 file changed

+136
-10
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+136
-10
lines changed

‎cores/esp8266/Delegate.h

Copy file name to clipboardExpand all lines: cores/esp8266/Delegate.h
+136-10Lines changed: 136 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ namespace delegate
239239
return *this;
240240
}
241241

242+
template<typename F> DelegatePImpl& operator=(F functional)
243+
{
244+
if (FUNC == kind)
245+
{
246+
this->functional.~FunctionType();
247+
}
248+
else if (FPA == kind)
249+
{
250+
obj.~A();
251+
}
252+
kind = FUNC;
253+
new (&this->functional) FunctionType(std::forward<F>(functional));
254+
return *this;
255+
}
256+
242257
DelegatePImpl& IRAM_ATTR operator=(std::nullptr_t)
243258
{
244259
if (FUNC == kind)
@@ -421,10 +436,10 @@ namespace delegate
421436
DelegatePImpl::fn = fn;
422437
}
423438

424-
template<typename F> DelegatePImpl(F fn)
439+
template<typename F> DelegatePImpl(F functional)
425440
{
426441
kind = FP;
427-
DelegatePImpl::fn = std::forward<F>(fn);
442+
fn = std::forward<F>(functional);
428443
}
429444

430445
DelegatePImpl& operator=(const DelegatePImpl& del)
@@ -484,6 +499,16 @@ namespace delegate
484499
return *this;
485500
}
486501

502+
template<typename F> DelegatePImpl& operator=(F functional)
503+
{
504+
if (FPA == kind)
505+
{
506+
obj = {};
507+
}
508+
kind = FP;
509+
fn = std::forward<F>(functional);
510+
}
511+
487512
DelegatePImpl& IRAM_ATTR operator=(std::nullptr_t)
488513
{
489514
if (FPA == kind)
@@ -683,6 +708,17 @@ namespace delegate
683708
return *this;
684709
}
685710

711+
template<typename F> DelegatePImpl& operator=(F functional)
712+
{
713+
if (FUNC == kind)
714+
{
715+
this->functional.~FunctionType();
716+
}
717+
kind = FUNC;
718+
new (&this->functional) FunctionType(std::forward<F>(functional));
719+
return *this;
720+
}
721+
686722
DelegatePImpl& IRAM_ATTR operator=(std::nullptr_t)
687723
{
688724
if (FUNC == kind)
@@ -823,6 +859,12 @@ namespace delegate
823859
return *this;
824860
}
825861

862+
template<typename F> DelegatePImpl& operator=(F functional)
863+
{
864+
fn = std::forward<F>(functional);
865+
return *this;
866+
}
867+
826868
DelegatePImpl& IRAM_ATTR operator=(std::nullptr_t)
827869
{
828870
fn = nullptr;
@@ -1040,6 +1082,21 @@ namespace delegate
10401082
return *this;
10411083
}
10421084

1085+
template<typename F> DelegateImpl& operator=(F functional)
1086+
{
1087+
if (FUNC == kind)
1088+
{
1089+
this->functional.~FunctionType();
1090+
}
1091+
else if (FPA == kind)
1092+
{
1093+
obj.~A();
1094+
}
1095+
kind = FUNC;
1096+
new (&this->functional) FunctionType(std::forward<F>(functional));
1097+
return *this;
1098+
}
1099+
10431100
DelegateImpl& IRAM_ATTR operator=(std::nullptr_t)
10441101
{
10451102
if (FUNC == kind)
@@ -1284,6 +1341,17 @@ namespace delegate
12841341
return *this;
12851342
}
12861343

1344+
template<typename F> DelegateImpl& operator=(F functional)
1345+
{
1346+
if (FPA == kind)
1347+
{
1348+
obj.~A();
1349+
}
1350+
kind = FP;
1351+
fn = std::forward<F>(functional);
1352+
return *this;
1353+
}
1354+
12871355
DelegateImpl& IRAM_ATTR operator=(std::nullptr_t)
12881356
{
12891357
if (FPA == kind)
@@ -1482,6 +1550,17 @@ namespace delegate
14821550
return *this;
14831551
}
14841552

1553+
template<typename F> DelegateImpl& operator=(F functional)
1554+
{
1555+
if (FUNC == kind)
1556+
{
1557+
this->functional.~FunctionType();
1558+
}
1559+
kind = FUNC;
1560+
new (&this->functional) FunctionType(std::forward<F>(functional));
1561+
return *this;
1562+
}
1563+
14851564
DelegateImpl& IRAM_ATTR operator=(std::nullptr_t)
14861565
{
14871566
if (FUNC == kind)
@@ -1622,6 +1701,12 @@ namespace delegate
16221701
return *this;
16231702
}
16241703

1704+
template<typename F> DelegateImpl& operator=(F functional)
1705+
{
1706+
fn = std::forward<F>(functional);
1707+
return *this;
1708+
}
1709+
16251710
DelegateImpl& IRAM_ATTR operator=(std::nullptr_t)
16261711
{
16271712
fn = nullptr;
@@ -1691,7 +1776,7 @@ namespace delegate
16911776

16921777
Delegate(FunPtr fn) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(fn) {}
16931778

1694-
template<typename F> Delegate(F functional) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(functional) {}
1779+
template<typename F> Delegate(F functional) : detail::DelegatePImpl<A, R, P...>::DelegatePImpl(std::forward<F>(functional)) {}
16951780

16961781
Delegate& operator=(const Delegate& del) {
16971782
detail::DelegatePImpl<A, R, P...>::operator=(del);
@@ -1708,6 +1793,11 @@ namespace delegate
17081793
return *this;
17091794
}
17101795

1796+
template<typename F> Delegate& operator=(F functional) {
1797+
detail::DelegatePImpl<A, R, P...>::operator=(std::forward<F>(functional));
1798+
return *this;
1799+
}
1800+
17111801
Delegate& IRAM_ATTR operator=(std::nullptr_t) {
17121802
detail::DelegatePImpl<A, R, P...>::operator=(nullptr);
17131803
return *this;
@@ -1770,7 +1860,7 @@ namespace delegate
17701860

17711861
Delegate(FunPtr fn) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(fn) {}
17721862

1773-
template<typename F> Delegate(F functional) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(functional) {}
1863+
template<typename F> Delegate(F functional) : detail::DelegatePImpl<A*, R, P...>::DelegatePImpl(std::forward<F>(functional)) {}
17741864

17751865
Delegate& operator=(const Delegate& del) {
17761866
detail::DelegatePImpl<A*, R, P...>::operator=(del);
@@ -1787,6 +1877,11 @@ namespace delegate
17871877
return *this;
17881878
}
17891879

1880+
template<typename F> Delegate& operator=(F functional) {
1881+
detail::DelegatePImpl<A*, R, P...>::operator=(std::forward<F>(functional));
1882+
return *this;
1883+
}
1884+
17901885
Delegate& IRAM_ATTR operator=(std::nullptr_t) {
17911886
detail::DelegatePImpl<A*, R, P...>::operator=(nullptr);
17921887
return *this;
@@ -1826,7 +1921,7 @@ namespace delegate
18261921

18271922
Delegate(FunPtr fn) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(fn) {}
18281923

1829-
template<typename F> Delegate(F functional) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(functional) {}
1924+
template<typename F> Delegate(F functional) : detail::DelegatePImpl<void, R, P...>::DelegatePImpl(std::forward<F>(functional)) {}
18301925

18311926
Delegate& operator=(const Delegate& del) {
18321927
detail::DelegatePImpl<void, R, P...>::operator=(del);
@@ -1843,6 +1938,11 @@ namespace delegate
18431938
return *this;
18441939
}
18451940

1941+
template<typename F> Delegate& operator=(F functional) {
1942+
detail::DelegatePImpl<void, R, P...>::operator=(std::forward<F>(functional));
1943+
return *this;
1944+
}
1945+
18461946
Delegate& IRAM_ATTR operator=(std::nullptr_t) {
18471947
detail::DelegatePImpl<void, R, P...>::operator=(nullptr);
18481948
return *this;
@@ -1887,7 +1987,7 @@ namespace delegate
18871987

18881988
Delegate(FunPtr fn) : detail::DelegateImpl<A, R>::DelegateImpl(fn) {}
18891989

1890-
template<typename F> Delegate(F functional) : detail::DelegateImpl<A, R>::DelegateImpl(functional) {}
1990+
template<typename F> Delegate(F functional) : detail::DelegateImpl<A, R>::DelegateImpl(std::forward<F>(functional)) {}
18911991

18921992
Delegate& operator=(const Delegate& del) {
18931993
detail::DelegateImpl<A, R>::operator=(del);
@@ -1904,6 +2004,11 @@ namespace delegate
19042004
return *this;
19052005
}
19062006

2007+
template<typename F> Delegate& operator=(F functional) {
2008+
detail::DelegateImpl<A, R>::operator=(std::forward<F>(functional));
2009+
return *this;
2010+
}
2011+
19072012
Delegate& IRAM_ATTR operator=(std::nullptr_t) {
19082013
detail::DelegateImpl<A, R>::operator=(nullptr);
19092014
return *this;
@@ -1966,7 +2071,7 @@ namespace delegate
19662071

19672072
Delegate(FunPtr fn) : detail::DelegateImpl<A*, R>::DelegateImpl(fn) {}
19682073

1969-
template<typename F> Delegate(F functional) : detail::DelegateImpl<A*, R>::DelegateImpl(functional) {}
2074+
template<typename F> Delegate(F functional) : detail::DelegateImpl<A*, R>::DelegateImpl(std::forward<F>(functional)) {}
19702075

19712076
Delegate& operator=(const Delegate& del) {
19722077
detail::DelegateImpl<A*, R>::operator=(del);
@@ -1983,6 +2088,11 @@ namespace delegate
19832088
return *this;
19842089
}
19852090

2091+
template<typename F> Delegate& operator=(F functional) {
2092+
detail::DelegateImpl<A*, R>::operator=(std::forward<F>(functional));
2093+
return *this;
2094+
}
2095+
19862096
Delegate& IRAM_ATTR operator=(std::nullptr_t) {
19872097
detail::DelegateImpl<A*, R>::operator=(nullptr);
19882098
return *this;
@@ -2022,7 +2132,7 @@ namespace delegate
20222132

20232133
Delegate(FunPtr fn) : detail::DelegateImpl<void, R>::DelegateImpl(fn) {}
20242134

2025-
template<typename F> Delegate(F functional) : detail::DelegateImpl<void, R>::DelegateImpl(functional) {}
2135+
template<typename F> Delegate(F functional) : detail::DelegateImpl<void, R>::DelegateImpl(std::forward<F>(functional)) {}
20262136

20272137
Delegate& operator=(const Delegate& del) {
20282138
detail::DelegateImpl<void, R>::operator=(del);
@@ -2039,6 +2149,11 @@ namespace delegate
20392149
return *this;
20402150
}
20412151

2152+
template<typename F> Delegate& operator=(F functional) {
2153+
detail::DelegateImpl<void, R>::operator=(std::forward<F>(functional));
2154+
return *this;
2155+
}
2156+
20422157
Delegate& IRAM_ATTR operator=(std::nullptr_t) {
20432158
detail::DelegateImpl<void, R>::operator=(nullptr);
20442159
return *this;
@@ -2067,7 +2182,7 @@ template<typename A, typename R, typename... P> class Delegate<R(P...), A> : pub
20672182

20682183
Delegate(typename delegate::detail::Delegate<A, R, P...>::FunPtr fn) : delegate::detail::Delegate<A, R, P...>::Delegate(fn) {}
20692184

2070-
template<typename F> Delegate(F functional) : delegate::detail::Delegate<A, R, P...>::Delegate(functional) {}
2185+
template<typename F> Delegate(F functional) : delegate::detail::Delegate<A, R, P...>::Delegate(std::forward<F>(functional)) {}
20712186

20722187
Delegate& operator=(const Delegate& del) {
20732188
delegate::detail::Delegate<A, R, P...>::operator=(del);
@@ -2084,11 +2199,17 @@ template<typename A, typename R, typename... P> class Delegate<R(P...), A> : pub
20842199
return *this;
20852200
}
20862201

2202+
template<typename F> Delegate& operator=(F functional) {
2203+
delegate::detail::Delegate<A, R, P...>::operator=(std::forward<F>(functional));
2204+
return *this;
2205+
}
2206+
20872207
Delegate& IRAM_ATTR operator=(std::nullptr_t) {
20882208
delegate::detail::Delegate<A, R, P...>::operator=(nullptr);
20892209
return *this;
20902210
}
20912211
};
2212+
20922213
template<typename R, typename... P> class Delegate<R(P...)> : public delegate::detail::Delegate<void, R, P...>
20932214
{
20942215
public:
@@ -2104,7 +2225,7 @@ template<typename R, typename... P> class Delegate<R(P...)> : public delegate::d
21042225

21052226
Delegate(typename delegate::detail::Delegate<void, R, P...>::FunPtr fn) : delegate::detail::Delegate<void, R, P...>::Delegate(fn) {}
21062227

2107-
template<typename F> Delegate(F functional) : delegate::detail::Delegate<void, R, P...>::Delegate(functional) {}
2228+
template<typename F> Delegate(F functional) : delegate::detail::Delegate<void, R, P...>::Delegate(std::forward<F>(functional)) {}
21082229

21092230
Delegate& operator=(const Delegate& del) {
21102231
delegate::detail::Delegate<void, R, P...>::operator=(del);
@@ -2121,6 +2242,11 @@ template<typename R, typename... P> class Delegate<R(P...)> : public delegate::d
21212242
return *this;
21222243
}
21232244

2245+
template<typename F> Delegate& operator=(F functional) {
2246+
delegate::detail::Delegate<void, R, P...>::operator=(std::forward<F>(functional));
2247+
return *this;
2248+
}
2249+
21242250
Delegate& IRAM_ATTR operator=(std::nullptr_t) {
21252251
delegate::detail::Delegate<void, R, P...>::operator=(nullptr);
21262252
return *this;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.