This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
mdbx.h++
5978 lines (5132 loc) · 226 KB
/
mdbx.h++
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
/// \file mdbx.h++
/// \brief The libmdbx C++ API header file.
///
/// \author Copyright (c) 2020-2022, Leonid Yuriev <leo@yuriev.ru>.
/// \copyright SPDX-License-Identifier: Apache-2.0
///
/// Tested with:
/// - Elbrus LCC >= 1.23 (http://www.mcst.ru/lcc);
/// - GNU C++ >= 4.8;
/// - clang >= 3.9;
/// - MSVC >= 14.0 (Visual Studio 2015),
/// but 19.2x could hang due optimizer bug;
/// - AppleClang, but without C++20 concepts.
///
#pragma once
/* Workaround for modern libstdc++ with CLANG < 4.x */
#if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && \
defined(__clang__) && __clang_major__ < 4
#define __GLIBCXX_BITSIZE_INT_N_0 128
#define __GLIBCXX_TYPE_INT_N_0 __int128
#endif /* Workaround for modern libstdc++ with CLANG < 4.x */
#if !defined(__cplusplus) || __cplusplus < 201103L
#if !defined(_MSC_VER) || _MSC_VER < 1900
#error "C++11 compiler or better is required"
#elif _MSC_VER >= 1910
#error \
"Please add `/Zc:__cplusplus` to MSVC compiler options to enforce it conform ISO C++"
#endif /* MSVC is mad and don't define __cplusplus properly */
#endif /* __cplusplus < 201103L */
#if (defined(_WIN32) || defined(_WIN64)) && MDBX_WITHOUT_MSVC_CRT
#error \
"CRT is required for C++ API, the MDBX_WITHOUT_MSVC_CRT option must be disabled"
#endif /* Windows */
#ifndef __has_include
#define __has_include(header) (0)
#endif /* __has_include */
#if __has_include(<version>)
#include <version>
#endif /* <version> */
/* Disable min/max macros from C' headers */
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <algorithm> // for std::min/max
#include <cassert> // for assert()
#include <climits> // for CHAR_BIT
#include <cstring> // for std::strlen, str:memcmp
#include <exception> // for std::exception_ptr
#include <ostream> // for std::ostream
#include <sstream> // for std::ostringstream
#include <stdexcept> // for std::invalid_argument
#include <string> // for std::string
#include <type_traits> // for std::is_pod<>, etc.
#include <utility> // for std::make_pair
#include <vector> // for std::vector<> as template args
#if defined(__cpp_lib_memory_resource) && __cpp_lib_memory_resource >= 201603L
#include <memory_resource>
#endif
#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L
#include <string_view>
#endif
#if defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
#include <filesystem>
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
#endif
#include "mdbx.h"
#if (defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L) || \
(defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L) || \
(defined(__cpp_lib_bitops) && __cpp_lib_bitops >= 201907L) || \
(defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L)
#include <bit>
#elif !(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
defined(__ORDER_BIG_ENDIAN__))
#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
#define __ORDER_LITTLE_ENDIAN__ __LITTLE_ENDIAN
#define __ORDER_BIG_ENDIAN__ __BIG_ENDIAN
#define __BYTE_ORDER__ __BYTE_ORDER
#elif defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)
#define __ORDER_LITTLE_ENDIAN__ _LITTLE_ENDIAN
#define __ORDER_BIG_ENDIAN__ _BIG_ENDIAN
#define __BYTE_ORDER__ _BYTE_ORDER
#else
#define __ORDER_LITTLE_ENDIAN__ 1234
#define __ORDER_BIG_ENDIAN__ 4321
#if defined(__LITTLE_ENDIAN__) || \
(defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) || \
defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
defined(__MIPSEL__) || defined(_MIPSEL) || defined(__MIPSEL) || \
defined(_M_ARM) || defined(_M_ARM64) || defined(__e2k__) || \
defined(__elbrus_4c__) || defined(__elbrus_8c__) || defined(__bfin__) || \
defined(__BFIN__) || defined(__ia64__) || defined(_IA64) || \
defined(__IA64__) || defined(__ia64) || defined(_M_IA64) || \
defined(__itanium__) || defined(__ia32__) || defined(__CYGWIN__) || \
defined(_WIN64) || defined(_WIN32) || defined(__TOS_WIN__) || \
defined(__WINDOWS__)
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#elif defined(__BIG_ENDIAN__) || \
(defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) || \
defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
defined(__MIPSEB__) || defined(_MIPSEB) || defined(__MIPSEB) || \
defined(__m68k__) || defined(M68000) || defined(__hppa__) || \
defined(__hppa) || defined(__HPPA__) || defined(__sparc__) || \
defined(__sparc) || defined(__370__) || defined(__THW_370__) || \
defined(__s390__) || defined(__s390x__) || defined(__SYSC_ZARCH__)
#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
#endif
#endif
#endif /* Byte Order */
#if defined(DOXYGEN) || \
defined(__cpp_constexpr) && __cpp_constexpr >= 201603L && \
((defined(_MSC_VER) && _MSC_VER >= 1915) || \
(defined(__clang__) && __clang_major__ > 5) || \
(defined(__GNUC__) && __GNUC__ > 7) || \
(!defined(__GNUC__) && !defined(__clang__) && !defined(_MSC_VER)))
#define MDBX_CXX17_CONSTEXPR constexpr
#else
#define MDBX_CXX17_CONSTEXPR inline
#endif /* MDBX_CXX17_CONSTEXPR */
#if defined(DOXYGEN) || defined(__cpp_lib_is_constant_evaluated) && \
__cpp_lib_is_constant_evaluated >= 201811L && \
defined(__cpp_lib_constexpr_string) && \
__cpp_lib_constexpr_string >= 201907L
#define MDBX_CXX20_CONSTEXPR constexpr
#else
#define MDBX_CXX20_CONSTEXPR inline
#endif /* MDBX_CXX20_CONSTEXPR */
#if defined(CONSTEXPR_ASSERT)
#define MDBX_CONSTEXPR_ASSERT(expr) CONSTEXPR_ASSERT(expr)
#elif defined NDEBUG
#define MDBX_CONSTEXPR_ASSERT(expr) void(0)
#else
#define MDBX_CONSTEXPR_ASSERT(expr) \
((expr) ? void(0) : [] { assert(!#expr); }())
#endif /* MDBX_CONSTEXPR_ASSERT */
#ifndef MDBX_LIKELY
#if defined(DOXYGEN) || \
(defined(__GNUC__) || __has_builtin(__builtin_expect)) && \
!defined(__COVERITY__)
#define MDBX_LIKELY(cond) __builtin_expect(!!(cond), 1)
#else
#define MDBX_LIKELY(x) (x)
#endif
#endif /* MDBX_LIKELY */
#ifndef MDBX_UNLIKELY
#if defined(DOXYGEN) || \
(defined(__GNUC__) || __has_builtin(__builtin_expect)) && \
!defined(__COVERITY__)
#define MDBX_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
#else
#define MDBX_UNLIKELY(x) (x)
#endif
#endif /* MDBX_UNLIKELY */
#if defined(__cpp_if_constexpr) && __cpp_if_constexpr >= 201606L
#define MDBX_IF_CONSTEXPR constexpr
#else
#define MDBX_IF_CONSTEXPR
#endif /* MDBX_IF_CONSTEXPR */
#if defined(DOXYGEN) || \
(__has_cpp_attribute(fallthrough) && \
(!defined(__clang__) || __clang__ > 4)) || \
__cplusplus >= 201703L
#define MDBX_CXX17_FALLTHROUGH [[fallthrough]]
#else
#define MDBX_CXX17_FALLTHROUGH
#endif /* MDBX_CXX17_FALLTHROUGH */
#if defined(DOXYGEN) || (__has_cpp_attribute(likely) >= 201803L && \
(!defined(__GNUC__) || __GNUC__ > 9))
#define MDBX_CXX20_LIKELY [[likely]]
#else
#define MDBX_CXX20_LIKELY
#endif /* MDBX_CXX20_LIKELY */
#ifndef MDBX_CXX20_UNLIKELY
#if defined(DOXYGEN) || (__has_cpp_attribute(unlikely) >= 201803L && \
(!defined(__GNUC__) || __GNUC__ > 9))
#define MDBX_CXX20_UNLIKELY [[unlikely]]
#else
#define MDBX_CXX20_UNLIKELY
#endif
#endif /* MDBX_CXX20_UNLIKELY */
#ifndef MDBX_CXX20_CONCEPT
#if defined(DOXYGEN) || \
(defined(__cpp_concepts) && __cpp_concepts >= 201907L && \
(!defined(__clang__) || \
(__clang_major__ >= 12 && !defined(__APPLE__) && \
!defined(__ANDROID_API__)) || \
__clang_major__ >= \
/* Hope Apple will fix concepts in AppleClang 14 */ 14))
#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) CONCEPT NAME
#else
#define MDBX_CXX20_CONCEPT(CONCEPT, NAME) typename NAME
#endif
#endif /* MDBX_CXX20_CONCEPT */
#ifndef MDBX_ASSERT_CXX20_CONCEPT_SATISFIED
#if defined(DOXYGEN) || \
(defined(__cpp_concepts) && __cpp_concepts >= 201907L && \
(!defined(__clang__) || \
(__clang_major__ >= 12 && !defined(__APPLE__) && \
!defined(__ANDROID_API__)) || \
__clang_major__ >= \
/* Hope Apple will fix concepts in AppleClang 14 */ 14))
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, TYPE) \
static_assert(CONCEPT<TYPE>)
#else
#define MDBX_ASSERT_CXX20_CONCEPT_SATISFIED(CONCEPT, NAME) \
static_assert(true, MDBX_STRINGIFY(CONCEPT) "<" MDBX_STRINGIFY(TYPE) ">")
#endif
#endif /* MDBX_ASSERT_CXX20_CONCEPT_SATISFIED */
#ifdef _MSC_VER
#pragma warning(push, 4)
#pragma warning(disable : 4127) /* conditional expression is constant */
#pragma warning(disable : 4251) /* 'std::FOO' needs to have dll-interface to \
be used by clients of 'mdbx::BAR' */
#pragma warning(disable : 4275) /* non dll-interface 'std::FOO' used as \
base for dll-interface 'mdbx::BAR' */
/* MSVC is mad and can generate this warning for its own intermediate
* automatically generated code, which becomes unreachable after some kinds of
* optimization (copy elision, etc). */
#pragma warning(disable : 4702) /* unreachable code */
#endif /* _MSC_VER (warnings) */
//------------------------------------------------------------------------------
/// \defgroup cxx_api C++ API
/// @{
namespace mdbx {
// Functions whose signature depends on the `mdbx::byte` type
// must be strictly defined as inline!
#if defined(DOXYGEN) || (defined(__cpp_char8_t) && __cpp_char8_t >= 201811)
// To enable all kinds of an compiler optimizations we use a byte-like type
// that don't presumes aliases for pointers as does the `char` type and its
// derivatives/typedefs.
// Please see https://github.com/erthink/libmdbx/issues/263
// for reasoning of the use of `char8_t` type and switching to `__restrict__`.
using byte = char8_t;
#else
// Avoid `std::byte` since it doesn't add features but inconvenient
// restrictions.
using byte = unsigned char;
#endif /* __cpp_char8_t >= 201811*/
#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907L
using endian = ::std::endian;
#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
defined(__ORDER_BIG_ENDIAN__)
enum class endian {
little = __ORDER_LITTLE_ENDIAN__,
big = __ORDER_BIG_ENDIAN__,
native = __BYTE_ORDER__
};
#else
#error \
"Please use a C++ compiler provides byte order information or C++20 support"
#endif /* Byte Order enum */
/// \copydoc MDBX_version_info
using version_info = ::MDBX_version_info;
/// \brief Returns libmdbx version information.
MDBX_CXX11_CONSTEXPR const version_info &get_version() noexcept;
/// \copydoc MDBX_build_info
using build_info = ::MDBX_build_info;
/// \brief Returns libmdbx build information.
MDBX_CXX11_CONSTEXPR const build_info &get_build() noexcept;
/// \brief constexpr-compatible strlen().
static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
/// \brief Legacy default allocator
/// but it is recommended to use \ref polymorphic_allocator.
using legacy_allocator = ::std::string::allocator_type;
struct slice;
struct default_capacity_policy;
template <class ALLOCATOR = legacy_allocator,
class CAPACITY_POLICY = default_capacity_policy>
class buffer;
class env;
class env_managed;
class txn;
class txn_managed;
class cursor;
class cursor_managed;
#if defined(DOXYGEN) || \
(defined(__cpp_lib_memory_resource) && \
__cpp_lib_memory_resource >= 201603L && _GLIBCXX_USE_CXX11_ABI)
/// \brief Default polymorphic allocator for modern code.
using polymorphic_allocator = ::std::pmr::string::allocator_type;
#endif /* __cpp_lib_memory_resource >= 201603L */
/// \brief Default singe-byte string.
template <class ALLOCATOR = legacy_allocator>
using string = ::std::basic_string<char, ::std::char_traits<char>, ALLOCATOR>;
using filehandle = ::mdbx_filehandle_t;
#if defined(DOXYGEN) || \
(defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L && \
(!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || \
__MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) && \
(!defined(__IPHONE_OS_VERSION_MIN_REQUIRED) || \
__IPHONE_OS_VERSION_MIN_REQUIRED >= 130100))
namespace filesystem = ::std::filesystem;
#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
#elif defined(__cpp_lib_experimental_filesystem) && \
__cpp_lib_experimental_filesystem >= 201406L
namespace filesystem = ::std::experimental::filesystem;
#define MDBX_STD_FILESYSTEM_PATH ::mdbx::filesystem::path
#endif /* MDBX_STD_FILESYSTEM_PATH */
#ifdef MDBX_STD_FILESYSTEM_PATH
using path = MDBX_STD_FILESYSTEM_PATH;
#elif defined(_WIN32) || defined(_WIN64)
using path = ::std::wstring;
#else
using path = ::std::string;
#endif /* mdbx::path */
/// \brief Transfers C++ exceptions thru C callbacks.
/// \details Implements saving exceptions before returning
/// from an C++'s environment to the intermediate C code and re-throwing after
/// returning from C to the C++'s environment.
class LIBMDBX_API_TYPE exception_thunk {
::std::exception_ptr captured_;
public:
exception_thunk() noexcept = default;
exception_thunk(const exception_thunk &) = delete;
exception_thunk(exception_thunk &&) = delete;
exception_thunk &operator=(const exception_thunk &) = delete;
exception_thunk &operator=(exception_thunk &&) = delete;
inline bool is_clean() const noexcept;
inline void capture() noexcept;
inline void rethrow_captured() const;
};
/// \brief Implements error information and throwing corresponding exceptions.
class LIBMDBX_API_TYPE error {
MDBX_error_t code_;
inline error &operator=(MDBX_error_t error_code) noexcept;
public:
MDBX_CXX11_CONSTEXPR error(MDBX_error_t error_code) noexcept;
error(const error &) = default;
error(error &&) = default;
error &operator=(const error &) = default;
error &operator=(error &&) = default;
MDBX_CXX11_CONSTEXPR friend bool operator==(const error &a,
const error &b) noexcept;
MDBX_CXX11_CONSTEXPR friend bool operator!=(const error &a,
const error &b) noexcept;
MDBX_CXX11_CONSTEXPR bool is_success() const noexcept;
MDBX_CXX11_CONSTEXPR bool is_result_true() const noexcept;
MDBX_CXX11_CONSTEXPR bool is_result_false() const noexcept;
MDBX_CXX11_CONSTEXPR bool is_failure() const noexcept;
/// \brief Returns error code.
MDBX_CXX11_CONSTEXPR MDBX_error_t code() const noexcept;
/// \brief Returns message for MDBX's errors only and "SYSTEM" for others.
const char *what() const noexcept;
/// \brief Returns message for any errors.
::std::string message() const;
/// \brief Returns true for MDBX's errors.
MDBX_CXX11_CONSTEXPR bool is_mdbx_error() const noexcept;
/// \brief Panics on unrecoverable errors inside destructors etc.
[[noreturn]] void panic(const char *context_where_when,
const char *func_who_what) const noexcept;
[[noreturn]] void throw_exception() const;
[[noreturn]] static inline void throw_exception(int error_code);
inline void throw_on_failure() const;
inline void success_or_throw() const;
inline void success_or_throw(const exception_thunk &) const;
inline void panic_on_failure(const char *context_where,
const char *func_who) const noexcept;
inline void success_or_panic(const char *context_where,
const char *func_who) const noexcept;
static inline void throw_on_nullptr(const void *ptr, MDBX_error_t error_code);
static inline void success_or_throw(MDBX_error_t error_code);
static void success_or_throw(int error_code) {
success_or_throw(static_cast<MDBX_error_t>(error_code));
}
static inline void throw_on_failure(int error_code);
static inline bool boolean_or_throw(int error_code);
static inline void success_or_throw(int error_code, const exception_thunk &);
static inline void panic_on_failure(int error_code, const char *context_where,
const char *func_who) noexcept;
static inline void success_or_panic(int error_code, const char *context_where,
const char *func_who) noexcept;
};
/// \brief Base class for all libmdbx's exceptions that are corresponds
/// to libmdbx errors.
///
/// \see MDBX_error_t
class LIBMDBX_API_TYPE exception : public ::std::runtime_error {
using base = ::std::runtime_error;
::mdbx::error error_;
public:
exception(const ::mdbx::error &) noexcept;
exception(const exception &) = default;
exception(exception &&) = default;
exception &operator=(const exception &) = default;
exception &operator=(exception &&) = default;
virtual ~exception() noexcept;
const ::mdbx::error error() const noexcept { return error_; }
};
/// \brief Fatal exception that lead termination anyway
/// in dangerous unrecoverable cases.
class LIBMDBX_API_TYPE fatal : public exception {
using base = exception;
public:
fatal(const ::mdbx::error &) noexcept;
fatal(const exception &src) noexcept : fatal(src.error()) {}
fatal(exception &&src) noexcept : fatal(src.error()) {}
fatal(const fatal &src) noexcept : fatal(src.error()) {}
fatal(fatal &&src) noexcept : fatal(src.error()) {}
fatal &operator=(fatal &&) = default;
fatal &operator=(const fatal &) = default;
virtual ~fatal() noexcept;
};
#define MDBX_DECLARE_EXCEPTION(NAME) \
struct LIBMDBX_API_TYPE NAME : public exception { \
NAME(const ::mdbx::error &); \
virtual ~NAME() noexcept; \
}
MDBX_DECLARE_EXCEPTION(bad_map_id);
MDBX_DECLARE_EXCEPTION(bad_transaction);
MDBX_DECLARE_EXCEPTION(bad_value_size);
MDBX_DECLARE_EXCEPTION(db_corrupted);
MDBX_DECLARE_EXCEPTION(db_full);
MDBX_DECLARE_EXCEPTION(db_invalid);
MDBX_DECLARE_EXCEPTION(db_too_large);
MDBX_DECLARE_EXCEPTION(db_unable_extend);
MDBX_DECLARE_EXCEPTION(db_version_mismatch);
MDBX_DECLARE_EXCEPTION(db_wanna_write_for_recovery);
MDBX_DECLARE_EXCEPTION(incompatible_operation);
MDBX_DECLARE_EXCEPTION(internal_page_full);
MDBX_DECLARE_EXCEPTION(internal_problem);
MDBX_DECLARE_EXCEPTION(key_exists);
MDBX_DECLARE_EXCEPTION(key_mismatch);
MDBX_DECLARE_EXCEPTION(max_maps_reached);
MDBX_DECLARE_EXCEPTION(max_readers_reached);
MDBX_DECLARE_EXCEPTION(multivalue);
MDBX_DECLARE_EXCEPTION(no_data);
MDBX_DECLARE_EXCEPTION(not_found);
MDBX_DECLARE_EXCEPTION(operation_not_permitted);
MDBX_DECLARE_EXCEPTION(permission_denied_or_not_writeable);
MDBX_DECLARE_EXCEPTION(reader_slot_busy);
MDBX_DECLARE_EXCEPTION(remote_media);
MDBX_DECLARE_EXCEPTION(something_busy);
MDBX_DECLARE_EXCEPTION(thread_mismatch);
MDBX_DECLARE_EXCEPTION(transaction_full);
MDBX_DECLARE_EXCEPTION(transaction_overlapping);
#undef MDBX_DECLARE_EXCEPTION
[[noreturn]] LIBMDBX_API void throw_too_small_target_buffer();
[[noreturn]] LIBMDBX_API void throw_max_length_exceeded();
[[noreturn]] LIBMDBX_API void throw_out_range();
[[noreturn]] LIBMDBX_API void throw_allocators_mismatch();
static MDBX_CXX14_CONSTEXPR size_t check_length(size_t bytes);
static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom,
size_t payload);
static MDBX_CXX14_CONSTEXPR size_t check_length(size_t headroom, size_t payload,
size_t tailroom);
static MDBX_CXX17_CONSTEXPR size_t strlen(const char *c_str) noexcept;
static MDBX_CXX20_CONSTEXPR void *memcpy(void *dest, const void *src,
size_t bytes) noexcept;
//------------------------------------------------------------------------------
#if defined(DOXYGEN) || \
(defined(__cpp_concepts) && __cpp_concepts >= 201907L && \
(!defined(__clang__) || \
(__clang_major__ >= 12 && !defined(__APPLE__) && \
!defined(__ANDROID_API__)) || \
__clang_major__ >= \
/* Hope Apple will fix concepts in AppleClang 14 */ 14))
template <typename T>
concept MutableByteProducer = requires(T a, char array[42]) {
{ a.is_empty() } -> std::same_as<bool>;
{ a.envisage_result_length() } -> std::same_as<size_t>;
{ a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
};
template <typename T>
concept ImmutableByteProducer = requires(const T &a, char array[42]) {
{ a.is_empty() } -> std::same_as<bool>;
{ a.envisage_result_length() } -> std::same_as<size_t>;
{ a.write_bytes(&array[0], size_t(42)) } -> std::same_as<char *>;
};
template <typename T>
concept SliceTranscoder = ImmutableByteProducer<T> &&
requires(const slice &source, const T &a) {
T(source);
{ a.is_erroneous() } -> std::same_as<bool>;
};
#endif /* __cpp_concepts >= 201907L*/
template <class ALLOCATOR = legacy_allocator,
typename CAPACITY_POLICY = default_capacity_policy,
MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
inline buffer<ALLOCATOR, CAPACITY_POLICY>
make_buffer(PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
template <class ALLOCATOR = legacy_allocator,
typename CAPACITY_POLICY = default_capacity_policy,
MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
inline buffer<ALLOCATOR, CAPACITY_POLICY>
make_buffer(const PRODUCER &producer, const ALLOCATOR &allocator = ALLOCATOR());
template <class ALLOCATOR = legacy_allocator,
MDBX_CXX20_CONCEPT(MutableByteProducer, PRODUCER)>
inline string<ALLOCATOR> make_string(PRODUCER &producer,
const ALLOCATOR &allocator = ALLOCATOR());
template <class ALLOCATOR = legacy_allocator,
MDBX_CXX20_CONCEPT(ImmutableByteProducer, PRODUCER)>
inline string<ALLOCATOR> make_string(const PRODUCER &producer,
const ALLOCATOR &allocator = ALLOCATOR());
/// \brief References a data located outside the slice.
///
/// The `slice` is similar in many ways to `std::string_view`, but it
/// implements specific capabilities and manipulates with bytes but
/// not a characters.
///
/// \copydetails MDBX_val
struct LIBMDBX_API_TYPE slice : public ::MDBX_val {
/// \todo slice& operator<<(slice&, ...) for reading
/// \todo key-to-value (parse/unpack) functions
/// \todo template<class X> key(X); for decoding keys while reading
enum { max_length = MDBX_MAXDATASIZE };
/// \brief Create an empty slice.
MDBX_CXX11_CONSTEXPR slice() noexcept;
/// \brief Create a slice that refers to [0,bytes-1] of memory bytes pointed
/// by ptr.
MDBX_CXX14_CONSTEXPR slice(const void *ptr, size_t bytes);
/// \brief Create a slice that refers to [begin,end] of memory bytes.
MDBX_CXX14_CONSTEXPR slice(const void *begin, const void *end);
/// \brief Create a slice that refers to text[0,strlen(text)-1].
template <size_t SIZE>
MDBX_CXX14_CONSTEXPR slice(const char (&text)[SIZE]) : slice(text, SIZE - 1) {
MDBX_CONSTEXPR_ASSERT(SIZE > 0 && text[SIZE - 1] == '\0');
}
/// \brief Create a slice that refers to c_str[0,strlen(c_str)-1].
explicit MDBX_CXX17_CONSTEXPR slice(const char *c_str);
/// \brief Create a slice that refers to the contents of "str".
/// \note 'explicit' to avoid reference to the temporary std::string instance.
template <class CHAR, class T, class A>
explicit MDBX_CXX20_CONSTEXPR
slice(const ::std::basic_string<CHAR, T, A> &str)
: slice(str.data(), str.length() * sizeof(CHAR)) {}
MDBX_CXX14_CONSTEXPR slice(const MDBX_val &src);
MDBX_CXX11_CONSTEXPR slice(const slice &) noexcept = default;
MDBX_CXX14_CONSTEXPR slice(MDBX_val &&src);
MDBX_CXX14_CONSTEXPR slice(slice &&src) noexcept;
#if defined(DOXYGEN) || \
(defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
/// \brief Create a slice that refers to the same contents as "string_view"
template <class CHAR, class T>
MDBX_CXX14_CONSTEXPR slice(const ::std::basic_string_view<CHAR, T> &sv)
: slice(sv.data(), sv.data() + sv.length()) {}
template <class CHAR, class T>
slice(::std::basic_string_view<CHAR, T> &&sv) : slice(sv) {
sv = {};
}
#endif /* __cpp_lib_string_view >= 201606L */
template <size_t SIZE>
static MDBX_CXX14_CONSTEXPR slice wrap(const char (&text)[SIZE]) {
return slice(text);
}
template <typename POD>
MDBX_CXX14_CONSTEXPR static slice wrap(const POD &pod) {
static_assert(::std::is_standard_layout<POD>::value &&
!::std::is_pointer<POD>::value,
"Must be a standard layout type!");
return slice(&pod, sizeof(pod));
}
inline slice &assign(const void *ptr, size_t bytes);
inline slice &assign(const slice &src) noexcept;
inline slice &assign(const ::MDBX_val &src);
inline slice &assign(slice &&src) noexcept;
inline slice &assign(::MDBX_val &&src);
inline slice &assign(const void *begin, const void *end);
template <class CHAR, class T, class ALLOCATOR>
slice &assign(const ::std::basic_string<CHAR, T, ALLOCATOR> &str) {
return assign(str.data(), str.length() * sizeof(CHAR));
}
inline slice &assign(const char *c_str);
#if defined(DOXYGEN) || \
(defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
template <class CHAR, class T>
slice &assign(const ::std::basic_string_view<CHAR, T> &view) {
return assign(view.begin(), view.end());
}
template <class CHAR, class T>
slice &assign(::std::basic_string_view<CHAR, T> &&view) {
assign(view);
view = {};
return *this;
}
#endif /* __cpp_lib_string_view >= 201606L */
slice &operator=(const slice &) noexcept = default;
inline slice &operator=(slice &&src) noexcept;
inline slice &operator=(::MDBX_val &&src);
#if defined(DOXYGEN) || \
(defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
template <class CHAR, class T>
slice &operator=(const ::std::basic_string_view<CHAR, T> &view) {
return assign(view);
}
template <class CHAR, class T>
slice &operator=(::std::basic_string_view<CHAR, T> &&view) {
return assign(view);
}
/// \brief Return a string_view that references the same data as this slice.
template <class CHAR = char, class T = ::std::char_traits<CHAR>>
MDBX_CXX11_CONSTEXPR ::std::basic_string_view<CHAR, T>
string_view() const noexcept {
static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
return ::std::basic_string_view<CHAR, T>(char_ptr(), length());
}
/// \brief Return a string_view that references the same data as this slice.
template <class CHAR, class T>
MDBX_CXX11_CONSTEXPR explicit
operator ::std::basic_string_view<CHAR, T>() const noexcept {
return this->string_view<CHAR, T>();
}
#endif /* __cpp_lib_string_view >= 201606L */
template <class CHAR = char, class T = ::std::char_traits<CHAR>,
class ALLOCATOR = legacy_allocator>
MDBX_CXX20_CONSTEXPR ::std::basic_string<CHAR, T, ALLOCATOR>
as_string(const ALLOCATOR &allocator = ALLOCATOR()) const {
static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
return ::std::basic_string<CHAR, T, ALLOCATOR>(char_ptr(), length(),
allocator);
}
template <class CHAR, class T, class ALLOCATOR>
MDBX_CXX20_CONSTEXPR explicit
operator ::std::basic_string<CHAR, T, ALLOCATOR>() const {
return as_string<CHAR, T, ALLOCATOR>();
}
/// \brief Returns a string with a hexadecimal dump of the slice content.
template <class ALLOCATOR = legacy_allocator>
inline string<ALLOCATOR>
as_hex_string(bool uppercase = false, unsigned wrap_width = 0,
const ALLOCATOR &allocator = ALLOCATOR()) const;
/// \brief Returns a string with a
/// [Base58](https://en.wikipedia.org/wiki/Base58) dump of the slice content.
template <class ALLOCATOR = legacy_allocator>
inline string<ALLOCATOR>
as_base58_string(unsigned wrap_width = 0,
const ALLOCATOR &allocator = ALLOCATOR()) const;
/// \brief Returns a string with a
/// [Base58](https://en.wikipedia.org/wiki/Base64) dump of the slice content.
template <class ALLOCATOR = legacy_allocator>
inline string<ALLOCATOR>
as_base64_string(unsigned wrap_width = 0,
const ALLOCATOR &allocator = ALLOCATOR()) const;
/// \brief Returns a buffer with a hexadecimal dump of the slice content.
template <class ALLOCATOR = legacy_allocator,
class CAPACITY_POLICY = default_capacity_policy>
inline buffer<ALLOCATOR, CAPACITY_POLICY>
encode_hex(bool uppercase = false, unsigned wrap_width = 0,
const ALLOCATOR &allocator = ALLOCATOR()) const;
/// \brief Returns a buffer with a
/// [Base58](https://en.wikipedia.org/wiki/Base58) dump of the slice content.
template <class ALLOCATOR = legacy_allocator,
class CAPACITY_POLICY = default_capacity_policy>
inline buffer<ALLOCATOR, CAPACITY_POLICY>
encode_base58(unsigned wrap_width = 0,
const ALLOCATOR &allocator = ALLOCATOR()) const;
/// \brief Returns a buffer with a
/// [Base64](https://en.wikipedia.org/wiki/Base64) dump of the slice content.
template <class ALLOCATOR = legacy_allocator,
class CAPACITY_POLICY = default_capacity_policy>
inline buffer<ALLOCATOR, CAPACITY_POLICY>
encode_base64(unsigned wrap_width = 0,
const ALLOCATOR &allocator = ALLOCATOR()) const;
/// \brief Decodes hexadecimal dump from the slice content to returned buffer.
template <class ALLOCATOR = legacy_allocator,
class CAPACITY_POLICY = default_capacity_policy>
inline buffer<ALLOCATOR, CAPACITY_POLICY>
hex_decode(bool ignore_spaces = false,
const ALLOCATOR &allocator = ALLOCATOR()) const;
/// \brief Decodes [Base58](https://en.wikipedia.org/wiki/Base58) dump
/// from the slice content to returned buffer.
template <class ALLOCATOR = legacy_allocator,
class CAPACITY_POLICY = default_capacity_policy>
inline buffer<ALLOCATOR, CAPACITY_POLICY>
base58_decode(bool ignore_spaces = false,
const ALLOCATOR &allocator = ALLOCATOR()) const;
/// \brief Decodes [Base64](https://en.wikipedia.org/wiki/Base64) dump
/// from the slice content to returned buffer.
template <class ALLOCATOR = legacy_allocator,
class CAPACITY_POLICY = default_capacity_policy>
inline buffer<ALLOCATOR, CAPACITY_POLICY>
base64_decode(bool ignore_spaces = false,
const ALLOCATOR &allocator = ALLOCATOR()) const;
/// \brief Checks whether the content of the slice is printable.
/// \param [in] disable_utf8 By default if `disable_utf8` is `false` function
/// checks that content bytes are printable ASCII-7 characters or a valid UTF8
/// sequences. Otherwise, if if `disable_utf8` is `true` function checks that
/// content bytes are printable extended 8-bit ASCII codes.
MDBX_NOTHROW_PURE_FUNCTION bool
is_printable(bool disable_utf8 = false) const noexcept;
/// \brief Checks whether the content of the slice is a hexadecimal dump.
/// \param [in] ignore_spaces If `true` function will skips spaces surrounding
/// (before, between and after) a encoded bytes. However, spaces should not
/// break a pair of characters encoding a single byte.
inline MDBX_NOTHROW_PURE_FUNCTION bool
is_hex(bool ignore_spaces = false) const noexcept;
/// \brief Checks whether the content of the slice is a
/// [Base58](https://en.wikipedia.org/wiki/Base58) dump.
/// \param [in] ignore_spaces If `true` function will skips spaces surrounding
/// (before, between and after) a encoded bytes. However, spaces should not
/// break a code group of characters.
inline MDBX_NOTHROW_PURE_FUNCTION bool
is_base58(bool ignore_spaces = false) const noexcept;
/// \brief Checks whether the content of the slice is a
/// [Base64](https://en.wikipedia.org/wiki/Base64) dump.
/// \param [in] ignore_spaces If `true` function will skips spaces surrounding
/// (before, between and after) a encoded bytes. However, spaces should not
/// break a code group of characters.
inline MDBX_NOTHROW_PURE_FUNCTION bool
is_base64(bool ignore_spaces = false) const noexcept;
inline void swap(slice &other) noexcept;
#if defined(DOXYGEN) || \
(defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L)
template <class CHAR, class T>
void swap(::std::basic_string_view<CHAR, T> &view) noexcept {
static_assert(sizeof(CHAR) == 1, "Must be single byte characters");
const auto temp = ::std::basic_string_view<CHAR, T>(*this);
*this = view;
view = temp;
}
#endif /* __cpp_lib_string_view >= 201606L */
/// \brief Returns casted to pointer to byte an address of data.
MDBX_CXX11_CONSTEXPR const byte *byte_ptr() const noexcept;
MDBX_CXX11_CONSTEXPR byte *byte_ptr() noexcept;
/// \brief Returns casted to pointer to byte an end of data.
MDBX_CXX11_CONSTEXPR const byte *end_byte_ptr() const noexcept;
MDBX_CXX11_CONSTEXPR byte *end_byte_ptr() noexcept;
/// \brief Returns casted to pointer to char an address of data.
MDBX_CXX11_CONSTEXPR const char *char_ptr() const noexcept;
MDBX_CXX11_CONSTEXPR char *char_ptr() noexcept;
/// \brief Returns casted to pointer to char an end of data.
MDBX_CXX11_CONSTEXPR const char *end_char_ptr() const noexcept;
MDBX_CXX11_CONSTEXPR char *end_char_ptr() noexcept;
/// \brief Return a pointer to the beginning of the referenced data.
MDBX_CXX11_CONSTEXPR const void *data() const noexcept;
MDBX_CXX11_CONSTEXPR void *data() noexcept;
/// \brief Return a pointer to the ending of the referenced data.
MDBX_CXX11_CONSTEXPR const void *end() const noexcept;
MDBX_CXX11_CONSTEXPR void *end() noexcept;
/// \brief Returns the number of bytes.
MDBX_CXX11_CONSTEXPR size_t length() const noexcept;
/// \brief Set slice length.
MDBX_CXX14_CONSTEXPR slice &set_length(size_t bytes);
/// \brief Sets the length by specifying the end of the slice data.
MDBX_CXX14_CONSTEXPR slice &set_end(const void *ptr);
/// \brief Checks whether the slice is empty.
MDBX_CXX11_CONSTEXPR bool empty() const noexcept;
/// \brief Checks whether the slice data pointer is nullptr.
MDBX_CXX11_CONSTEXPR bool is_null() const noexcept;
/// \brief Returns the number of bytes.
MDBX_CXX11_CONSTEXPR size_t size() const noexcept;
/// \brief Returns true if slice is not empty.
MDBX_CXX11_CONSTEXPR operator bool() const noexcept;
/// \brief Depletes content of slice and make it invalid.
MDBX_CXX14_CONSTEXPR void invalidate() noexcept;
/// \brief Makes the slice empty and referencing to nothing.
MDBX_CXX14_CONSTEXPR void clear() noexcept;
/// \brief Drops the first "n" bytes from this slice.
/// \pre REQUIRES: `n <= size()`
inline void remove_prefix(size_t n) noexcept;
/// \brief Drops the last "n" bytes from this slice.
/// \pre REQUIRES: `n <= size()`
inline void remove_suffix(size_t n) noexcept;
/// \brief Drops the first "n" bytes from this slice.
/// \throws std::out_of_range if `n > size()`
inline void safe_remove_prefix(size_t n);
/// \brief Drops the last "n" bytes from this slice.
/// \throws std::out_of_range if `n > size()`
inline void safe_remove_suffix(size_t n);
/// \brief Checks if the data starts with the given prefix.
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool
starts_with(const slice &prefix) const noexcept;
/// \brief Checks if the data ends with the given suffix.
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool
ends_with(const slice &suffix) const noexcept;
/// \brief Returns the nth byte in the referenced data.
/// \pre REQUIRES: `n < size()`
MDBX_CXX11_CONSTEXPR byte operator[](size_t n) const noexcept;
/// \brief Returns the nth byte in the referenced data with bounds checking.
/// \throws std::out_of_range if `n >= size()`
MDBX_CXX11_CONSTEXPR byte at(size_t n) const;
/// \brief Returns the first "n" bytes of the slice.
/// \pre REQUIRES: `n <= size()`
MDBX_CXX14_CONSTEXPR slice head(size_t n) const noexcept;
/// \brief Returns the last "n" bytes of the slice.
/// \pre REQUIRES: `n <= size()`
MDBX_CXX14_CONSTEXPR slice tail(size_t n) const noexcept;
/// \brief Returns the middle "n" bytes of the slice.
/// \pre REQUIRES: `from + n <= size()`
MDBX_CXX14_CONSTEXPR slice middle(size_t from, size_t n) const noexcept;
/// \brief Returns the first "n" bytes of the slice.
/// \throws std::out_of_range if `n >= size()`
MDBX_CXX14_CONSTEXPR slice safe_head(size_t n) const;
/// \brief Returns the last "n" bytes of the slice.
/// \throws std::out_of_range if `n >= size()`
MDBX_CXX14_CONSTEXPR slice safe_tail(size_t n) const;
/// \brief Returns the middle "n" bytes of the slice.
/// \throws std::out_of_range if `from + n >= size()`
MDBX_CXX14_CONSTEXPR slice safe_middle(size_t from, size_t n) const;
/// \brief Returns the hash value of referenced data.
/// \attention Function implementation and returned hash values may changed
/// version to version, and in future the t1ha3 will be used here. Therefore
/// values obtained from this function shouldn't be persisted anywhere.
MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR size_t
hash_value() const noexcept;
/// \brief Three-way fast non-lexicographically length-based comparison.
/// \return value:
/// == 0 if "a" == "b",
/// < 0 if "a" shorter than "b",
/// > 0 if "a" longer than "b",
/// < 0 if "a" length-equal and lexicographically less than "b",
/// > 0 if "a" length-equal and lexicographically great than "b".
MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t
compare_fast(const slice &a, const slice &b) noexcept;
/// \brief Three-way lexicographically comparison.
/// \return value:
/// < 0 if "a" < "b",
/// == 0 if "a" == "b",
/// > 0 if "a" > "b".
MDBX_NOTHROW_PURE_FUNCTION static MDBX_CXX14_CONSTEXPR intptr_t
compare_lexicographically(const slice &a, const slice &b) noexcept;
friend MDBX_CXX14_CONSTEXPR bool operator==(const slice &a,
const slice &b) noexcept;
friend MDBX_CXX14_CONSTEXPR bool operator<(const slice &a,
const slice &b) noexcept;
friend MDBX_CXX14_CONSTEXPR bool operator>(const slice &a,
const slice &b) noexcept;
friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a,
const slice &b) noexcept;
friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a,
const slice &b) noexcept;
friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a,
const slice &b) noexcept;
/// \brief Checks the slice is not refers to null address or has zero length.
MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept {
return !(iov_base == nullptr && iov_len != 0);
}
/// \brief Build an invalid slice which non-zero length and refers to null
/// address.
MDBX_CXX14_CONSTEXPR static slice invalid() noexcept {
return slice(size_t(-1));
}
protected:
MDBX_CXX11_CONSTEXPR slice(size_t invalid_length) noexcept
: ::MDBX_val({nullptr, invalid_length}) {}
};
//------------------------------------------------------------------------------
namespace allocation_aware_details {
template <typename A> constexpr bool allocator_is_always_equal() noexcept {
#if defined(__cpp_lib_allocator_traits_is_always_equal) && \
__cpp_lib_allocator_traits_is_always_equal >= 201411L
return ::std::allocator_traits<A>::is_always_equal::value;
#else
return ::std::is_empty<A>::value;
#endif /* __cpp_lib_allocator_traits_is_always_equal */
}
template <typename T, typename A = typename T::allocator_type,
bool PoCMA = ::std::allocator_traits<
A>::propagate_on_container_move_assignment::value>
struct move_assign_alloc;
template <typename T, typename A> struct move_assign_alloc<T, A, false> {
static constexpr bool is_nothrow() noexcept {
return allocator_is_always_equal<A>();
}
static MDBX_CXX20_CONSTEXPR bool is_moveable(T *target, T &source) noexcept {
return allocator_is_always_equal<A>() ||
target->get_allocator() == source.get_allocator();
}
static MDBX_CXX20_CONSTEXPR void propagate(T *target, T &source) noexcept {
assert(target->get_allocator() != source.get_allocator());
(void)target;
(void)source;
}
};