catboost 1.25.1 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) hide show
  1. package/DEPLOYMENT.md +22 -15
  2. package/README.md +37 -27
  3. package/binding.gyp +5 -7
  4. package/build_scripts/bootstrap.js +2 -1
  5. package/build_scripts/out/build.js +46 -68
  6. package/build_scripts/out/build_model.js +1 -1
  7. package/build_scripts/out/{build_ya.js → build_native.js} +1 -1
  8. package/build_scripts/out/ci.js +5 -5
  9. package/build_scripts/out/config.js +32 -18
  10. package/build_scripts/out/install.js +5 -3
  11. package/build_scripts/out/package_prepublish.js +1 -1
  12. package/build_scripts/out/packaging.js +1 -19
  13. package/build_scripts/out/run_tests.js +1 -1
  14. package/build_scripts/out/test.js +8 -3
  15. package/config.json +18 -11
  16. package/inc/catboost/libs/model_interface/c_api.h +349 -3
  17. package/lib/catboost.d.ts +65 -21
  18. package/package.json +4 -4
  19. package/src/api_helpers.cpp +100 -24
  20. package/src/api_helpers.h +8 -7
  21. package/src/api_module.cpp +1 -2
  22. package/src/model.cpp +483 -83
  23. package/src/model.h +24 -9
  24. package/inc/contrib/libs/cxxsupp/system_stl/include/stlfwd +0 -14
  25. package/inc/util/charset/recode_result.h +0 -9
  26. package/inc/util/charset/unicode_table.h +0 -123
  27. package/inc/util/charset/unidata.h +0 -421
  28. package/inc/util/charset/utf8.h +0 -384
  29. package/inc/util/charset/wide.h +0 -843
  30. package/inc/util/charset/wide_specific.h +0 -22
  31. package/inc/util/datetime/base.h +0 -669
  32. package/inc/util/datetime/constants.h +0 -7
  33. package/inc/util/datetime/cputimer.h +0 -124
  34. package/inc/util/datetime/parser.h +0 -292
  35. package/inc/util/datetime/systime.h +0 -47
  36. package/inc/util/datetime/uptime.h +0 -8
  37. package/inc/util/digest/city.h +0 -88
  38. package/inc/util/digest/fnv.h +0 -73
  39. package/inc/util/digest/multi.h +0 -14
  40. package/inc/util/digest/murmur.h +0 -57
  41. package/inc/util/digest/numeric.h +0 -86
  42. package/inc/util/digest/sequence.h +0 -48
  43. package/inc/util/draft/date.h +0 -129
  44. package/inc/util/draft/datetime.h +0 -184
  45. package/inc/util/draft/enum.h +0 -136
  46. package/inc/util/draft/holder_vector.h +0 -102
  47. package/inc/util/draft/ip.h +0 -131
  48. package/inc/util/draft/matrix.h +0 -108
  49. package/inc/util/draft/memory.h +0 -40
  50. package/inc/util/folder/dirent_win.h +0 -46
  51. package/inc/util/folder/dirut.h +0 -121
  52. package/inc/util/folder/filelist.h +0 -81
  53. package/inc/util/folder/fts.h +0 -108
  54. package/inc/util/folder/iterator.h +0 -109
  55. package/inc/util/folder/lstat_win.h +0 -20
  56. package/inc/util/folder/path.h +0 -225
  57. package/inc/util/folder/pathsplit.h +0 -113
  58. package/inc/util/folder/tempdir.h +0 -42
  59. package/inc/util/generic/adaptor.h +0 -134
  60. package/inc/util/generic/algorithm.h +0 -765
  61. package/inc/util/generic/array_ref.h +0 -282
  62. package/inc/util/generic/array_size.h +0 -24
  63. package/inc/util/generic/benchmark/vector_count_ctor/f.h +0 -9
  64. package/inc/util/generic/bitmap.h +0 -1115
  65. package/inc/util/generic/bitops.h +0 -459
  66. package/inc/util/generic/bt_exception.h +0 -24
  67. package/inc/util/generic/buffer.h +0 -232
  68. package/inc/util/generic/cast.h +0 -176
  69. package/inc/util/generic/deque.h +0 -24
  70. package/inc/util/generic/explicit_type.h +0 -42
  71. package/inc/util/generic/fastqueue.h +0 -55
  72. package/inc/util/generic/flags.h +0 -244
  73. package/inc/util/generic/function.h +0 -103
  74. package/inc/util/generic/fwd.h +0 -171
  75. package/inc/util/generic/guid.h +0 -61
  76. package/inc/util/generic/hash.h +0 -2032
  77. package/inc/util/generic/hash_primes.h +0 -140
  78. package/inc/util/generic/hash_set.h +0 -490
  79. package/inc/util/generic/hide_ptr.h +0 -3
  80. package/inc/util/generic/intrlist.h +0 -876
  81. package/inc/util/generic/is_in.h +0 -53
  82. package/inc/util/generic/iterator.h +0 -137
  83. package/inc/util/generic/iterator_range.h +0 -105
  84. package/inc/util/generic/lazy_value.h +0 -66
  85. package/inc/util/generic/list.h +0 -22
  86. package/inc/util/generic/map.h +0 -44
  87. package/inc/util/generic/mapfindptr.h +0 -60
  88. package/inc/util/generic/maybe.h +0 -713
  89. package/inc/util/generic/maybe_traits.h +0 -164
  90. package/inc/util/generic/mem_copy.h +0 -55
  91. package/inc/util/generic/noncopyable.h +0 -38
  92. package/inc/util/generic/object_counter.h +0 -53
  93. package/inc/util/generic/ptr.h +0 -1113
  94. package/inc/util/generic/queue.h +0 -57
  95. package/inc/util/generic/refcount.h +0 -162
  96. package/inc/util/generic/reserve.h +0 -11
  97. package/inc/util/generic/scope.h +0 -65
  98. package/inc/util/generic/serialized_enum.h +0 -406
  99. package/inc/util/generic/set.h +0 -42
  100. package/inc/util/generic/singleton.h +0 -136
  101. package/inc/util/generic/size_literals.h +0 -65
  102. package/inc/util/generic/stack.h +0 -18
  103. package/inc/util/generic/store_policy.h +0 -120
  104. package/inc/util/generic/strbase.h +0 -612
  105. package/inc/util/generic/strbuf.h +0 -552
  106. package/inc/util/generic/strfcpy.h +0 -17
  107. package/inc/util/generic/string.h +0 -1572
  108. package/inc/util/generic/string_hash.h +0 -21
  109. package/inc/util/generic/string_ut.h +0 -1175
  110. package/inc/util/generic/type_name.h +0 -34
  111. package/inc/util/generic/typelist.h +0 -114
  112. package/inc/util/generic/typetraits.h +0 -325
  113. package/inc/util/generic/utility.h +0 -132
  114. package/inc/util/generic/va_args.h +0 -400
  115. package/inc/util/generic/variant.h +0 -631
  116. package/inc/util/generic/variant_traits.h +0 -171
  117. package/inc/util/generic/vector.h +0 -119
  118. package/inc/util/generic/xrange.h +0 -258
  119. package/inc/util/generic/yexception.h +0 -212
  120. package/inc/util/generic/yexception_ut.h +0 -14
  121. package/inc/util/generic/ylimits.h +0 -92
  122. package/inc/util/generic/ymath.h +0 -206
  123. package/inc/util/memory/addstorage.h +0 -93
  124. package/inc/util/memory/alloc.h +0 -27
  125. package/inc/util/memory/blob.h +0 -296
  126. package/inc/util/memory/mmapalloc.h +0 -8
  127. package/inc/util/memory/pool.h +0 -432
  128. package/inc/util/memory/segmented_string_pool.h +0 -194
  129. package/inc/util/memory/segpool_alloc.h +0 -118
  130. package/inc/util/memory/smallobj.h +0 -141
  131. package/inc/util/memory/tempbuf.h +0 -111
  132. package/inc/util/network/address.h +0 -136
  133. package/inc/util/network/endpoint.h +0 -61
  134. package/inc/util/network/hostip.h +0 -16
  135. package/inc/util/network/init.h +0 -60
  136. package/inc/util/network/interface.h +0 -17
  137. package/inc/util/network/iovec.h +0 -65
  138. package/inc/util/network/ip.h +0 -116
  139. package/inc/util/network/nonblock.h +0 -8
  140. package/inc/util/network/pair.h +0 -9
  141. package/inc/util/network/poller.h +0 -58
  142. package/inc/util/network/pollerimpl.h +0 -707
  143. package/inc/util/network/sock.h +0 -608
  144. package/inc/util/network/socket.h +0 -421
  145. package/inc/util/random/common_ops.h +0 -130
  146. package/inc/util/random/easy.h +0 -47
  147. package/inc/util/random/entropy.h +0 -21
  148. package/inc/util/random/fast.h +0 -101
  149. package/inc/util/random/init_atfork.h +0 -3
  150. package/inc/util/random/lcg_engine.h +0 -66
  151. package/inc/util/random/mersenne.h +0 -46
  152. package/inc/util/random/mersenne32.h +0 -50
  153. package/inc/util/random/mersenne64.h +0 -50
  154. package/inc/util/random/normal.h +0 -38
  155. package/inc/util/random/random.h +0 -30
  156. package/inc/util/random/shuffle.h +0 -39
  157. package/inc/util/str_stl.h +0 -266
  158. package/inc/util/stream/aligned.h +0 -99
  159. package/inc/util/stream/buffer.h +0 -119
  160. package/inc/util/stream/buffered.h +0 -225
  161. package/inc/util/stream/debug.h +0 -53
  162. package/inc/util/stream/direct_io.h +0 -43
  163. package/inc/util/stream/file.h +0 -108
  164. package/inc/util/stream/format.h +0 -444
  165. package/inc/util/stream/fwd.h +0 -100
  166. package/inc/util/stream/hex.h +0 -8
  167. package/inc/util/stream/holder.h +0 -44
  168. package/inc/util/stream/input.h +0 -273
  169. package/inc/util/stream/labeled.h +0 -19
  170. package/inc/util/stream/length.h +0 -100
  171. package/inc/util/stream/mem.h +0 -255
  172. package/inc/util/stream/multi.h +0 -32
  173. package/inc/util/stream/null.h +0 -61
  174. package/inc/util/stream/output.h +0 -304
  175. package/inc/util/stream/pipe.h +0 -112
  176. package/inc/util/stream/printf.h +0 -25
  177. package/inc/util/stream/str.h +0 -207
  178. package/inc/util/stream/tee.h +0 -28
  179. package/inc/util/stream/tempbuf.h +0 -21
  180. package/inc/util/stream/tokenizer.h +0 -214
  181. package/inc/util/stream/trace.h +0 -60
  182. package/inc/util/stream/walk.h +0 -35
  183. package/inc/util/stream/zerocopy.h +0 -91
  184. package/inc/util/stream/zerocopy_output.h +0 -57
  185. package/inc/util/stream/zlib.h +0 -173
  186. package/inc/util/string/ascii.h +0 -236
  187. package/inc/util/string/builder.h +0 -39
  188. package/inc/util/string/cast.h +0 -347
  189. package/inc/util/string/cstriter.h +0 -14
  190. package/inc/util/string/escape.h +0 -70
  191. package/inc/util/string/hex.h +0 -59
  192. package/inc/util/string/join.h +0 -194
  193. package/inc/util/string/printf.h +0 -13
  194. package/inc/util/string/reverse.h +0 -16
  195. package/inc/util/string/split.h +0 -1080
  196. package/inc/util/string/strip.h +0 -257
  197. package/inc/util/string/strspn.h +0 -65
  198. package/inc/util/string/subst.h +0 -56
  199. package/inc/util/string/type.h +0 -50
  200. package/inc/util/string/util.h +0 -195
  201. package/inc/util/string/vector.h +0 -132
  202. package/inc/util/system/align.h +0 -50
  203. package/inc/util/system/atexit.h +0 -22
  204. package/inc/util/system/atomic.h +0 -51
  205. package/inc/util/system/atomic_gcc.h +0 -90
  206. package/inc/util/system/atomic_ops.h +0 -189
  207. package/inc/util/system/atomic_win.h +0 -114
  208. package/inc/util/system/backtrace.h +0 -39
  209. package/inc/util/system/byteorder.h +0 -186
  210. package/inc/util/system/compat.h +0 -84
  211. package/inc/util/system/compiler.h +0 -620
  212. package/inc/util/system/condvar.h +0 -71
  213. package/inc/util/system/context.h +0 -181
  214. package/inc/util/system/context_aarch64.h +0 -8
  215. package/inc/util/system/context_i686.h +0 -9
  216. package/inc/util/system/context_x86.h +0 -12
  217. package/inc/util/system/context_x86_64.h +0 -7
  218. package/inc/util/system/cpu_id.h +0 -159
  219. package/inc/util/system/daemon.h +0 -28
  220. package/inc/util/system/datetime.h +0 -98
  221. package/inc/util/system/defaults.h +0 -149
  222. package/inc/util/system/demangle.h +0 -5
  223. package/inc/util/system/demangle_impl.h +0 -23
  224. package/inc/util/system/direct_io.h +0 -71
  225. package/inc/util/system/dynlib.h +0 -119
  226. package/inc/util/system/env.h +0 -32
  227. package/inc/util/system/error.h +0 -95
  228. package/inc/util/system/event.h +0 -122
  229. package/inc/util/system/execpath.h +0 -17
  230. package/inc/util/system/fasttime.h +0 -6
  231. package/inc/util/system/fhandle.h +0 -27
  232. package/inc/util/system/file.h +0 -210
  233. package/inc/util/system/file_lock.h +0 -34
  234. package/inc/util/system/filemap.h +0 -383
  235. package/inc/util/system/flock.h +0 -35
  236. package/inc/util/system/fs.h +0 -156
  237. package/inc/util/system/fs_win.h +0 -29
  238. package/inc/util/system/fstat.h +0 -46
  239. package/inc/util/system/getpid.h +0 -12
  240. package/inc/util/system/guard.h +0 -179
  241. package/inc/util/system/hi_lo.h +0 -139
  242. package/inc/util/system/hostname.h +0 -10
  243. package/inc/util/system/hp_timer.h +0 -36
  244. package/inc/util/system/info.h +0 -12
  245. package/inc/util/system/interrupt_signals.h +0 -22
  246. package/inc/util/system/madvise.h +0 -30
  247. package/inc/util/system/maxlen.h +0 -32
  248. package/inc/util/system/mem_info.h +0 -18
  249. package/inc/util/system/mincore.h +0 -38
  250. package/inc/util/system/mktemp.h +0 -11
  251. package/inc/util/system/mlock.h +0 -43
  252. package/inc/util/system/mutex.h +0 -67
  253. package/inc/util/system/nice.h +0 -3
  254. package/inc/util/system/pipe.h +0 -90
  255. package/inc/util/system/platform.h +0 -246
  256. package/inc/util/system/progname.h +0 -13
  257. package/inc/util/system/protect.h +0 -25
  258. package/inc/util/system/rusage.h +0 -26
  259. package/inc/util/system/rwlock.h +0 -78
  260. package/inc/util/system/sanitizers.h +0 -122
  261. package/inc/util/system/sem.h +0 -41
  262. package/inc/util/system/shellcommand.h +0 -472
  263. package/inc/util/system/shmat.h +0 -32
  264. package/inc/util/system/sigset.h +0 -78
  265. package/inc/util/system/spin_wait.h +0 -10
  266. package/inc/util/system/spinlock.h +0 -121
  267. package/inc/util/system/src_location.h +0 -25
  268. package/inc/util/system/src_root.h +0 -68
  269. package/inc/util/system/sys_alloc.h +0 -43
  270. package/inc/util/system/sysstat.h +0 -52
  271. package/inc/util/system/tempfile.h +0 -34
  272. package/inc/util/system/thread.h +0 -167
  273. package/inc/util/system/tls.h +0 -307
  274. package/inc/util/system/types.h +0 -119
  275. package/inc/util/system/unaligned_mem.h +0 -67
  276. package/inc/util/system/user.h +0 -5
  277. package/inc/util/system/utime.h +0 -6
  278. package/inc/util/system/valgrind.h +0 -48
  279. package/inc/util/system/winint.h +0 -43
  280. package/inc/util/system/yassert.h +0 -121
  281. package/inc/util/system/yield.h +0 -4
  282. package/inc/util/thread/factory.h +0 -65
  283. package/inc/util/thread/fwd.h +0 -30
  284. package/inc/util/thread/lfqueue.h +0 -406
  285. package/inc/util/thread/lfstack.h +0 -188
  286. package/inc/util/thread/pool.h +0 -388
  287. package/inc/util/thread/singleton.h +0 -42
  288. package/inc/util/ysafeptr.h +0 -427
  289. package/inc/util/ysaveload.h +0 -700
