-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathrocket.hpp
3763 lines (3121 loc) · 113 KB
/
rocket.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************************
* rocket - lightweight & fast signal/slots & utility library *
* *
* v2.0 - public domain *
* no warranty is offered or implied; use this code at your own risk *
* *
* AUTHORS *
* *
* Written by Michael Bleis *
* *
* *
* LICENSE *
* *
* This software is dual-licensed to the public domain and under the following *
* license: you are granted a perpetual, irrevocable license to copy, modify, *
* publish, and distribute this file as you see fit. *
***********************************************************************************/
#ifndef ROCKET_HPP_INCLUDED
#define ROCKET_HPP_INCLUDED
/***********************************************************************************
* CONFIGURATION *
* ------------------------------------------------------------------------------- *
* Define this if your compiler doesn't support std::optional. *
* ------------------------------------------------------------------------------- */
#ifndef ROCKET_NO_STD_OPTIONAL
// #define ROCKET_NO_STD_OPTIONAL
#endif
/***********************************************************************************
* ------------------------------------------------------------------------------- *
* Define this if you want to disable exceptions. *
* ------------------------------------------------------------------------------- */
#ifndef ROCKET_NO_EXCEPTIONS
// #define ROCKET_NO_EXCEPTIONS
#endif
/***********************************************************************************
* ------------------------------------------------------------------------------- *
* Define this if you want to disable `set_timeout` and `set_interval` features. *
* ------------------------------------------------------------------------------- */
#ifndef ROCKET_NO_TIMERS
// #define ROCKET_NO_TIMERS
#endif
/***********************************************************************************
* ------------------------------------------------------------------------------- *
* Define this if you want to disable the connection blocking feature. *
* ------------------------------------------------------------------------------- */
#ifndef ROCKET_NO_BLOCKING_CONNECTIONS
// #define ROCKET_NO_BLOCKING_CONNECTIONS
#endif
/***********************************************************************************
* ------------------------------------------------------------------------------- *
* Redefine this if your compiler doesn't support the `thread_local`-keyword. *
* For Visual Studio < 2015 you can define it to `__declspec(thread)` for example. *
* ------------------------------------------------------------------------------- */
#ifndef ROCKET_THREAD_LOCAL
#define ROCKET_THREAD_LOCAL thread_local
#endif
/***********************************************************************************
* ------------------------------------------------------------------------------- *
* Redefine this if your compiler doesn't support the `noexcept`-keyword. *
* For Visual Studio < 2015 you can define it to `throw()` for example. *
* ------------------------------------------------------------------------------- */
#ifndef ROCKET_NOEXCEPT
#define ROCKET_NOEXCEPT noexcept
#endif
/***********************************************************************************
* USAGE *
* ------------------------------------------------------------------------------- *
* 1. Creating your first signal *
* ------------------------------------------------------------------------------- *
#include <iostream>
int main() {
rocket::signal<void()> my_signal;
// Connecting the first handler to our signal
my_signal.connect([]() {
std::cout << "First handler called!" << std::endl;
});
// Connecting a second handler to our signal using alternative syntax
my_signal += []() {
std::cout << "Second handler called!" << std::endl;
};
// Invoking the signal
my_signal();
}
// Output:
// First handler called!
// Second handler called!
* ------------------------------------------------------------------------------- *
* 2. Passing arguments to the signal *
* ------------------------------------------------------------------------------- *
#include <string>
#include <iostream>
int main() {
rocket::signal<void(std::string)> my_signal;
my_signal.connect([](const std::string& argument) {
std::cout << "Handler called with arg: " << argument << std::endl;
});
my_signal("Hello world");
}
// Output:
// Handler called with arg: Hello world
* ------------------------------------------------------------------------------- *
* 3. Connecting class methods to the signal *
* ------------------------------------------------------------------------------- *
#include <string>
#include <iostream>
class Subject {
public:
void setName(const std::string& newName) {
if (name != newName) {
name = newName;
nameChanged(newName);
}
}
public:
rocket::signal<void(std::string)> nameChanged;
private:
std::string name;
};
class Observer {
public:
Observer(Subject& subject) {
// Register the `onNameChanged`-function of this object as a listener and
// store the resultant connection object in the listener's connection set.
// This is all your need to do for the most common case, if you want the
// connection to be broken when the observer is destroyed.
connections += {
subject.nameChanged.connect(this, &Observer::onNameChanged)
};
}
void onNameChanged(const std::string& name) {
std::cout << "Subject received new name: " << name << std::endl;
}
private:
rocket::scoped_connection_container connections;
};
int main() {
Subject s;
Observer o{ s };
s.setName("Peter");
}
// Output:
// Subject received new name: Peter
#include <string>
#include <iostream>
#include <memory>
struct ILogger {
virtual void logMessage(const std::string& message) = 0;
};
struct ConsoleLogger : ILogger {
void logMessage(const std::string& message) override {
std::cout << "New log message: " << message << std::endl;
}
};
struct App {
void run() {
if (work()) {
onSuccess("I finished my work!");
}
}
bool work() {
return true;
}
rocket::signal<void(std::string)> onSuccess;
};
int main() {
std::unique_ptr<App> app = std::make_unique<App>();
std::unique_ptr<ILogger> logger = std::make_unique<ConsoleLogger>();
app->onSuccess.connect(logger.get(), &ILogger::logMessage);
app->run();
}
// Output:
// New log message: I finished my work!
* ------------------------------------------------------------------------------- *
* 4.a Handling lifetime and scope of connection objects *
* *
* What if we want to destroy our logger instance from example 3 but continue *
* to use the app instance? *
* *
* Solution: We use `scoped_connection`-objects to track our connected slots! *
* ------------------------------------------------------------------------------- *
// [...] (See example 3)
int main() {
std::unique_ptr<App> app = std::make_unique<App>();
{
std::unique_ptr<ILogger> logger = std::make_unique<ConsoleLogger>();
rocket::scoped_connection connection = app->onSuccess
.connect(logger.get(), &ILogger::logMessage);
app->run();
} //<-- `logger`-instance is destroyed at the end of this block
//<-- The `connection`-object is also destroyed here
// and therefore removed from App::onSuccess.
// Run the app a second time
//
// This would normally cause a crash / undefined behavior because the logger
// instance is destroyed at this point, but App::onSuccess still referenced it
// in example 3.
app->run();
}
// Output:
// New log message: I finished my work!
* ------------------------------------------------------------------------------- *
* 4.b Advanced lifetime tracking *
* *
* The library can also track the lifetime of your class objects for you, if the *
* connected slot instances inherit from the `rocket::trackable` base class. *
* ------------------------------------------------------------------------------- *
// [...] (See example 3)
struct ILogger : rocket::trackable {
virtual void logMessage(const std::string& message) = 0;
};
// [...] (See example 3)
int main() {
std::unique_ptr<App> app = std::make_unique<App>();
{
std::unique_ptr<ILogger> logger = std::make_unique<ConsoleLogger>();
app->onSuccess.connect(logger.get(), &ILogger::logMessage);
app->run();
} //<-- `logger`-instance is destroyed at the end of this block
//<-- Because `ILogger` inherits from `rocket::trackable`, the signal knows
// about its destruction and will automatically disconnect the slot!
// Run the app a second time
//
// This would normally cause a crash / undefined behavior because the logger
// instance is destroyed at this point, but App::onSuccess still referenced it
// in example 3.
app->run();
}
* ------------------------------------------------------------------------------- *
* 5. Getting return values from a call to a signal *
* *
* Slots can also return values to the emitting signal. *
* Because a signal can have several slots attached to it, the return values are *
* collected by using the so called `value collectors`. *
* *
* The default value collector returns an `optional<T>` from a call to a *
* `signal<T(...)>::operator()` *
* *
* However, this behaviour can be overriden at declaration time of the signal as *
* well as during signal invocation. *
* ------------------------------------------------------------------------------- *
#include <cmath>
#include <iostream>
int main() {
rocket::signal<int(int)> signal;
// The library supports argument and return type transformation between the
// signal and the slots. We show this by connecting the `float sqrtf(float)`
// function to a signal with an `int` argument and `int` return value.
signal.connect(std::sqrtf);
std::cout << "Computed value: " << *signal(16);
}
// Output:
// Computed value: 4
#include <cmath>
#include <iostream>
#include <iomanip>
int main() {
// Because we set `rocket::range` as the value collector for this signal
// calling operator() now returns the return values of all connected slots.
rocket::signal<float(float), rocket::range<float>> signal;
// Lets connect a couple more functions to our signal and print all the
// return values.
signal.connect(std::sinf);
signal.connect(std::cosf);
std::cout << std::fixed << std::setprecision(2);
for (auto result : signal(3.14159)) {
std::cout << result << std::endl;
}
// We can also override the return value collector at invocation time
std::cout << "First return value: " << signal.invoke<rocket::first<float>>(3.14159);
std::cout << std::endl;
std::cout << "Last return value: " << signal.invoke<rocket::last<float>>(3.14159);
}
// Output:
// 0.00
// -1.00
// First return value: 0.00
// Last return value: -1.00
* ------------------------------------------------------------------------------- *
* 6. Accessing the current connection object inside a slot *
* *
* Sometimes it is desirable to get an instance to the current connection object *
* inside of a slot function. An example would be if you want to make a callback *
* that only fires once and then disconnects itself from the signal that called it *
* ------------------------------------------------------------------------------- *
#include <iostream>
int main() {
rocket::signal<void()> signal;
signal.connect([] {
std::cout << "Slot called. Now disconnecting..." << std::endl;
// `current_connection` is stored in thread-local-storage.
rocket::current_connection().disconnect();
});
signal();
signal();
signal();
}
// Output:
// Slot called. Now disconnecting...
* ------------------------------------------------------------------------------- *
* 7. Preemtively aborting the emission of a signal *
* *
* A slot can preemtively abort the emission of a signal if it needs to. *
* This is useful in scenarios where your slot functions try to find some value *
* and you just want the result of the first slot that found one and stop other *
* slots from running. *
* ------------------------------------------------------------------------------- *
#include <iostream>
int main() {
rocket::signal<void()> signal;
signal.connect([] {
std::cout << "First slot called. Aborting emission of other slots." << std::endl;
rocket::abort_emission();
// Notice that this doesn't disconnect the other slots. It just breaks out of the
// signal emitting loop.
});
signal.connect([] {
std::cout << "Second slot called. Should never happen." << std::endl;
});
signal();
}
// Output:
// First slot called. Aborting emission of other slots.
***********************************************************************************
* BEGIN IMPLEMENTATION *
* ------------------------------------------------------------------------------- *
* Do not change anything below this line *
* ------------------------------------------------------------------------------- *
***********************************************************************************/
#include <iterator>
#include <exception>
#include <type_traits>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <list>
#include <forward_list>
#include <initializer_list>
#include <thread>
#include <atomic>
#include <limits>
#include <mutex>
#include <future>
#include <unordered_map>
#include <deque>
#include <chrono>
#include <tuple>
#ifndef ROCKET_NO_STD_OPTIONAL
# include <optional>
#endif
#if __has_cpp_attribute(likely)
# define ROCKET_LIKELY [[likely]]
#else
# define ROCKET_LIKELY
#endif
#if __has_cpp_attribute(unlikely)
# define ROCKET_UNLIKELY [[unlikely]]
#else
# define ROCKET_UNLIKELY
#endif
#if __has_cpp_attribute(no_unique_address)
# define ROCKET_NO_UNIQUE_ADDRESS [[no_unique_address]]
#else
# define ROCKET_NO_UNIQUE_ADDRESS
#endif
namespace rocket
{
template <class T>
struct minimum
{
using value_type = T;
using result_type = T;
template <class U>
void operator () (U&& value)
{
if (!has_value || value < current) {
current = std::forward<U>(value);
has_value = true;
}
}
result_type result()
{
return std::move(current);
}
private:
value_type current{};
bool has_value{ false };
};
template <class T>
struct maximum
{
using value_type = T;
using result_type = T;
template <class U>
void operator () (U&& value)
{
if (!has_value || value > current) {
current = std::forward<U>(value);
has_value = true;
}
}
result_type result()
{
return std::move(current);
}
private:
value_type current{};
bool has_value{ false };
};
template <class T>
struct first
{
using value_type = T;
using result_type = T;
template <class U>
void operator () (U&& value)
{
if (!has_value) {
current = std::forward<U>(value);
has_value = true;
}
}
result_type result()
{
return std::move(current);
}
private:
value_type current{};
bool has_value{ false };
};
template <class T>
struct last
{
using value_type = T;
using result_type = T;
template <class U>
void operator () (U&& value)
{
current = std::forward<U>(value);
}
result_type result()
{
return std::move(current);
}
private:
value_type current{};
};
template <class T>
struct range
{
using value_type = T;
using result_type = std::list<T>;
template <class U>
void operator () (U&& value)
{
values.emplace_back(std::forward<U>(value));
}
result_type result()
{
return std::move(values);
}
private:
std::list<value_type> values;
};
#ifndef ROCKET_NO_EXCEPTIONS
struct error : std::exception
{
};
struct bad_optional_access final : error
{
const char* what() const ROCKET_NOEXCEPT override
{
return "rocket: Bad optional access.";
}
};
struct invocation_slot_error final : error
{
const char* what() const ROCKET_NOEXCEPT override
{
return "rocket: One of the slots has raised an exception during the signal invocation.";
}
};
#endif
#ifdef ROCKET_NO_STD_OPTIONAL
template <class T>
struct optional final
{
using value_type = T;
optional() ROCKET_NOEXCEPT = default;
~optional() ROCKET_NOEXCEPT
{
if (engaged()) {
disengage();
}
}
template <class... Args>
explicit optional(Args&&... args)
{
engage(std::forward<Args>(args)...);
}
optional(optional const& opt)
{
if (opt.engaged()) {
engage(*opt.object());
}
}
optional(optional&& opt)
{
if (opt.engaged()) {
engage(std::move(*opt.object()));
opt.disengage();
}
}
template <class U>
explicit optional(optional<U> const& opt)
{
if (opt.engaged()) {
engage(*opt.object());
}
}
template <class U>
explicit optional(optional<U>&& opt)
{
if (opt.engaged()) {
engage(std::move(*opt.object()));
opt.disengage();
}
}
template <class U>
optional& operator = (U&& rhs)
{
if (engaged()) {
disengage();
}
engage(std::forward<U>(rhs));
return *this;
}
optional& operator = (optional const& rhs)
{
if (this != &rhs) {
if (engaged()) {
disengage();
}
if (rhs.engaged()) {
engage(*rhs.object());
}
}
return *this;
}
template <class U>
optional& operator = (optional<U> const& rhs)
{
if (this != &rhs) {
if (engaged()) {
disengage();
}
if (rhs.engaged()) {
engage(*rhs.object());
}
}
return *this;
}
optional& operator = (optional&& rhs)
{
if (engaged()) {
disengage();
}
if (rhs.engaged()) {
engage(std::move(*rhs.object()));
rhs.disengage();
}
return *this;
}
template <class U>
optional& operator = (optional<U>&& rhs)
{
if (engaged()) {
disengage();
}
if (rhs.engaged()) {
engage(std::move(*rhs.object()));
rhs.disengage();
}
return *this;
}
void reset() ROCKET_NOEXCEPT
{
if (engaged()) {
disengage();
}
}
template <class... Args>
value_type& emplace(Args&&... args)
{
if (engaged()) {
disengage();
}
engage(std::forward<Args>(args)...);
return value();
}
bool engaged() const ROCKET_NOEXCEPT
{
return initialized;
}
bool has_value() const ROCKET_NOEXCEPT
{
return initialized;
}
explicit operator bool() const ROCKET_NOEXCEPT
{
return engaged();
}
value_type& operator * () ROCKET_NOEXCEPT
{
return value();
}
value_type const& operator * () const ROCKET_NOEXCEPT
{
return value();
}
value_type* operator -> () ROCKET_NOEXCEPT
{
return object();
}
value_type const* operator -> () const ROCKET_NOEXCEPT
{
return object();
}
value_type& value()
{
#ifndef ROCKET_NO_EXCEPTIONS
if (!engaged()) {
throw bad_optional_access{};
}
#endif
return *object();
}
value_type const& value() const
{
#ifndef ROCKET_NO_EXCEPTIONS
if (!engaged()) {
throw bad_optional_access{};
}
#endif
return *object();
}
template <class U>
value_type value_or(U&& val) const
{
return engaged() ? *object() : value_type{ std::forward<U>(val) };
}
void swap(optional& other)
{
if (this != &other) {
auto t{ std::move(*this) };
*this = std::move(other);
other = std::move(t);
}
}
private:
void* storage() ROCKET_NOEXCEPT
{
return static_cast<void*>(&buffer);
}
void const* storage() const ROCKET_NOEXCEPT
{
return static_cast<void const*>(&buffer);
}
value_type* object() ROCKET_NOEXCEPT
{
assert(initialized == true);
return static_cast<value_type*>(storage());
}
value_type const* object() const ROCKET_NOEXCEPT
{
assert(initialized == true);
return static_cast<value_type const*>(storage());
}
template <class... Args>
void engage(Args&&... args)
{
assert(initialized == false);
new (storage()) value_type{ std::forward<Args>(args)... };
initialized = true;
}
void disengage() ROCKET_NOEXCEPT
{
assert(initialized == true);
object()->~value_type();
initialized = false;
}
bool initialized = false;
std::aligned_storage_t<sizeof(value_type), alignof(value_type)> buffer;
};
#else
template <class T> using optional = std::optional<T>;
#endif
template <class T>
struct intrusive_ptr final
{
using value_type = T;
using element_type = T;
using pointer = T*;
using reference = T&;
template <class U> friend struct intrusive_ptr;
constexpr intrusive_ptr() ROCKET_NOEXCEPT
: ptr{ nullptr }
{
}
constexpr intrusive_ptr(std::nullptr_t) ROCKET_NOEXCEPT
: ptr{ nullptr }
{
}
explicit intrusive_ptr(pointer p) ROCKET_NOEXCEPT
: ptr{ p }
{
if (ptr) {
ptr->addref();
}
}
intrusive_ptr(intrusive_ptr const& p) ROCKET_NOEXCEPT
: ptr{ p.ptr }
{
if (ptr) {
ptr->addref();
}
}
intrusive_ptr(intrusive_ptr&& p) ROCKET_NOEXCEPT
: ptr{ p.ptr }
{
p.ptr = nullptr;
}
template <class U>
explicit intrusive_ptr(intrusive_ptr<U> const& p) ROCKET_NOEXCEPT
: ptr{ p.ptr }
{
if (ptr) {
ptr->addref();
}
}
template <class U>
explicit intrusive_ptr(intrusive_ptr<U>&& p) ROCKET_NOEXCEPT
: ptr{ p.ptr }
{
p.ptr = nullptr;
}
~intrusive_ptr() ROCKET_NOEXCEPT
{
if (ptr) {
ptr->release();
}
}
pointer get() const ROCKET_NOEXCEPT
{
return ptr;
}
pointer get() const volatile ROCKET_NOEXCEPT
{
return ptr;
}
pointer detach() ROCKET_NOEXCEPT
{
pointer p = ptr;
ptr = nullptr;
return p;
}
operator pointer() const ROCKET_NOEXCEPT
{
return ptr;
}
operator pointer() const volatile ROCKET_NOEXCEPT
{
return ptr;
}
pointer operator -> () const ROCKET_NOEXCEPT
{
assert(ptr != nullptr);
return ptr;
}
reference operator * () const ROCKET_NOEXCEPT
{
assert(ptr != nullptr);
return *ptr;
}
pointer* operator & () ROCKET_NOEXCEPT
{
assert(ptr == nullptr);
return &ptr;
}
pointer const* operator & () const ROCKET_NOEXCEPT
{
return &ptr;
}
intrusive_ptr& operator = (pointer p) ROCKET_NOEXCEPT
{
if (p) {
p->addref();
}
pointer o = ptr;
ptr = p;
if (o) {
o->release();
}
return *this;
}