forked from boostorg/json
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue.hpp
More file actions
3829 lines (3082 loc) · 96.6 KB
/
value.hpp
File metadata and controls
3829 lines (3082 loc) · 96.6 KB
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
//
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
// Copyright (c) 2020 Krystian Stasiowski (sdkrystian@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/json
//
#ifndef BOOST_JSON_VALUE_HPP
#define BOOST_JSON_VALUE_HPP
#include <boost/json/detail/config.hpp>
#include <boost/json/array.hpp>
#include <boost/json/kind.hpp>
#include <boost/json/object.hpp>
#include <boost/json/pilfer.hpp>
#include <boost/json/set_pointer_options.hpp>
#include <boost/json/storage_ptr.hpp>
#include <boost/json/string.hpp>
#include <boost/json/string_view.hpp>
#include <boost/json/value_ref.hpp>
#include <boost/json/detail/except.hpp>
#include <boost/json/detail/value.hpp>
#include <cstdlib>
#include <cstring>
#include <initializer_list>
#include <iosfwd>
#include <limits>
#include <new>
#include <type_traits>
#include <utility>
namespace boost {
namespace json {
//----------------------------------------------------------
/** The type used to represent any JSON value
This is a [Regular](https://en.cppreference.com/w/cpp/concepts/regular)
type which works like a variant of the basic JSON data types: array,
object, string, number, boolean, and null.
@par Thread Safety
Distinct instances may be accessed concurrently. Non-const member
functions of a shared instance may not be called concurrently with any
other member functions of that instance.
*/
class value
{
#ifndef BOOST_JSON_DOCS
using scalar = detail::scalar;
union
{
storage_ptr sp_; // must come first
array arr_;
object obj_;
string str_;
scalar sca_;
};
#endif
struct init_iter;
#ifndef BOOST_JSON_DOCS
// VFALCO doc toolchain incorrectly treats this as public
friend struct detail::access;
#endif
explicit
value(
detail::unchecked_array&& ua)
: arr_(std::move(ua))
{
}
explicit
value(
detail::unchecked_object&& uo)
: obj_(std::move(uo))
{
}
value(
detail::key_t const&,
string_view s,
storage_ptr sp)
: str_(detail::key_t{}, s, std::move(sp))
{
}
value(
detail::key_t const&,
string_view s1,
string_view s2,
storage_ptr sp)
: str_(detail::key_t{}, s1, s2, std::move(sp))
{
}
inline bool is_scalar() const noexcept
{
return sca_.k < json::kind::string;
}
public:
/// Associated [Allocator](https://en.cppreference.com/w/cpp/named_req/Allocator)
using allocator_type = container::pmr::polymorphic_allocator<value>;
/** Destructor.
The value and all of its contents are destroyed. Any dynamically
allocated memory that was allocated internally is freed.
@par Complexity
Constant, or linear in size for array or object.
@par Exception Safety
No-throw guarantee.
*/
BOOST_JSON_DECL
~value() noexcept;
/** Constructors.
Construct a new `value`.
@li **(1)**--**(3)** the constructed value is null.
@li **(4)** the constructed value contains a copy of `b`.
@li **(5)**--**(9)** the constructed value contains a copy of `i`.
@li **(10)**--**(14)** the constructed value contains a copy of `u`.
@li **(15)** the constructed value contains a copy of `d`.
@li **(16)**, **(19)** the constructed value contains a copy of the
string `s`.
@li **(17)** the constructed value contains a copy of the
null-terminated string `s`.
@li **(18)** the constructed value takes ownership of `s`'s storage.
@li **(20)** if `*s.storage() == *sp` equivalent to **(18)**, otherwise
equivalent to **(19)**.
@li **(21)** the constructed value contains an empty string.
@li **(22)** the constructed value takes ownership of `arr`'s storage.
@li **(23)** the constructed value contains an element-wise copy of the
array `arr`.
@li **(24)** if `*arr.storage() == *sp` equivalent to **(22)**,
otherwise equivalent to **(23)**.
@li **(25)** the constructed value contains an empty array.
@li **(26)** the constructed value takes ownership of `obj`'s storage.
@li **(27)** the constructed value contains an element-wise copy of the
object `obj`.
@li **(28)** if `*obj.storage() == *sp` equivalent to **(26)**,
otherwise equivalent to **(27)**.
@li **(29)** the constructed value contains an empty object.
@li **(30)** the constructed value's contents are formed by
constructing from `init` and `sp` (see \<\<initializer_lists\>\>).
@li **(31)**, **(32)** the constructed value contains a copy of the
contents of `other`.
@li **(33)** the constructed value acquires ownership of the contents
of `other`.
@li **(34)** equivalent to **(33)** if `*sp == *other.storage()`;
otherwise equivalent to **(32)**.
@li **(35)** the constructed value acquires ownership of the contents
of `other` using pilfer semantics. This is more efficient than move
construction, when it is known that the moved-from object will be
immediately destroyed afterwards.
With **(2)**--**(17)**, **(19)**--**(21)**, **(23)**--**(25)**,
{sp} **(27)**--**(30)**, **(32)**, and **(34)** the constructed value
uses memory resource of `sp`. With **(18)**, **(22)**, **(26)**,
{sp} **(31)**, **(33)**, and **(35)** it uses the memory resource of
the argument (`s`, `arr`, obj`, or `value`). In either case the value
will share the ownership of the memory resource. With **(1)**
it uses the \<\<default_memory_resource, default memory resource\>\>.
After **(18)**, **(22)**, **(26)**, and **(33)** the argument behaves
as if newly constructed with its current storage pointer (i.e. becomes
an empty string, array, object, or null value).
After **(35)** `other` is not in a usable state and may only be
destroyed.
@par Complexity
@li **(1)**--**(15)**, **(18)**, **(21)**, **(22)**, **(25)**,
{sp} **(26)**, **(29)**, **(33)**, **(35)** constant.
@li **(16)**, **(19)** linear in `s.size()`.
@li **(17)** linear in `std::strlen(s)`.
@li **(20)** if `*s.storage() == *sp` constant, otherwise linear
in `s.size()`.
@li **(23)** linear in `arr.size()`.
@li **(24)** if `*arr.storage() == *sp` constant, otherwise linear
in `arr.size()`.
@li **(27)** linear in `obj.size()`.
@li **(28)** if `*obj.storage() == *sp` constant, otherwise linear
in `obj.size()`.
@li **(30)** linear in `init.size()`.
@li **(31)**, **(32)** linear in the size of `other`.
@li **(34)** constant if `*sp == *other.storage()`; otherwise linear in
the size of `other`.
The size of `other` is either the size of the underlying container
(if there is one), or can be considered to be 1.
@par Exception Safety
@li **(1)**--**(15)**, **(18)**, **(21)**, **(22)**, **(25)**,
**(26)**, **(29)**, **(33)**, **(35)** no-throw guarantee.
@li **(16)**, **(17)**, **(19)**, **(23)**, **(27)**,
**(30)**--**(32)** strong guarantee.
@li **(20)** if `*s.storage() == *sp` no-throw guarantee, otherwise
strong guarantee.
@li **(24)** if `*arr.storage() == *sp` no-throw guarantee, otherwise
strong guarantee.
@li **(28)** if `*obj.storage() == *sp` no-throw guarantee, otherwise
strong guarantee.
@li **(33)** if `*other.storage() == *sp` no-throw guarantee, otherwise
strong guarantee.
Calls to `memory_resource::allocate` may throw.
@see @ref pilfer,
[Valueless Variants Considered Harmful](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0308r0.html).
//
@{
*/
value() noexcept
: sca_()
{
}
/** Overload
@param sp A pointer to the @ref boost::container::pmr::memory_resource
to use.
*/
explicit
value(storage_ptr sp) noexcept
: sca_(std::move(sp))
{
}
/// Overload
value(
std::nullptr_t,
storage_ptr sp = {}) noexcept
: sca_(std::move(sp))
{
}
/** Overload
@param b The boolean to construct with.
@param sp
*/
#ifdef BOOST_JSON_DOCS
value(
bool b,
storage_ptr sp = {}) noexcept;
#else
template<class T
,class = typename std::enable_if<
std::is_same<T, bool>::value>::type
>
value(
T b,
storage_ptr sp = {}) noexcept
: sca_(b, std::move(sp))
{
}
#endif
/** Overload
@param i The number to construct with.
@param sp
*/
value(
signed char i,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::int64_t>(
i), std::move(sp))
{
}
/// Overload
value(
short i,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::int64_t>(
i), std::move(sp))
{
}
/// Overload
value(
int i,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::int64_t>(i),
std::move(sp))
{
}
/// Overload
value(
long i,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::int64_t>(i),
std::move(sp))
{
}
/// Overload
value(
long long i,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::int64_t>(i),
std::move(sp))
{
}
/** Overload
@param u The number to construct with.
@param sp
*/
value(
unsigned char u,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::uint64_t>(
u), std::move(sp))
{
}
/// Overload
value(
unsigned short u,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::uint64_t>(u),
std::move(sp))
{
}
/// Overload
value(
unsigned int u,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::uint64_t>(u),
std::move(sp))
{
}
/// Overload
value(
unsigned long u,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::uint64_t>(u),
std::move(sp))
{
}
/// Overload
value(
unsigned long long u,
storage_ptr sp = {}) noexcept
: sca_(static_cast<std::uint64_t>(u),
std::move(sp))
{
}
/** Overload
@param d The number to construct with.
@param sp
*/
value(
double d,
storage_ptr sp = {}) noexcept
: sca_(d, std::move(sp))
{
}
/** Overload
@param s The string to construct with.
@param sp
*/
value(
string_view s,
storage_ptr sp = {})
: str_(s, std::move(sp))
{
}
/// Overload
value(
char const* s,
storage_ptr sp = {})
: str_(s, std::move(sp))
{
}
/// Overload
value(
string s) noexcept
: str_(std::move(s))
{
}
/// Overload
value(
string const& s,
storage_ptr sp)
: str_(
s,
std::move(sp))
{
}
/// Overload
value(
string&& s,
storage_ptr sp)
: str_(
std::move(s),
std::move(sp))
{
}
/// Overload
value(
string_kind_t,
storage_ptr sp = {}) noexcept
: str_(std::move(sp))
{
}
/** Overload
@param arr The array to construct with.
*/
value(array arr) noexcept
: arr_(std::move(arr))
{
}
/// Overload
value(
array const& arr,
storage_ptr sp)
: arr_(
arr,
std::move(sp))
{
}
/// Overload
value(
array&& arr,
storage_ptr sp)
: arr_(
std::move(arr),
std::move(sp))
{
}
/// Overload
value(
array_kind_t,
storage_ptr sp = {}) noexcept
: arr_(std::move(sp))
{
}
/** Overload
@param obj The object to construct with.
*/
value(object obj) noexcept
: obj_(std::move(obj))
{
}
/// Overload
value(
object const& obj,
storage_ptr sp)
: obj_( obj, std::move(sp) )
{
}
/// Overload
value(
object&& obj,
storage_ptr sp)
: obj_( std::move(obj), std::move(sp) )
{
}
/// Overload
value(
object_kind_t,
storage_ptr sp = {}) noexcept
: obj_(std::move(sp))
{
}
/** Overload
@param init The initializer list to construct from.
@param sp
*/
BOOST_JSON_DECL
value(
std::initializer_list<value_ref> init,
storage_ptr sp = {});
/** Overload
@param other Another `value`.
*/
value(value const& other)
: value(other, other.storage())
{
}
/// Overload
BOOST_JSON_DECL
value(
value const& other,
storage_ptr sp);
/// Overload
BOOST_JSON_DECL
value(value&& other) noexcept;
/// Overload
BOOST_JSON_DECL
value(
value&& other,
storage_ptr sp);
/// Overload
value(pilfered<value> other) noexcept
{
relocate(this, other.get());
::new(&other.get().sca_) scalar();
}
/// @}
//------------------------------------------------------
//
// Assignment
//
//------------------------------------------------------
/** Assignment.
Replaces the contents of this value.
@li **(1)** replaces with an element-wise copy of the contents of
`other`.
@li **(2)** replaces with the contents `other` using move semantics
(see below).
@li **(3)** replaces with the value formed by constructing from `init`
and `this->storage()` (see \<\<initializer_lists\>\>).
@li **(4)** replaces with null.
@li **(5)** replaces with the boolean value `b`.
@li **(6)**--**(10)** replaces with the signed integer `i`.
@li **(11)**--**(15)** replaces with the unsigned integer `u`.
@li **(16)** replaces with the number `d`.
@li **(17)**, **(19)** replaces with a copy of the string `s`.
@li **(18)**, equivalent to `*this = string_view(s)`.
@li **(20)** replaces with the string `s` using move semantics
see below.
@li **(21)** replaces with a copy of the array `arr`.
@li **(22)** replaces with the array `arr` using move semantics
(see below).
@li **(23)** replaces with a copy of the object `obj`.
@li **(24)** replaces with the object `obj` using move semantics
(see below).
Move assignment for `value` never changes the associated memory
resource. Because of this if the memory resource of the assigned value
differs from that of `*this`, the operation is equivalent to a copy.
Otherwise, it replaces the underlying storage in constant time without
the possibility of exceptions.
@par Complexity
@li **(1)** linear in the sizes of `*this` and `other`.
@li **(2)** constant if `*this->storage() == *other.storage()`,
otherwise linear in the sizes of `*this` and `other`.
@li **(3)** linear in the sizes of `*this` and `init`.
@li **(4)**--**(16)** linear in the size of `*this`.
@li **(17)**, **(19)** linear in the size of `*this` and `s.size()`.
@li **(18)** linear in the size of `*this` and `std::strlen(s)`.
@li **(22)** constant if `*this->storage() == *s.storage()`,
otherwise linear in the size of `*this` and `s.size()`.
@li **(21)** linear in the size of `*this` and `arr.size()`.
@li **(22)** constant if `*this->storage() == *arr.storage()`,
otherwise linear in the size of `*this` and `arr.size()`.
@li **(23)** linear in the size of `*this` and `obj.size()`.
@li **(24)** constant if `*this->storage() == *obj.storage()`,
otherwise linear in the size of `*this` and `obj.size()`.
The size of `*this` is either the size of the underlying container
(if there is one), or can be considered to be 1.
@par Exception Safety
@li **(1)**--**(3)**, **(17)**--**(24)** strong guarantee.
@li **(4)**--**(16)** no-throw guarantee.
Calls to `memory_resource::allocate` may throw.
@param other The source value.
@{
*/
BOOST_JSON_DECL
value&
operator=(value const& other);
/** Overload
The contents of the value are replaced with the
contents of `other` using move semantics:
@li If `*other.storage() == *sp`, ownership of
the underlying memory is transferred in constant
time, with no possibility of exceptions.
After assignment, the moved-from value becomes
a null with its current storage pointer.
@li If `*other.storage() != *sp`, an
element-wise copy is performed if
`other.is_structured() == true`, which may throw.
In this case, the moved-from value is not
changed.
*/
BOOST_JSON_DECL
value&
operator=(value&& other);
/** Overload
@param init The initializer list to assign from.
*/
BOOST_JSON_DECL
value&
operator=(
std::initializer_list<value_ref> init);
/// Overload
value&
operator=(std::nullptr_t) noexcept
{
if(is_scalar())
{
sca_.k = json::kind::null;
}
else
{
::new(&sca_) scalar(
destroy());
}
return *this;
}
/** Overload
@param b The new value.
*/
#ifdef BOOST_JSON_DOCS
value& operator=(bool b) noexcept;
#else
template<class T
,class = typename std::enable_if<
std::is_same<T, bool>::value>::type
>
value& operator=(T b) noexcept
{
if(is_scalar())
{
sca_.b = b;
sca_.k = json::kind::bool_;
}
else
{
::new(&sca_) scalar(
b, destroy());
}
return *this;
}
#endif
/** Overload
@param i The new value.
*/
value& operator=(signed char i) noexcept
{
return operator=(
static_cast<long long>(i));
}
/// Overload
value& operator=(short i) noexcept
{
return operator=(
static_cast<long long>(i));
}
/// Overload
value& operator=(int i) noexcept
{
return operator=(
static_cast<long long>(i));
}
/// Overload
value& operator=(long i) noexcept
{
return operator=(
static_cast<long long>(i));
}
/// Overload
value& operator=(long long i) noexcept
{
if(is_scalar())
{
sca_.i = i;
sca_.k = json::kind::int64;
}
else
{
::new(&sca_) scalar(static_cast<
std::int64_t>(i), destroy());
}
return *this;
}
/** Overload
@param u The new value.
*/
value& operator=(unsigned char u) noexcept
{
return operator=(static_cast<
unsigned long long>(u));
}
/// Overload
value& operator=(unsigned short u) noexcept
{
return operator=(static_cast<
unsigned long long>(u));
}
/// Overload
value& operator=(unsigned int u) noexcept
{
return operator=(static_cast<
unsigned long long>(u));
}
/// Overload
value& operator=(unsigned long u) noexcept
{
return operator=(static_cast<
unsigned long long>(u));
}
/// Overload
value& operator=(unsigned long long u) noexcept
{
if(is_scalar())
{
sca_.u = u;
sca_.k = json::kind::uint64;
}
else
{
::new(&sca_) scalar(static_cast<
std::uint64_t>(u), destroy());
}
return *this;
}
/** Overload
@param d The new value.
*/
value& operator=(double d) noexcept
{
if(is_scalar())
{
sca_.d = d;
sca_.k = json::kind::double_;
}
else
{
::new(&sca_) scalar(
d, destroy());
}
return *this;
}
/** Overload
@param s The new string.
*/
BOOST_JSON_DECL
value& operator=(string_view s);
/// Overload
BOOST_JSON_DECL
value& operator=(char const* s);
/// Overload
BOOST_JSON_DECL
value& operator=(string const& s);
/** Overload
The contents of the value are replaced with the
contents of `s` using move semantics:
@li If `*other.storage() == *this->storage()`,
ownership of the underlying memory is transferred
in constant time, with no possibility of exceptions.
After assignment, the moved-from string becomes
empty with its current storage pointer.
@li If `*other.storage() != *this->storage()`, an
element-wise copy is performed, which may throw.
In this case, the moved-from string is not
changed.
@param s The string to move-assign from.
*/
BOOST_JSON_DECL
value& operator=(string&& s);
/** Overload
Replace `*this` with a copy of the array `arr`.
@par Exception Safety
Strong guarantee.
Calls to `memory_resource::allocate` may throw.
@par Complexity
Linear in the sum of sizes of `*this` and `arr`
@param arr The new array.
*/
BOOST_JSON_DECL
value& operator=(array const& arr);
/** Overload
The contents of the value are replaced with the
contents of `arr` using move semantics:
@li If `*arr.storage() == *this->storage()`,
ownership of the underlying memory is transferred
in constant time, with no possibility of exceptions.
After assignment, the moved-from array becomes
empty with its current storage pointer.
@li If `*arr.storage() != *this->storage()`, an
element-wise copy is performed, which may throw.
In this case, the moved-from array is not
changed.
@par Complexity
Constant, or linear in the size of `*this` plus `arr.size()`.
@par Exception Safety
Strong guarantee.
Calls to `memory_resource::allocate` may throw.
@param arr The array to move-assign from.
*/
BOOST_JSON_DECL
value& operator=(array&& arr);
/** Overload
Replace `*this` with a copy of the obect `obj`.
@par Exception Safety
Strong guarantee.
Calls to `memory_resource::allocate` may throw.
@par Complexity
Linear in the sum of sizes of `*this` and `obj`
@param obj The new object.
*/
BOOST_JSON_DECL
value& operator=(object const& obj);
/** Overload
The contents of the value are replaced with the
contents of `obj` using move semantics:
@li If `*obj.storage() == *this->storage()`,
ownership of the underlying memory is transferred
in constant time, with no possibility of exceptions.
After assignment, the moved-from object becomes
empty with its current storage pointer.
@li If `*obj.storage() != *this->storage()`, an
element-wise copy is performed, which may throw.
In this case, the moved-from object is not
changed.
@par Complexity
Constant, or linear in the size of `*this` plus `obj.size()`.
@par Exception Safety
Strong guarantee.
Calls to `memory_resource::allocate` may throw.
@param obj The object to move-assign from.
*/
BOOST_JSON_DECL
value& operator=(object&& obj);
/// @}
//------------------------------------------------------
//
// Modifiers
//
//------------------------------------------------------
/** Replace with a null value.
The current value is destroyed and the kind is changed to kind::null.
The associated memeory resource is kept unchanged.
@par Complexity
Linear in the size of `*this`.
@par Exception Safety
No-throw guarantee.
*/
void
emplace_null() noexcept
{
*this = nullptr;
}
/** Replace with a `bool` value.
The value is replaced with a `bool` initialized to `false`, destroying
the previous contents, but keeping the memeory resource.
@par Complexity
Linear in the size of `*this`.
@par Exception Safety
No-throw guarantee.
@return `this->get_bool()`.
*/
bool&
emplace_bool() noexcept
{
*this = false;
return sca_.b;
}
/** Replace with a `std::int64_t` value.
The value is replaced with a `std::int64_t` initialized to zero,
destroying the previous contents, but keeping the memeory resource.
@par Complexity
Linear in the size of `*this`.
@par Exception Safety
No-throw guarantee.
@return `this->get_int64()`.
*/
std::int64_t&
emplace_int64() noexcept
{
*this = std::int64_t{};
return sca_.i;
}
/** Replace with a `std::uint64_t` value.
The value is replaced with a `std::uint64_t` initialized to zero,
destroying the the previous contents, but keeping the memeory resource.