@@ -1,713 +0,0 @@
1
- #pragma once
2
-
3
- #include <utility>
4
-
5
- #include "maybe_traits.h"
6
- #include "yexception.h"
7
-
8
- #include <util/system/align.h>
9
- #include <util/stream/output.h>
10
- #include <util/ysaveload.h>
11
-
12
- namespace NMaybe {
13
- struct TPolicyUndefinedExcept {
14
- [[noreturn]] static void OnEmpty();
15
- };
16
-
17
- struct TPolicyUndefinedFail {
18
- [[noreturn]] static void OnEmpty();
19
- };
20
- }
21
-
22
- struct TNothing {
23
- explicit constexpr TNothing(int) noexcept {
24
- }
25
- };
26
-
27
- constexpr TNothing NothingObject{0};
28
-
29
- constexpr TNothing Nothing() noexcept {
30
- return NothingObject;
31
- }
32
-
33
- constexpr bool operator==(TNothing, TNothing) noexcept {
34
- return true;
35
- }
36
-
37
- template <class T, class Policy /*= ::NMaybe::TPolicyUndefinedExcept*/>
38
- class TMaybe : private TMaybeBase<T> {
39
- public:
40
- using TInPlace = NMaybe::TInPlace;
41
-
42
- private:
43
- static_assert(!std::is_same<std::remove_cv_t<T>, TNothing>::value,
44
- "Instantiation of TMaybe with a TNothing type is ill-formed");
45
- static_assert(!std::is_same<std::remove_cv_t<T>, TInPlace>::value,
46
- "Instantiation of TMaybe with a TInPlace type is ill-formed");
47
- static_assert(!std::is_reference<T>::value,
48
- "Instantiation of TMaybe with reference type is ill-formed");
49
- static_assert(std::is_destructible<T>::value,
50
- "Instantiation of TMaybe with non-destructible type is ill-formed");
51
-
52
- template <class U>
53
- struct TConstructibleFromMaybeSomehow {
54
- public:
55
- static constexpr bool value = std::is_constructible<T, TMaybe<U, Policy>&>::value ||
56
- std::is_constructible<T, const TMaybe<U, Policy>&>::value ||
57
- std::is_constructible<T, TMaybe<U, Policy>&&>::value ||
58
- std::is_constructible<T, const TMaybe<U, Policy>&&>::value ||
59
- std::is_convertible<TMaybe<U, Policy>&, T>::value ||
60
- std::is_convertible<const TMaybe<U, Policy>&, T>::value ||
61
- std::is_convertible<TMaybe<U, Policy>&&, T>::value ||
62
- std::is_convertible<const TMaybe<U, Policy>&&, T>::value;
63
- };
64
-
65
- template <class U>
66
- struct TAssignableFromMaybeSomehow {
67
- public:
68
- static constexpr bool value = TConstructibleFromMaybeSomehow<U>::value ||
69
- std::is_assignable<T&, TMaybe<U, Policy>&>::value ||
70
- std::is_assignable<T&, const TMaybe<U, Policy>&>::value ||
71
- std::is_assignable<T&, TMaybe<U, Policy>&&>::value ||
72
- std::is_assignable<T&, const TMaybe<U, Policy>&&>::value;
73
- };
74
-
75
- template <class U>
76
- struct TImplicitCopyCtor {
77
- public:
78
- static constexpr bool value = std::is_constructible<T, const U&>::value &&
79
- std::is_convertible<const U&, T>::value &&
80
- !TConstructibleFromMaybeSomehow<U>::value;
81
- };
82
-
83
- template <class U>
84
- struct TExplicitCopyCtor {
85
- public:
86
- static constexpr bool value = std::is_constructible<T, const U&>::value &&
87
- !std::is_convertible<const U&, T>::value &&
88
- !TConstructibleFromMaybeSomehow<U>::value;
89
- };
90
-
91
- template <class U>
92
- struct TImplicitMoveCtor {
93
- public:
94
- static constexpr bool value = std::is_constructible<T, U&&>::value &&
95
- std::is_convertible<U&&, T>::value &&
96
- !TConstructibleFromMaybeSomehow<U>::value;
97
- };
98
-
99
- template <class U>
100
- struct TExplicitMoveCtor {
101
- public:
102
- static constexpr bool value = std::is_constructible<T, U&&>::value &&
103
- !std::is_convertible<U&&, T>::value &&
104
- !TConstructibleFromMaybeSomehow<U>::value;
105
- };
106
-
107
- template <class U>
108
- struct TCopyAssignable {
109
- public:
110
- static constexpr bool value = std::is_constructible<T, const U&>::value &&
111
- std::is_assignable<T&, const U&>::value &&
112
- !TAssignableFromMaybeSomehow<U>::value;
113
- };
114
-
115
- template <class U>
116
- struct TMoveAssignable {
117
- public:
118
- static constexpr bool value = std::is_constructible<T, U&&>::value &&
119
- std::is_assignable<T&, U&&>::value &&
120
- !TAssignableFromMaybeSomehow<U>::value;
121
- };
122
-
123
- template <class U>
124
- struct TImplicitAnyCtor {
125
- public:
126
- using UDec = std::decay_t<U>;
127
-
128
- static constexpr bool value = std::is_constructible<T, U>::value &&
129
- std::is_convertible<U, T>::value &&
130
- !std::is_same<UDec, TInPlace>::value &&
131
- !std::is_same<UDec, TMaybe>::value;
132
- };
133
-
134
- template <class U>
135
- struct TExplicitAnyCtor {
136
- public:
137
- using UDec = std::decay_t<U>;
138
- static constexpr bool value = std::is_constructible<T, U>::value &&
139
- !std::is_convertible<U, T>::value &&
140
- !std::is_same<UDec, TInPlace>::value &&
141
- !std::is_same<UDec, TMaybe>::value;
142
- };
143
-
144
- template <class U>
145
- struct TAssignableFromAny {
146
- public:
147
- using UDec = std::decay_t<U>;
148
- static constexpr bool value = !std::is_same<UDec, TMaybe>::value &&
149
- std::is_constructible<T, U>::value &&
150
- std::is_assignable<T&, U>::value &&
151
- (!std::is_scalar<T>::value || !std::is_same<UDec, T>::value);
152
- };
153
-
154
- using TBase = TMaybeBase<T>;
155
-
156
- public:
157
- using value_type = T;
158
- using TValueType = value_type;
159
-
160
- TMaybe() noexcept = default;
161
-
162
- constexpr TMaybe(const TMaybe&) = default;
163
- constexpr TMaybe(TMaybe&&) = default;
164
-
165
- template <class... Args>
166
- constexpr explicit TMaybe(TInPlace, Args&&... args)
167
- : TBase(TInPlace{}, std::forward<Args>(args)...) {}
168
-
169
- template <class U, class... TArgs>
170
- constexpr explicit TMaybe(TInPlace, std::initializer_list<U> il, TArgs&&... args)
171
- : TBase(TInPlace{}, il, std::forward<TArgs>(args)...) {}
172
-
173
- constexpr TMaybe(TNothing) noexcept {}
174
-
175
- template <class U, class = std::enable_if_t<TImplicitCopyCtor<U>::value>>
176
- TMaybe(const TMaybe<U, Policy>& right) {
177
- if (right.Defined()) {
178
- new (Data()) T(right.GetRef());
179
- this->Defined_ = true;
180
- }
181
- }
182
-
183
- template <class U, std::enable_if_t<TExplicitCopyCtor<U>::value, bool> = false>
184
- explicit TMaybe(const TMaybe<U, Policy>& right) {
185
- if (right.Defined()) {
186
- new (Data()) T(right.GetRef());
187
- this->Defined_ = true;
188
- }
189
- }
190
-
191
- template <class U, class = std::enable_if_t<TImplicitMoveCtor<U>::value>>
192
- TMaybe(TMaybe<U, Policy>&& right) noexcept(std::is_nothrow_constructible<T, U&&>::value) {
193
- if (right.Defined()) {
194
- new (Data()) T(std::move(right.GetRef()));
195
- this->Defined_ = true;
196
- }
197
- }
198
-
199
- template <class U, std::enable_if_t<TExplicitMoveCtor<U>::value, bool> = false>
200
- explicit TMaybe(TMaybe<U, Policy>&& right) noexcept(std::is_nothrow_constructible<T, U&&>::value) {
201
- if (right.Defined()) {
202
- new (Data()) T(std::move(right.GetRef()));
203
- this->Defined_ = true;
204
- }
205
- }
206
-
207
- template <class U = T, class = std::enable_if_t<TImplicitAnyCtor<U>::value>>
208
- constexpr TMaybe(U&& right)
209
- : TBase(TInPlace{}, std::forward<U>(right)) {}
210
-
211
- template <class U = T, std::enable_if_t<TExplicitAnyCtor<U>::value, bool> = false>
212
- constexpr explicit TMaybe(U&& right)
213
- : TBase(TInPlace{}, std::forward<U>(right)) {}
214
-
215
- ~TMaybe() = default;
216
-
217
- constexpr TMaybe& operator=(const TMaybe&) = default;
218
- constexpr TMaybe& operator=(TMaybe&&) = default;
219
-
220
- TMaybe& operator=(TNothing) noexcept {
221
- Clear();
222
- return *this;
223
- }
224
-
225
- template <class U = T>
226
- std::enable_if_t<TAssignableFromAny<U>::value, TMaybe&> operator=(U&& right) {
227
- if (Defined()) {
228
- *Data() = std::forward<U>(right);
229
- } else {
230
- Init(std::forward<U>(right));
231
- }
232
- return *this;
233
- }
234
-
235
- template <class U>
236
- std::enable_if_t<TCopyAssignable<U>::value,
237
- TMaybe&> operator=(const TMaybe<U, Policy>& right) {
238
- if (right.Defined()) {
239
- if (Defined()) {
240
- *Data() = right.GetRef();
241
- } else {
242
- Init(right.GetRef());
243
- }
244
- } else {
245
- Clear();
246
- }
247
-
248
- return *this;
249
- }
250
-
251
- template <class U>
252
- std::enable_if_t<TMoveAssignable<U>::value,
253
- TMaybe&> operator=(TMaybe<U, Policy>&& right) noexcept(
254
- std::is_nothrow_assignable<T&, U&&>::value
255
- && std::is_nothrow_constructible<T, U&&>::value)
256
- {
257
- if (right.Defined()) {
258
- if (Defined()) {
259
- *Data() = std::move(right.GetRef());
260
- } else {
261
- Init(std::move(right.GetRef()));
262
- }
263
- } else {
264
- Clear();
265
- }
266
-
267
- return *this;
268
- }
269
-
270
- template <typename... Args>
271
- T& ConstructInPlace(Args&&... args) {
272
- Clear();
273
- Init(std::forward<Args>(args)...);
274
- return *Data();
275
- }
276
-
277
- void Clear() noexcept {
278
- if (Defined()) {
279
- this->Defined_ = false;
280
- Data()->~T();
281
- }
282
- }
283
-
284
- constexpr bool Defined() const noexcept {
285
- return this->Defined_;
286
- }
287
-
288
- Y_PURE_FUNCTION
289
- constexpr bool Empty() const noexcept {
290
- return !Defined();
291
- }
292
-
293
- void CheckDefined() const {
294
- if (Y_UNLIKELY(!Defined())) {
295
- Policy::OnEmpty();
296
- }
297
- }
298
-
299
- const T* Get() const noexcept {
300
- return Defined() ? Data() : nullptr;
301
- }
302
-
303
- T* Get() noexcept {
304
- return Defined() ? Data() : nullptr;
305
- }
306
-
307
- constexpr const T& GetRef() const& {
308
- CheckDefined();
309
-
310
- return *Data();
311
- }
312
-
313
- constexpr T& GetRef() & {
314
- CheckDefined();
315
-
316
- return *Data();
317
- }
318
-
319
- constexpr const T&& GetRef() const&& {
320
- CheckDefined();
321
-
322
- return std::move(*Data());
323
- }
324
-
325
- constexpr T&& GetRef() && {
326
- CheckDefined();
327
-
328
- return std::move(*Data());
329
- }
330
-
331
- constexpr const T& operator*() const& {
332
- return GetRef();
333
- }
334
-
335
- constexpr T& operator*() & {
336
- return GetRef();
337
- }
338
-
339
- constexpr const T&& operator*() const&& {
340
- return std::move(GetRef());
341
- }
342
-
343
- constexpr T&& operator*() && {
344
- return std::move(GetRef());
345
- }
346
-
347
- constexpr const T* operator->() const {
348
- return &GetRef();
349
- }
350
-
351
- constexpr T* operator->() {
352
- return &GetRef();
353
- }
354
-
355
- constexpr const T& GetOrElse(const T& elseValue) const {
356
- return Defined() ? *Data() : elseValue;
357
- }
358
-
359
- constexpr T& GetOrElse(T& elseValue) {
360
- return Defined() ? *Data() : elseValue;
361
- }
362
-
363
- constexpr const TMaybe& OrElse(const TMaybe& elseValue) const noexcept {
364
- return Defined() ? *this : elseValue;
365
- }
366
-
367
- constexpr TMaybe& OrElse(TMaybe& elseValue) {
368
- return Defined() ? *this : elseValue;
369
- }
370
-
371
- template <typename U>
372
- TMaybe<U, Policy> Cast() const {
373
- return Defined() ? TMaybe<U, Policy>(*Data()) : TMaybe<U, Policy>();
374
- }
375
-
376
- constexpr explicit operator bool() const noexcept {
377
- return Defined();
378
- }
379
-
380
- void Save(IOutputStream* out) const {
381
- const bool defined = Defined();
382
-
383
- ::Save<bool>(out, defined);
384
-
385
- if (defined) {
386
- ::Save(out, *Data());
387
- }
388
- }
389
-
390
- void Load(IInputStream* in) {
391
- bool defined;
392
-
393
- ::Load(in, defined);
394
-
395
- if (defined) {
396
- if (!Defined()) {
397
- ConstructInPlace();
398
- }
399
-
400
- ::Load(in, *Data());
401
- } else {
402
- Clear();
403
- }
404
- }
405
-
406
- void Swap(TMaybe& other) {
407
- if (this->Defined_ == other.Defined_) {
408
- if (this->Defined_) {
409
- ::DoSwap(this->Data_, other.Data_);
410
- }
411
- } else {
412
- if (this->Defined_) {
413
- other.Init(std::move(this->Data_));
414
- this->Clear();
415
- } else {
416
- this->Init(std::move(other.Data_));
417
- other.Clear();
418
- }
419
- }
420
- }
421
-
422
- void swap(TMaybe& other) {
423
- Swap(other);
424
- }
425
-
426
- private:
427
- constexpr const T* Data() const noexcept {
428
- return std::addressof(this->Data_);
429
- }
430
-
431
- constexpr T* Data() noexcept {
432
- return std::addressof(this->Data_);
433
- }
434
-
435
- template <typename... Args>
436
- void Init(Args&&... args) {
437
- new (Data()) T(std::forward<Args>(args)...);
438
- this->Defined_ = true;
439
- }
440
- };
441
-
442
- template <class T>
443
- using TMaybeFail = TMaybe<T, NMaybe::TPolicyUndefinedFail>;
444
-
445
- template <class T, class TPolicy = ::NMaybe::TPolicyUndefinedExcept>
446
- constexpr TMaybe<std::decay_t<T>, TPolicy> MakeMaybe(T&& value) {
447
- return TMaybe<std::decay_t<T>, TPolicy>(std::forward<T>(value));
448
- }
449
-
450
- template <class T, class... TArgs>
451
- constexpr TMaybe<T> MakeMaybe(TArgs&&... args) {
452
- return TMaybe<T>(typename TMaybe<T>::TInPlace{}, std::forward<TArgs>(args)...);
453
- }
454
-
455
- template <class T, class U, class... TArgs>
456
- constexpr TMaybe<T> MakeMaybe(std::initializer_list<U> il, TArgs&&... args) {
457
- return TMaybe<T>(typename TMaybe<T>::TInPlace{}, il, std::forward<TArgs>(args)...);
458
- }
459
-
460
- template <class T, class TPolicy>
461
- void Swap(TMaybe<T, TPolicy>& lhs, TMaybe<T, TPolicy>& rhs) {
462
- lhs.Swap(rhs);
463
- }
464
-
465
- template <class T, class TPolicy>
466
- void swap(TMaybe<T, TPolicy>& lhs, TMaybe<T, TPolicy>& rhs) {
467
- lhs.Swap(rhs);
468
- }
469
-
470
- template <typename T, class TPolicy>
471
- struct THash<TMaybe<T, TPolicy>> {
472
- constexpr size_t operator()(const TMaybe<T, TPolicy>& data) const {
473
- return (data.Defined()) ? THash<T>()(data.GetRef()) : 42;
474
- }
475
- };
476
-
477
- // Comparisons between TMaybe
478
- template <class T, class TPolicy>
479
- constexpr bool operator==(const ::TMaybe<T, TPolicy>& left, const ::TMaybe<T, TPolicy>& right) {
480
- return (static_cast<bool>(left) != static_cast<bool>(right))
481
- ? false
482
- : (
483
- !static_cast<bool>(left)
484
- ? true
485
- : *left == *right);
486
- }
487
-
488
- template <class T, class TPolicy>
489
- constexpr bool operator!=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) {
490
- return !(left == right);
491
- }
492
-
493
- template <class T, class TPolicy>
494
- constexpr bool operator<(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) {
495
- return (!static_cast<bool>(right))
496
- ? false
497
- : (
498
- !static_cast<bool>(left)
499
- ? true
500
- : (*left < *right));
501
- }
502
-
503
- template <class T, class TPolicy>
504
- constexpr bool operator>(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) {
505
- return right < left;
506
- }
507
-
508
- template <class T, class TPolicy>
509
- constexpr bool operator<=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) {
510
- return !(right < left);
511
- }
512
-
513
- template <class T, class TPolicy>
514
- constexpr bool operator>=(const TMaybe<T, TPolicy>& left, const TMaybe<T, TPolicy>& right) {
515
- return !(left < right);
516
- }
517
-
518
- // Comparisons with TNothing
519
- template <class T, class TPolicy>
520
- constexpr bool operator==(const TMaybe<T, TPolicy>& left, TNothing) noexcept {
521
- return !static_cast<bool>(left);
522
- }
523
-
524
- template <class T, class TPolicy>
525
- constexpr bool operator==(TNothing, const TMaybe<T, TPolicy>& right) noexcept {
526
- return !static_cast<bool>(right);
527
- }
528
-
529
- template <class T, class TPolicy>
530
- constexpr bool operator!=(const TMaybe<T, TPolicy>& left, TNothing) noexcept {
531
- return static_cast<bool>(left);
532
- }
533
-
534
- template <class T, class TPolicy>
535
- constexpr bool operator!=(TNothing, const TMaybe<T, TPolicy>& right) noexcept {
536
- return static_cast<bool>(right);
537
- }
538
-
539
- template <class T, class TPolicy>
540
- constexpr bool operator<(const TMaybe<T, TPolicy>&, TNothing) noexcept {
541
- return false;
542
- }
543
-
544
- template <class T, class TPolicy>
545
- constexpr bool operator<(TNothing, const TMaybe<T, TPolicy>& right) noexcept {
546
- return static_cast<bool>(right);
547
- }
548
-
549
- template <class T, class TPolicy>
550
- constexpr bool operator<=(const TMaybe<T, TPolicy>& left, TNothing) noexcept {
551
- return !static_cast<bool>(left);
552
- }
553
-
554
- template <class T, class TPolicy>
555
- constexpr bool operator<=(TNothing, const TMaybe<T, TPolicy>&) noexcept {
556
- return true;
557
- }
558
-
559
- template <class T, class TPolicy>
560
- constexpr bool operator>(const TMaybe<T, TPolicy>& left, TNothing) noexcept {
561
- return static_cast<bool>(left);
562
- }
563
-
564
- template <class T, class TPolicy>
565
- constexpr bool operator>(TNothing, const TMaybe<T, TPolicy>&) noexcept {
566
- return false;
567
- }
568
-
569
- template <class T, class TPolicy>
570
- constexpr bool operator>=(const TMaybe<T, TPolicy>&, TNothing) noexcept {
571
- return true;
572
- }
573
-
574
- template <class T, class TPolicy>
575
- constexpr bool operator>=(TNothing, const TMaybe<T, TPolicy>& right) noexcept {
576
- return !static_cast<bool>(right);
577
- }
578
-
579
- // Comparisons with T
580
-
581
- template <class T, class TPolicy>
582
- constexpr bool operator==(const TMaybe<T, TPolicy>& maybe, const T& value) {
583
- return static_cast<bool>(maybe) ? *maybe == value : false;
584
- }
585
-
586
- template <class T, class TPolicy>
587
- constexpr bool operator==(const T& value, const TMaybe<T, TPolicy>& maybe) {
588
- return static_cast<bool>(maybe) ? *maybe == value : false;
589
- }
590
-
591
- template <class T, class TPolicy>
592
- constexpr bool operator!=(const TMaybe<T, TPolicy>& maybe, const T& value) {
593
- return static_cast<bool>(maybe) ? !(*maybe == value) : true;
594
- }
595
-
596
- template <class T, class TPolicy>
597
- constexpr bool operator!=(const T& value, const TMaybe<T, TPolicy>& maybe) {
598
- return static_cast<bool>(maybe) ? !(*maybe == value) : true;
599
- }
600
-
601
- template <class T, class TPolicy>
602
- constexpr bool operator<(const TMaybe<T, TPolicy>& maybe, const T& value) {
603
- return static_cast<bool>(maybe) ? std::less<T>{}(*maybe, value) : true;
604
- }
605
-
606
- template <class T, class TPolicy>
607
- constexpr bool operator<(const T& value, const TMaybe<T, TPolicy>& maybe) {
608
- return static_cast<bool>(maybe) ? std::less<T>{}(value, *maybe) : false;
609
- }
610
-
611
- template <class T, class TPolicy>
612
- constexpr bool operator<=(const TMaybe<T, TPolicy>& maybe, const T& value) {
613
- return !(maybe > value);
614
- }
615
-
616
- template <class T, class TPolicy>
617
- constexpr bool operator<=(const T& value, const TMaybe<T, TPolicy>& maybe) {
618
- return !(value > maybe);
619
- }
620
-
621
- template <class T, class TPolicy>
622
- constexpr bool operator>(const TMaybe<T, TPolicy>& maybe, const T& value) {
623
- return static_cast<bool>(maybe) ? value < maybe : false;
624
- }
625
-
626
- template <class T, class TPolicy>
627
- constexpr bool operator>(const T& value, const TMaybe<T, TPolicy>& maybe) {
628
- return static_cast<bool>(maybe) ? maybe < value : true;
629
- }
630
-
631
- template <class T, class TPolicy>
632
- constexpr bool operator>=(const TMaybe<T, TPolicy>& maybe, const T& value) {
633
- return !(maybe < value);
634
- }
635
-
636
- template <class T, class TPolicy>
637
- constexpr bool operator>=(const T& value, const TMaybe<T, TPolicy>& maybe) {
638
- return !(value < maybe);
639
- }
640
-
641
- // Comparison with values convertible to T
642
-
643
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
644
- constexpr bool operator==(const ::TMaybe<T, TPolicy>& maybe, const U& value) {
645
- return static_cast<bool>(maybe) ? *maybe == value : false;
646
- }
647
-
648
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
649
- constexpr bool operator==(const U& value, const ::TMaybe<T, TPolicy>& maybe) {
650
- return static_cast<bool>(maybe) ? *maybe == value : false;
651
- }
652
-
653
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
654
- constexpr bool operator!=(const TMaybe<T, TPolicy>& maybe, const U& value) {
655
- return static_cast<bool>(maybe) ? !(*maybe == value) : true;
656
- }
657
-
658
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
659
- constexpr bool operator!=(const U& value, const TMaybe<T, TPolicy>& maybe) {
660
- return static_cast<bool>(maybe) ? !(*maybe == value) : true;
661
- }
662
-
663
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
664
- constexpr bool operator<(const TMaybe<T, TPolicy>& maybe, const U& value) {
665
- return static_cast<bool>(maybe) ? std::less<T>{}(*maybe, value) : true;
666
- }
667
-
668
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
669
- constexpr bool operator<(const U& value, const TMaybe<T, TPolicy>& maybe) {
670
- return static_cast<bool>(maybe) ? std::less<T>{}(value, *maybe) : false;
671
- }
672
-
673
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
674
- constexpr bool operator<=(const TMaybe<T, TPolicy>& maybe, const U& value) {
675
- return !(maybe > value);
676
- }
677
-
678
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
679
- constexpr bool operator<=(const U& value, const TMaybe<T, TPolicy>& maybe) {
680
- return !(value > maybe);
681
- }
682
-
683
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
684
- constexpr bool operator>(const TMaybe<T, TPolicy>& maybe, const U& value) {
685
- return static_cast<bool>(maybe) ? value < maybe : false;
686
- }
687
-
688
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
689
- constexpr bool operator>(const U& value, const TMaybe<T, TPolicy>& maybe) {
690
- return static_cast<bool>(maybe) ? maybe < value : true;
691
- }
692
-
693
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
694
- constexpr bool operator>=(const TMaybe<T, TPolicy>& maybe, const U& value) {
695
- return !(maybe < value);
696
- }
697
-
698
- template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
699
- constexpr bool operator>=(const U& value, const TMaybe<T, TPolicy>& maybe) {
700
- return !(value < maybe);
701
- }
702
-
703
- class IOutputStream;
704
-
705
- template <class T, class TPolicy>
706
- inline IOutputStream& operator<<(IOutputStream& out, const TMaybe<T, TPolicy>& maybe) {
707
- if (maybe.Defined()) {
708
- out << *maybe;
709
- } else {
710
- out << TStringBuf("(empty maybe)");
711
- }
712
- return out;
713
- }