webruby 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/lib/webruby/config.rb +4 -9
  3. data/lib/webruby/rake/files.rake +2 -2
  4. data/modules/emscripten/AUTHORS +9 -1
  5. data/modules/emscripten/CONTRIBUTING.markdown +5 -0
  6. data/modules/emscripten/ChangeLog +435 -0
  7. data/modules/emscripten/cmake/Modules/FindOpenAL.cmake +26 -0
  8. data/modules/emscripten/cmake/Platform/Emscripten.cmake +9 -2
  9. data/modules/emscripten/em++ +0 -2
  10. data/modules/emscripten/emcc +92 -32
  11. data/modules/emscripten/emlink.py +16 -13
  12. data/modules/emscripten/emmake +1 -1
  13. data/modules/emscripten/emrun +918 -0
  14. data/modules/emscripten/emrun.bat +2 -0
  15. data/modules/emscripten/emscripten.py +545 -20
  16. data/modules/emscripten/src/analyzer.js +6 -1
  17. data/modules/emscripten/src/compiler.js +25 -16
  18. data/modules/emscripten/src/emrun_postjs.js +20 -0
  19. data/modules/emscripten/{tests → src}/hello_world.js +0 -0
  20. data/modules/emscripten/src/intertyper.js +45 -16
  21. data/modules/emscripten/src/jsifier.js +78 -48
  22. data/modules/emscripten/src/library.js +381 -96
  23. data/modules/emscripten/src/library_browser.js +50 -53
  24. data/modules/emscripten/src/library_egl.js +66 -24
  25. data/modules/emscripten/src/library_fs.js +122 -90
  26. data/modules/emscripten/src/library_gl.js +739 -353
  27. data/modules/emscripten/src/library_glfw.js +9 -3
  28. data/modules/emscripten/src/library_glut.js +10 -5
  29. data/modules/emscripten/src/library_idbfs.js +14 -14
  30. data/modules/emscripten/src/library_memfs.js +65 -41
  31. data/modules/emscripten/src/library_nodefs.js +61 -9
  32. data/modules/emscripten/src/library_openal.js +4 -4
  33. data/modules/emscripten/src/library_path.js +9 -13
  34. data/modules/emscripten/src/library_sdl.js +301 -64
  35. data/modules/emscripten/src/library_sockfs.js +7 -5
  36. data/modules/emscripten/src/modules.js +62 -22
  37. data/modules/emscripten/src/parseTools.js +135 -102
  38. data/modules/emscripten/src/postamble.js +3 -4
  39. data/modules/emscripten/src/preamble.js +49 -29
  40. data/modules/emscripten/src/proxyClient.js +1 -1
  41. data/modules/emscripten/src/proxyWorker.js +10 -10
  42. data/modules/emscripten/src/relooper/Relooper.cpp +15 -4
  43. data/modules/emscripten/src/runtime.js +32 -8
  44. data/modules/emscripten/src/settings.js +25 -8
  45. data/modules/emscripten/src/shell.html +6 -3
  46. data/modules/emscripten/src/shell.js +13 -11
  47. data/modules/emscripten/src/simd.js +602 -432
  48. data/modules/emscripten/src/struct_info.json +22 -2
  49. data/modules/emscripten/src/utility.js +32 -17
  50. data/modules/emscripten/system/include/SDL/SDL_events.h +1 -0
  51. data/modules/emscripten/system/include/compat/ctype.h +17 -0
  52. data/modules/emscripten/system/include/compat/wchar.h +23 -0
  53. data/modules/emscripten/system/include/compat/wctype.h +23 -0
  54. data/modules/emscripten/system/include/emscripten/emmintrin.h +87 -0
  55. data/modules/emscripten/system/include/emscripten/emscripten.h +30 -4
  56. data/modules/emscripten/system/include/emscripten/vector.h +29 -1
  57. data/modules/emscripten/system/include/emscripten/xmmintrin.h +131 -0
  58. data/modules/emscripten/system/include/libcxx/CREDITS.TXT +9 -1
  59. data/modules/emscripten/system/include/libcxx/__bit_reference +8 -8
  60. data/modules/emscripten/system/include/libcxx/__config +95 -17
  61. data/modules/emscripten/system/include/libcxx/__debug +25 -4
  62. data/modules/emscripten/system/include/libcxx/__functional_03 +7 -7
  63. data/modules/emscripten/system/include/libcxx/__functional_base +169 -9
  64. data/modules/emscripten/system/include/libcxx/__functional_base_03 +1 -1
  65. data/modules/emscripten/system/include/libcxx/__hash_table +25 -25
  66. data/modules/emscripten/system/include/libcxx/__locale +21 -19
  67. data/modules/emscripten/system/include/libcxx/__mutex_base +2 -33
  68. data/modules/emscripten/system/include/libcxx/__split_buffer +9 -9
  69. data/modules/emscripten/system/include/libcxx/__std_stream +14 -0
  70. data/modules/emscripten/system/include/libcxx/__tree +35 -26
  71. data/modules/emscripten/system/include/libcxx/__tuple +15 -15
  72. data/modules/emscripten/system/include/libcxx/__tuple_03 +2 -2
  73. data/modules/emscripten/system/include/libcxx/__undef_min_max +8 -0
  74. data/modules/emscripten/system/include/libcxx/algorithm +121 -110
  75. data/modules/emscripten/system/include/libcxx/array +15 -15
  76. data/modules/emscripten/system/include/libcxx/bitset +4 -4
  77. data/modules/emscripten/system/include/libcxx/chrono +51 -17
  78. data/modules/emscripten/system/include/libcxx/cmath +25 -23
  79. data/modules/emscripten/system/include/libcxx/codecvt +21 -18
  80. data/modules/emscripten/system/include/libcxx/complex +48 -7
  81. data/modules/emscripten/system/include/libcxx/cstddef +1 -1
  82. data/modules/emscripten/system/include/libcxx/cstdio +8 -1
  83. data/modules/emscripten/system/include/libcxx/cstdlib +1 -1
  84. data/modules/emscripten/system/include/libcxx/cwchar +1 -1
  85. data/modules/emscripten/system/include/libcxx/deque +26 -12
  86. data/modules/emscripten/system/include/libcxx/dynarray +311 -0
  87. data/modules/emscripten/system/include/libcxx/exception +4 -4
  88. data/modules/emscripten/system/include/libcxx/ext/__hash +3 -3
  89. data/modules/emscripten/system/include/libcxx/ext/hash_map +19 -15
  90. data/modules/emscripten/system/include/libcxx/ext/hash_set +7 -3
  91. data/modules/emscripten/system/include/libcxx/forward_list +33 -7
  92. data/modules/emscripten/system/include/libcxx/fstream +4 -4
  93. data/modules/emscripten/system/include/libcxx/functional +200 -170
  94. data/modules/emscripten/system/include/libcxx/future +83 -39
  95. data/modules/emscripten/system/include/libcxx/initializer_list +24 -11
  96. data/modules/emscripten/system/include/libcxx/iomanip +147 -0
  97. data/modules/emscripten/system/include/libcxx/ios +24 -16
  98. data/modules/emscripten/system/include/libcxx/iosfwd +19 -19
  99. data/modules/emscripten/system/include/libcxx/istream +13 -8
  100. data/modules/emscripten/system/include/libcxx/iterator +108 -417
  101. data/modules/emscripten/system/include/libcxx/limits +8 -4
  102. data/modules/emscripten/system/include/libcxx/list +28 -8
  103. data/modules/emscripten/system/include/libcxx/locale +153 -390
  104. data/modules/emscripten/system/include/libcxx/map +280 -100
  105. data/modules/emscripten/system/include/libcxx/memory +49 -97
  106. data/modules/emscripten/system/include/libcxx/mutex +2 -2
  107. data/modules/emscripten/system/include/libcxx/new +43 -14
  108. data/modules/emscripten/system/include/libcxx/numeric +2 -2
  109. data/modules/emscripten/system/include/libcxx/optional +697 -0
  110. data/modules/emscripten/system/include/libcxx/ostream +17 -8
  111. data/modules/emscripten/system/include/libcxx/queue +5 -5
  112. data/modules/emscripten/system/include/libcxx/random +53 -51
  113. data/modules/emscripten/system/include/libcxx/ratio +11 -11
  114. data/modules/emscripten/system/include/libcxx/readme.txt +1 -1
  115. data/modules/emscripten/system/include/libcxx/regex +23 -20
  116. data/modules/emscripten/system/include/libcxx/scoped_allocator +1 -1
  117. data/modules/emscripten/system/include/libcxx/set +166 -2
  118. data/modules/emscripten/system/include/libcxx/shared_mutex +419 -0
  119. data/modules/emscripten/system/include/libcxx/sstream +4 -4
  120. data/modules/emscripten/system/include/libcxx/stack +3 -3
  121. data/modules/emscripten/system/include/libcxx/streambuf +5 -5
  122. data/modules/emscripten/system/include/libcxx/string +372 -324
  123. data/modules/emscripten/system/include/libcxx/support/ibm/limits.h +99 -0
  124. data/modules/emscripten/system/include/libcxx/support/ibm/support.h +54 -0
  125. data/modules/emscripten/system/include/libcxx/support/ibm/xlocale.h +326 -0
  126. data/modules/emscripten/system/include/libcxx/support/win32/limits_win32.h +6 -6
  127. data/modules/emscripten/system/include/libcxx/support/win32/locale_win32.h +15 -15
  128. data/modules/emscripten/system/include/libcxx/support/win32/math_win32.h +2 -0
  129. data/modules/emscripten/system/include/libcxx/support/win32/support.h +6 -1
  130. data/modules/emscripten/system/include/libcxx/system_error +14 -8
  131. data/modules/emscripten/system/include/libcxx/thread +7 -8
  132. data/modules/emscripten/system/include/libcxx/tuple +29 -88
  133. data/modules/emscripten/system/include/libcxx/type_traits +253 -209
  134. data/modules/emscripten/system/include/libcxx/typeindex +3 -3
  135. data/modules/emscripten/system/include/libcxx/unordered_map +162 -101
  136. data/modules/emscripten/system/include/libcxx/unordered_set +79 -2
  137. data/modules/emscripten/system/include/libcxx/utility +20 -20
  138. data/modules/emscripten/system/include/libcxx/valarray +23 -23
  139. data/modules/emscripten/system/include/libcxx/vector +114 -91
  140. data/modules/emscripten/system/lib/libc/musl/src/regex/regcomp.c +3352 -0
  141. data/modules/emscripten/system/lib/libc/musl/src/regex/regerror.c +35 -0
  142. data/modules/emscripten/system/lib/libc/musl/src/regex/regexec.c +1011 -0
  143. data/modules/emscripten/system/lib/libc/musl/src/regex/tre-mem.c +158 -0
  144. data/modules/emscripten/system/lib/libc/musl/src/regex/tre.h +231 -0
  145. data/modules/emscripten/system/lib/libcextra.symbols +7 -0
  146. data/modules/emscripten/system/lib/libcxx/CREDITS.TXT +9 -1
  147. data/modules/emscripten/system/lib/libcxx/algorithm.cpp +1 -0
  148. data/modules/emscripten/system/lib/libcxx/debug.cpp +66 -42
  149. data/modules/emscripten/system/lib/libcxx/exception.cpp +88 -16
  150. data/modules/emscripten/system/lib/libcxx/future.cpp +6 -0
  151. data/modules/emscripten/system/lib/libcxx/ios.cpp +7 -2
  152. data/modules/emscripten/system/lib/libcxx/iostream.cpp +8 -8
  153. data/modules/emscripten/system/lib/libcxx/locale.cpp +38 -11
  154. data/modules/emscripten/system/lib/libcxx/mutex.cpp +3 -0
  155. data/modules/emscripten/system/lib/libcxx/new.cpp +44 -10
  156. data/modules/emscripten/system/lib/libcxx/optional.cpp +25 -0
  157. data/modules/emscripten/system/lib/libcxx/random.cpp +26 -0
  158. data/modules/emscripten/system/lib/libcxx/readme.txt +1 -1
  159. data/modules/emscripten/system/lib/libcxx/shared_mutex.cpp +101 -0
  160. data/modules/emscripten/system/lib/libcxx/stdexcept.cpp +11 -7
  161. data/modules/emscripten/system/lib/libcxx/string.cpp +3 -1
  162. data/modules/emscripten/system/lib/libcxx/strstream.cpp +7 -7
  163. data/modules/emscripten/system/lib/libcxx/support/win32/locale_win32.cpp +12 -13
  164. data/modules/emscripten/system/lib/libcxx/support/win32/support.cpp +33 -36
  165. data/modules/emscripten/system/lib/libcxx/symbols +187 -168
  166. data/modules/emscripten/system/lib/libcxx/system_error.cpp +1 -0
  167. data/modules/emscripten/system/lib/libcxx/thread.cpp +7 -3
  168. data/modules/emscripten/system/lib/libcxx/typeinfo.cpp +9 -6
  169. data/modules/emscripten/system/lib/libcxx/valarray.cpp +2 -0
  170. data/modules/emscripten/third_party/lzma.js/doit.bat +4 -0
  171. data/modules/emscripten/third_party/lzma.js/doit.sh +9 -2
  172. data/modules/emscripten/tools/cache.py +5 -7
  173. data/modules/emscripten/tools/cache.pyc +0 -0
  174. data/modules/emscripten/tools/eliminator/asm-eliminator-test-output.js +7 -0
  175. data/modules/emscripten/tools/eliminator/asm-eliminator-test.js +9 -1
  176. data/modules/emscripten/tools/eliminator/eliminator-test-output.js +3 -0
  177. data/modules/emscripten/tools/eliminator/eliminator-test.js +9 -1
  178. data/modules/emscripten/tools/file_packager.py +93 -50
  179. data/modules/emscripten/tools/js-optimizer.js +98 -48
  180. data/modules/emscripten/tools/js_optimizer.py +4 -4
  181. data/modules/emscripten/tools/js_optimizer.pyc +0 -0
  182. data/modules/emscripten/tools/jsrun.py +1 -1
  183. data/modules/emscripten/tools/jsrun.pyc +0 -0
  184. data/modules/emscripten/tools/response_file.py +6 -0
  185. data/modules/emscripten/tools/response_file.pyc +0 -0
  186. data/modules/emscripten/tools/settings_template_readonly.py +2 -0
  187. data/modules/emscripten/tools/shared.py +88 -34
  188. data/modules/emscripten/tools/shared.pyc +0 -0
  189. data/modules/emscripten/tools/split.py +21 -13
  190. data/modules/mruby/build_config.rb +7 -1
  191. data/modules/mruby/doc/compile/README.md +5 -9
  192. data/modules/mruby/include/mrbconf.h +5 -2
  193. data/modules/mruby/include/mruby/array.h +1 -0
  194. data/modules/mruby/include/mruby/compile.h +2 -4
  195. data/modules/mruby/include/mruby/dump.h +7 -16
  196. data/modules/mruby/include/mruby/hash.h +1 -1
  197. data/modules/mruby/include/mruby/irep.h +14 -2
  198. data/modules/mruby/include/mruby/khash.h +8 -7
  199. data/modules/mruby/include/mruby/string.h +1 -0
  200. data/modules/mruby/include/mruby/value.h +5 -2
  201. data/modules/mruby/include/mruby.h +12 -13
  202. data/modules/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +16 -6
  203. data/modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +18 -30
  204. data/modules/mruby/mrbgems/mruby-fiber/src/fiber.c +21 -0
  205. data/modules/mruby/mrbgems/mruby-math/src/math.c +1 -1
  206. data/modules/mruby/mrbgems/mruby-random/src/random.c +144 -47
  207. data/modules/mruby/mrbgems/mruby-random/test/random.rb +44 -0
  208. data/modules/mruby/mrbgems/mruby-struct/src/struct.c +5 -5
  209. data/modules/mruby/mrblib/numeric.rb +99 -33
  210. data/modules/mruby/src/array.c +11 -4
  211. data/modules/mruby/src/backtrace.c +2 -2
  212. data/modules/mruby/src/class.c +49 -30
  213. data/modules/mruby/src/codegen.c +131 -79
  214. data/modules/mruby/src/debug.c +1 -1
  215. data/modules/mruby/src/dump.c +213 -163
  216. data/modules/mruby/src/error.c +17 -17
  217. data/modules/mruby/src/error.h +1 -1
  218. data/modules/mruby/src/etc.c +10 -0
  219. data/modules/mruby/src/gc.c +35 -17
  220. data/modules/mruby/src/hash.c +5 -5
  221. data/modules/mruby/src/kernel.c +36 -14
  222. data/modules/mruby/src/load.c +238 -296
  223. data/modules/mruby/src/numeric.c +18 -98
  224. data/modules/mruby/src/object.c +3 -5
  225. data/modules/mruby/src/parse.y +63 -56
  226. data/modules/mruby/src/proc.c +8 -5
  227. data/modules/mruby/src/re.h +0 -1
  228. data/modules/mruby/src/state.c +65 -27
  229. data/modules/mruby/src/string.c +3 -31
  230. data/modules/mruby/src/symbol.c +3 -3
  231. data/modules/mruby/src/variable.c +12 -5
  232. data/modules/mruby/src/vm.c +90 -72
  233. data/modules/mruby/tasks/mruby_build.rake +10 -1
  234. data/modules/mruby/tasks/toolchains/gcc.rake +12 -2
  235. data/modules/mruby/tasks/toolchains/{vs2012.rake → visualcpp.rake} +1 -1
  236. data/modules/mruby/test/driver.c +3 -3
  237. data/modules/mruby/test/t/array.rb +5 -5
  238. data/modules/mruby/test/t/class.rb +14 -1
  239. data/modules/mruby/test/t/kernel.rb +4 -0
  240. data/modules/mruby/test/t/module.rb +4 -4
  241. data/modules/mruby/test/t/nameerror.rb +1 -1
  242. data/modules/mruby/tools/mrbc/mrbc.c +23 -17
  243. data/modules/mruby/travis_config.rb +10 -1
  244. metadata +28 -5
  245. data/modules/mruby/tasks/toolchains/vs2010.rake +0 -3
@@ -447,7 +447,7 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1
447
447
  #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
448
448
  #include <cstdint>
449
449
  #endif
450
- #if defined(_LIBCPP_NO_EXCEPTIONS) || defined(_LIBCPP_DEBUG)
450
+ #if defined(_LIBCPP_NO_EXCEPTIONS)
451
451
  #include <cassert>
452
452
  #endif
453
453
 
@@ -462,7 +462,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
462
462
  // fpos
463
463
 
464
464
  template <class _StateT>
465
- class _LIBCPP_TYPE_VIS fpos
465
+ class _LIBCPP_TYPE_VIS_ONLY fpos
466
466
  {
467
467
  private:
468
468
  _StateT __st_;
@@ -499,7 +499,7 @@ bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
499
499
  // char_traits
500
500
 
501
501
  template <class _CharT>
502
- struct _LIBCPP_TYPE_VIS char_traits
502
+ struct _LIBCPP_TYPE_VIS_ONLY char_traits
503
503
  {
504
504
  typedef _CharT char_type;
505
505
  typedef int int_type;
@@ -605,6 +605,7 @@ inline _LIBCPP_INLINE_VISIBILITY
605
605
  _CharT*
606
606
  char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
607
607
  {
608
+ _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
608
609
  char_type* __r = __s1;
609
610
  for (; __n; --__n, ++__s1, ++__s2)
610
611
  assign(*__s1, *__s2);
@@ -625,7 +626,7 @@ char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
625
626
  // char_traits<char>
626
627
 
627
628
  template <>
628
- struct _LIBCPP_TYPE_VIS char_traits<char>
629
+ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char>
629
630
  {
630
631
  typedef char char_type;
631
632
  typedef int int_type;
@@ -656,7 +657,10 @@ struct _LIBCPP_TYPE_VIS char_traits<char>
656
657
  {return (char_type*)memmove(__s1, __s2, __n);}
657
658
  _LIBCPP_INLINE_VISIBILITY
658
659
  static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
659
- {return (char_type*)memcpy(__s1, __s2, __n);}
660
+ {
661
+ _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
662
+ return (char_type*)memcpy(__s1, __s2, __n);
663
+ }
660
664
  _LIBCPP_INLINE_VISIBILITY
661
665
  static char_type* assign(char_type* __s, size_t __n, char_type __a)
662
666
  {return (char_type*)memset(__s, to_int_type(__a), __n);}
@@ -681,7 +685,7 @@ struct _LIBCPP_TYPE_VIS char_traits<char>
681
685
  // char_traits<wchar_t>
682
686
 
683
687
  template <>
684
- struct _LIBCPP_TYPE_VIS char_traits<wchar_t>
688
+ struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
685
689
  {
686
690
  typedef wchar_t char_type;
687
691
  typedef wint_t int_type;
@@ -713,7 +717,10 @@ struct _LIBCPP_TYPE_VIS char_traits<wchar_t>
713
717
  {return (char_type*)wmemmove(__s1, __s2, __n);}
714
718
  _LIBCPP_INLINE_VISIBILITY
715
719
  static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
716
- {return (char_type*)wmemcpy(__s1, __s2, __n);}
720
+ {
721
+ _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
722
+ return (char_type*)wmemcpy(__s1, __s2, __n);
723
+ }
717
724
  _LIBCPP_INLINE_VISIBILITY
718
725
  static char_type* assign(char_type* __s, size_t __n, char_type __a)
719
726
  {return (char_type*)wmemset(__s, __a, __n);}
@@ -738,7 +745,7 @@ struct _LIBCPP_TYPE_VIS char_traits<wchar_t>
738
745
  #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
739
746
 
740
747
  template <>
741
- struct _LIBCPP_TYPE_VIS char_traits<char16_t>
748
+ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
742
749
  {
743
750
  typedef char16_t char_type;
744
751
  typedef uint_least16_t int_type;
@@ -841,6 +848,7 @@ inline _LIBCPP_INLINE_VISIBILITY
841
848
  char16_t*
842
849
  char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
843
850
  {
851
+ _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
844
852
  char_type* __r = __s1;
845
853
  for (; __n; --__n, ++__s1, ++__s2)
846
854
  assign(*__s1, *__s2);
@@ -858,7 +866,7 @@ char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
858
866
  }
859
867
 
860
868
  template <>
861
- struct _LIBCPP_TYPE_VIS char_traits<char32_t>
869
+ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
862
870
  {
863
871
  typedef char32_t char_type;
864
872
  typedef uint_least32_t int_type;
@@ -961,6 +969,7 @@ inline _LIBCPP_INLINE_VISIBILITY
961
969
  char32_t*
962
970
  char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
963
971
  {
972
+ _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
964
973
  char_type* __r = __s1;
965
974
  for (; __n; --__n, ++__s1, ++__s2)
966
975
  assign(*__s1, *__s2);
@@ -1003,7 +1012,7 @@ basic_string<_CharT, _Traits, _Allocator>
1003
1012
  operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
1004
1013
 
1005
1014
  template <bool>
1006
- class __basic_string_common
1015
+ class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
1007
1016
  {
1008
1017
  protected:
1009
1018
  void __throw_length_error() const;
@@ -1036,7 +1045,7 @@ __basic_string_common<__b>::__throw_out_of_range() const
1036
1045
  #pragma warning( push )
1037
1046
  #pragma warning( disable: 4231 )
1038
1047
  #endif // _LIBCPP_MSVC
1039
- _LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>)
1048
+ _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
1040
1049
  #ifdef _LIBCPP_MSVC
1041
1050
  #pragma warning( pop )
1042
1051
  #endif // _LIBCPP_MSVC
@@ -1057,7 +1066,7 @@ struct __padding<_CharT, 1>
1057
1066
  #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1058
1067
 
1059
1068
  template<class _CharT, class _Traits, class _Allocator>
1060
- class _LIBCPP_TYPE_VIS basic_string
1069
+ class _LIBCPP_TYPE_VIS_ONLY basic_string
1061
1070
  : private __basic_string_common<true>
1062
1071
  {
1063
1072
  public:
@@ -1072,13 +1081,13 @@ public:
1072
1081
  typedef const value_type& const_reference;
1073
1082
  typedef typename __alloc_traits::pointer pointer;
1074
1083
  typedef typename __alloc_traits::const_pointer const_pointer;
1075
- #ifdef _LIBCPP_DEBUG
1076
- typedef __debug_iter<basic_string, pointer> iterator;
1077
- typedef __debug_iter<basic_string, const_pointer> const_iterator;
1078
1084
 
1079
- friend class __debug_iter<basic_string, pointer>;
1080
- friend class __debug_iter<basic_string, const_pointer>;
1081
- #elif defined(_LIBCPP_RAW_ITERATORS)
1085
+ static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
1086
+ static_assert((is_same<_CharT, value_type>::value),
1087
+ "traits_type::char_type must be the same type as CharT");
1088
+ static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1089
+ "Allocator::value_type must be same type as value_type");
1090
+ #if defined(_LIBCPP_RAW_ITERATORS)
1082
1091
  typedef pointer iterator;
1083
1092
  typedef const_pointer const_iterator;
1084
1093
  #else // defined(_LIBCPP_RAW_ITERATORS)
@@ -1152,9 +1161,9 @@ private:
1152
1161
 
1153
1162
  #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1154
1163
 
1155
- union __lx{__long __lx; __short __lxx;};
1164
+ union __ulx{__long __lx; __short __lxx;};
1156
1165
 
1157
- enum {__n_words = sizeof(__lx) / sizeof(size_type)};
1166
+ enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
1158
1167
 
1159
1168
  struct __raw
1160
1169
  {
@@ -1173,15 +1182,6 @@ private:
1173
1182
 
1174
1183
  __compressed_pair<__rep, allocator_type> __r_;
1175
1184
 
1176
- #ifdef _LIBCPP_DEBUG
1177
-
1178
- pair<iterator*, const_iterator*> __iterator_list_;
1179
-
1180
- _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1181
- _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
1182
-
1183
- #endif // _LIBCPP_DEBUG
1184
-
1185
1185
  public:
1186
1186
  static const size_type npos = -1;
1187
1187
 
@@ -1239,7 +1239,20 @@ public:
1239
1239
  basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1240
1240
  #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1241
1241
 
1242
- #ifndef _LIBCPP_DEBUG
1242
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1243
+ _LIBCPP_INLINE_VISIBILITY
1244
+ iterator begin() _NOEXCEPT
1245
+ {return iterator(this, __get_pointer());}
1246
+ _LIBCPP_INLINE_VISIBILITY
1247
+ const_iterator begin() const _NOEXCEPT
1248
+ {return const_iterator(this, __get_pointer());}
1249
+ _LIBCPP_INLINE_VISIBILITY
1250
+ iterator end() _NOEXCEPT
1251
+ {return iterator(this, __get_pointer() + size());}
1252
+ _LIBCPP_INLINE_VISIBILITY
1253
+ const_iterator end() const _NOEXCEPT
1254
+ {return const_iterator(this, __get_pointer() + size());}
1255
+ #else
1243
1256
  _LIBCPP_INLINE_VISIBILITY
1244
1257
  iterator begin() _NOEXCEPT
1245
1258
  {return iterator(__get_pointer());}
@@ -1252,12 +1265,7 @@ public:
1252
1265
  _LIBCPP_INLINE_VISIBILITY
1253
1266
  const_iterator end() const _NOEXCEPT
1254
1267
  {return const_iterator(__get_pointer() + size());}
1255
- #else // _LIBCPP_DEBUG
1256
- _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(this, __get_pointer());}
1257
- _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());}
1258
- _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(this, __get_pointer() + size());}
1259
- _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return const_iterator(this, data() + size());}
1260
- #endif // _LIBCPP_DEBUG
1268
+ #endif // _LIBCPP_DEBUG_LEVEL >= 2
1261
1269
  _LIBCPP_INLINE_VISIBILITY
1262
1270
  reverse_iterator rbegin() _NOEXCEPT
1263
1271
  {return reverse_iterator(end());}
@@ -1520,6 +1528,15 @@ public:
1520
1528
  bool __is_long() const _NOEXCEPT
1521
1529
  {return bool(__r_.first().__s.__size_ & __short_mask);}
1522
1530
 
1531
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1532
+
1533
+ bool __dereferenceable(const const_iterator* __i) const;
1534
+ bool __decrementable(const const_iterator* __i) const;
1535
+ bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1536
+ bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1537
+
1538
+ #endif // _LIBCPP_DEBUG_LEVEL >= 2
1539
+
1523
1540
  private:
1524
1541
  _LIBCPP_INLINE_VISIBILITY
1525
1542
  allocator_type& __alloc() _NOEXCEPT
@@ -1615,13 +1632,13 @@ private:
1615
1632
 
1616
1633
  template <size_type __a> static
1617
1634
  _LIBCPP_INLINE_VISIBILITY
1618
- size_type __align(size_type __s) _NOEXCEPT
1635
+ size_type __align_it(size_type __s) _NOEXCEPT
1619
1636
  {return __s + (__a-1) & ~(__a-1);}
1620
1637
  enum {__alignment = 16};
1621
1638
  static _LIBCPP_INLINE_VISIBILITY
1622
1639
  size_type __recommend(size_type __s) _NOEXCEPT
1623
1640
  {return (__s < __min_cap ? __min_cap :
1624
- __align<sizeof(value_type) < __alignment ?
1641
+ __align_it<sizeof(value_type) < __alignment ?
1625
1642
  __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
1626
1643
 
1627
1644
  void __init(const value_type* __s, size_type __sz, size_type __reserve);
@@ -1732,75 +1749,64 @@ private:
1732
1749
  };
1733
1750
 
1734
1751
  template <class _CharT, class _Traits, class _Allocator>
1735
- #ifndef _LIBCPP_DEBUG
1736
- _LIBCPP_INLINE_VISIBILITY inline
1737
- #endif
1752
+ inline _LIBCPP_INLINE_VISIBILITY
1738
1753
  void
1739
1754
  basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1740
1755
  {
1741
- #ifdef _LIBCPP_DEBUG
1742
- iterator::__remove_all(this);
1743
- const_iterator::__remove_all(this);
1744
- #endif // _LIBCPP_DEBUG
1756
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1757
+ __get_db()->__invalidate_all(this);
1758
+ #endif // _LIBCPP_DEBUG_LEVEL >= 2
1745
1759
  }
1746
1760
 
1747
1761
  template <class _CharT, class _Traits, class _Allocator>
1748
- #ifndef _LIBCPP_DEBUG
1749
- _LIBCPP_INLINE_VISIBILITY inline
1750
- #endif
1762
+ inline _LIBCPP_INLINE_VISIBILITY
1751
1763
  void
1752
1764
  basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1753
- #ifdef _LIBCPP_DEBUG
1765
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1754
1766
  __pos
1755
1767
  #endif
1756
1768
  )
1757
1769
  {
1758
- #ifdef _LIBCPP_DEBUG
1759
- const_iterator __beg = begin();
1760
- if (__iterator_list_.first)
1761
- {
1762
- for (iterator* __p = __iterator_list_.first; __p;)
1763
- {
1764
- if (*__p - __beg > static_cast<difference_type>(__pos))
1765
- {
1766
- iterator* __n = __p;
1767
- __p = __p->__next;
1768
- __n->__remove_owner();
1769
- }
1770
- else
1771
- __p = __p->__next;
1772
- }
1773
- }
1774
- if (__iterator_list_.second)
1770
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1771
+ __c_node* __c = __get_db()->__find_c_and_lock(this);
1772
+ if (__c)
1775
1773
  {
1776
- for (const_iterator* __p = __iterator_list_.second; __p;)
1774
+ const_pointer __new_last = __get_pointer() + __pos;
1775
+ for (__i_node** __p = __c->end_; __p != __c->beg_; )
1777
1776
  {
1778
- if (*__p - __beg > static_cast<difference_type>(__pos))
1777
+ --__p;
1778
+ const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1779
+ if (__i->base() > __new_last)
1779
1780
  {
1780
- const_iterator* __n = __p;
1781
- __p = __p->__next;
1782
- __n->__remove_owner();
1781
+ (*__p)->__c_ = nullptr;
1782
+ if (--__c->end_ != __p)
1783
+ memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1783
1784
  }
1784
- else
1785
- __p = __p->__next;
1786
1785
  }
1786
+ __get_db()->unlock();
1787
1787
  }
1788
- #endif // _LIBCPP_DEBUG
1788
+ #endif // _LIBCPP_DEBUG_LEVEL >= 2
1789
1789
  }
1790
1790
 
1791
1791
  template <class _CharT, class _Traits, class _Allocator>
1792
- _LIBCPP_INLINE_VISIBILITY inline
1792
+ inline _LIBCPP_INLINE_VISIBILITY
1793
1793
  basic_string<_CharT, _Traits, _Allocator>::basic_string()
1794
1794
  _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1795
1795
  {
1796
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1797
+ __get_db()->__insert_c(this);
1798
+ #endif
1796
1799
  __zero();
1797
1800
  }
1798
1801
 
1799
1802
  template <class _CharT, class _Traits, class _Allocator>
1800
- _LIBCPP_INLINE_VISIBILITY inline
1803
+ inline _LIBCPP_INLINE_VISIBILITY
1801
1804
  basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1802
1805
  : __r_(__a)
1803
1806
  {
1807
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1808
+ __get_db()->__insert_c(this);
1809
+ #endif
1804
1810
  __zero();
1805
1811
  }
1806
1812
 
@@ -1853,45 +1859,49 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty
1853
1859
  }
1854
1860
 
1855
1861
  template <class _CharT, class _Traits, class _Allocator>
1856
- _LIBCPP_INLINE_VISIBILITY inline
1862
+ inline _LIBCPP_INLINE_VISIBILITY
1857
1863
  basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
1858
1864
  {
1859
- #ifdef _LIBCPP_DEBUG
1860
- assert(__s != 0);
1861
- #endif
1865
+ _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
1862
1866
  __init(__s, traits_type::length(__s));
1867
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1868
+ __get_db()->__insert_c(this);
1869
+ #endif
1863
1870
  }
1864
1871
 
1865
1872
  template <class _CharT, class _Traits, class _Allocator>
1866
- _LIBCPP_INLINE_VISIBILITY inline
1873
+ inline _LIBCPP_INLINE_VISIBILITY
1867
1874
  basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
1868
1875
  : __r_(__a)
1869
1876
  {
1870
- #ifdef _LIBCPP_DEBUG
1871
- assert(__s != 0);
1872
- #endif
1877
+ _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
1873
1878
  __init(__s, traits_type::length(__s));
1879
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1880
+ __get_db()->__insert_c(this);
1881
+ #endif
1874
1882
  }
1875
1883
 
1876
1884
  template <class _CharT, class _Traits, class _Allocator>
1877
- _LIBCPP_INLINE_VISIBILITY inline
1885
+ inline _LIBCPP_INLINE_VISIBILITY
1878
1886
  basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
1879
1887
  {
1880
- #ifdef _LIBCPP_DEBUG
1881
- assert(__s != 0);
1882
- #endif
1888
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
1883
1889
  __init(__s, __n);
1890
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1891
+ __get_db()->__insert_c(this);
1892
+ #endif
1884
1893
  }
1885
1894
 
1886
1895
  template <class _CharT, class _Traits, class _Allocator>
1887
- _LIBCPP_INLINE_VISIBILITY inline
1896
+ inline _LIBCPP_INLINE_VISIBILITY
1888
1897
  basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
1889
1898
  : __r_(__a)
1890
1899
  {
1891
- #ifdef _LIBCPP_DEBUG
1892
- assert(__s != 0);
1893
- #endif
1900
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
1894
1901
  __init(__s, __n);
1902
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1903
+ __get_db()->__insert_c(this);
1904
+ #endif
1895
1905
  }
1896
1906
 
1897
1907
  template <class _CharT, class _Traits, class _Allocator>
@@ -1902,6 +1912,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
1902
1912
  __r_.first().__r = __str.__r_.first().__r;
1903
1913
  else
1904
1914
  __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1915
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1916
+ __get_db()->__insert_c(this);
1917
+ #endif
1905
1918
  }
1906
1919
 
1907
1920
  template <class _CharT, class _Traits, class _Allocator>
@@ -1912,24 +1925,29 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
1912
1925
  __r_.first().__r = __str.__r_.first().__r;
1913
1926
  else
1914
1927
  __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1928
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1929
+ __get_db()->__insert_c(this);
1930
+ #endif
1915
1931
  }
1916
1932
 
1917
1933
  #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1918
1934
 
1919
1935
  template <class _CharT, class _Traits, class _Allocator>
1920
- _LIBCPP_INLINE_VISIBILITY inline
1936
+ inline _LIBCPP_INLINE_VISIBILITY
1921
1937
  basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1922
1938
  _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1923
1939
  : __r_(_VSTD::move(__str.__r_))
1924
1940
  {
1925
1941
  __str.__zero();
1926
- #ifdef _LIBCPP_DEBUG
1927
- __str.__invalidate_all_iterators();
1942
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1943
+ __get_db()->__insert_c(this);
1944
+ if (__is_long())
1945
+ __get_db()->swap(this, &__str);
1928
1946
  #endif
1929
1947
  }
1930
1948
 
1931
1949
  template <class _CharT, class _Traits, class _Allocator>
1932
- _LIBCPP_INLINE_VISIBILITY inline
1950
+ inline _LIBCPP_INLINE_VISIBILITY
1933
1951
  basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
1934
1952
  : __r_(__a)
1935
1953
  {
@@ -1938,8 +1956,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co
1938
1956
  else
1939
1957
  __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1940
1958
  __str.__zero();
1941
- #ifdef _LIBCPP_DEBUG
1942
- __str.__invalidate_all_iterators();
1959
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1960
+ __get_db()->__insert_c(this);
1961
+ if (__is_long())
1962
+ __get_db()->swap(this, &__str);
1943
1963
  #endif
1944
1964
  }
1945
1965
 
@@ -1970,18 +1990,24 @@ basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1970
1990
  }
1971
1991
 
1972
1992
  template <class _CharT, class _Traits, class _Allocator>
1973
- _LIBCPP_INLINE_VISIBILITY inline
1993
+ inline _LIBCPP_INLINE_VISIBILITY
1974
1994
  basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1975
1995
  {
1976
1996
  __init(__n, __c);
1997
+ #if _LIBCPP_DEBUG_LEVEL >= 2
1998
+ __get_db()->__insert_c(this);
1999
+ #endif
1977
2000
  }
1978
2001
 
1979
2002
  template <class _CharT, class _Traits, class _Allocator>
1980
- _LIBCPP_INLINE_VISIBILITY inline
2003
+ inline _LIBCPP_INLINE_VISIBILITY
1981
2004
  basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1982
2005
  : __r_(__a)
1983
2006
  {
1984
2007
  __init(__n, __c);
2008
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2009
+ __get_db()->__insert_c(this);
2010
+ #endif
1985
2011
  }
1986
2012
 
1987
2013
  template <class _CharT, class _Traits, class _Allocator>
@@ -1993,6 +2019,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
1993
2019
  if (__pos > __str_sz)
1994
2020
  this->__throw_out_of_range();
1995
2021
  __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
2022
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2023
+ __get_db()->__insert_c(this);
2024
+ #endif
1996
2025
  }
1997
2026
 
1998
2027
  template <class _CharT, class _Traits, class _Allocator>
@@ -2056,37 +2085,49 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _For
2056
2085
 
2057
2086
  template <class _CharT, class _Traits, class _Allocator>
2058
2087
  template<class _InputIterator>
2059
- _LIBCPP_INLINE_VISIBILITY inline
2088
+ inline _LIBCPP_INLINE_VISIBILITY
2060
2089
  basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2061
2090
  {
2062
2091
  __init(__first, __last);
2092
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2093
+ __get_db()->__insert_c(this);
2094
+ #endif
2063
2095
  }
2064
2096
 
2065
2097
  template <class _CharT, class _Traits, class _Allocator>
2066
2098
  template<class _InputIterator>
2067
- _LIBCPP_INLINE_VISIBILITY inline
2099
+ inline _LIBCPP_INLINE_VISIBILITY
2068
2100
  basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2069
2101
  const allocator_type& __a)
2070
2102
  : __r_(__a)
2071
2103
  {
2072
2104
  __init(__first, __last);
2105
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2106
+ __get_db()->__insert_c(this);
2107
+ #endif
2073
2108
  }
2074
2109
 
2075
2110
  #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2076
2111
 
2077
2112
  template <class _CharT, class _Traits, class _Allocator>
2078
- _LIBCPP_INLINE_VISIBILITY inline
2113
+ inline _LIBCPP_INLINE_VISIBILITY
2079
2114
  basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2080
2115
  {
2081
2116
  __init(__il.begin(), __il.end());
2117
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2118
+ __get_db()->__insert_c(this);
2119
+ #endif
2082
2120
  }
2083
2121
 
2084
2122
  template <class _CharT, class _Traits, class _Allocator>
2085
- _LIBCPP_INLINE_VISIBILITY inline
2123
+ inline _LIBCPP_INLINE_VISIBILITY
2086
2124
  basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2087
2125
  : __r_(__a)
2088
2126
  {
2089
2127
  __init(__il.begin(), __il.end());
2128
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2129
+ __get_db()->__insert_c(this);
2130
+ #endif
2090
2131
  }
2091
2132
 
2092
2133
  #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@@ -2094,7 +2135,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_t
2094
2135
  template <class _CharT, class _Traits, class _Allocator>
2095
2136
  basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2096
2137
  {
2097
- __invalidate_all_iterators();
2138
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2139
+ __get_db()->__erase_c(this);
2140
+ #endif
2098
2141
  if (__is_long())
2099
2142
  __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2100
2143
  }
@@ -2138,7 +2181,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t
2138
2181
  size_type __n_copy, size_type __n_del, size_type __n_add)
2139
2182
  {
2140
2183
  size_type __ms = max_size();
2141
- if (__delta_cap > __ms - __old_cap - 1)
2184
+ if (__delta_cap > __ms - __old_cap)
2142
2185
  this->__throw_length_error();
2143
2186
  pointer __old_p = __get_pointer();
2144
2187
  size_type __cap = __old_cap < __ms / 2 - __alignment ?
@@ -2166,9 +2209,7 @@ template <class _CharT, class _Traits, class _Allocator>
2166
2209
  basic_string<_CharT, _Traits, _Allocator>&
2167
2210
  basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
2168
2211
  {
2169
- #ifdef _LIBCPP_DEBUG
2170
- assert(__s != 0);
2171
- #endif
2212
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign recieved nullptr");
2172
2213
  size_type __cap = capacity();
2173
2214
  if (__cap >= __n)
2174
2215
  {
@@ -2241,7 +2282,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2241
2282
  #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2242
2283
 
2243
2284
  template <class _CharT, class _Traits, class _Allocator>
2244
- _LIBCPP_INLINE_VISIBILITY inline
2285
+ inline _LIBCPP_INLINE_VISIBILITY
2245
2286
  void
2246
2287
  basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2247
2288
  {
@@ -2252,7 +2293,7 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, fa
2252
2293
  }
2253
2294
 
2254
2295
  template <class _CharT, class _Traits, class _Allocator>
2255
- _LIBCPP_INLINE_VISIBILITY inline
2296
+ inline _LIBCPP_INLINE_VISIBILITY
2256
2297
  void
2257
2298
  basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2258
2299
  _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
@@ -2265,7 +2306,7 @@ basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, tr
2265
2306
  }
2266
2307
 
2267
2308
  template <class _CharT, class _Traits, class _Allocator>
2268
- _LIBCPP_INLINE_VISIBILITY inline
2309
+ inline _LIBCPP_INLINE_VISIBILITY
2269
2310
  basic_string<_CharT, _Traits, _Allocator>&
2270
2311
  basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
2271
2312
  _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
@@ -2321,7 +2362,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _For
2321
2362
  }
2322
2363
 
2323
2364
  template <class _CharT, class _Traits, class _Allocator>
2324
- _LIBCPP_INLINE_VISIBILITY inline
2365
+ inline _LIBCPP_INLINE_VISIBILITY
2325
2366
  basic_string<_CharT, _Traits, _Allocator>&
2326
2367
  basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2327
2368
  {
@@ -2342,9 +2383,7 @@ template <class _CharT, class _Traits, class _Allocator>
2342
2383
  basic_string<_CharT, _Traits, _Allocator>&
2343
2384
  basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
2344
2385
  {
2345
- #ifdef _LIBCPP_DEBUG
2346
- assert(__s != 0);
2347
- #endif
2386
+ _LIBCPP_ASSERT(__s != nullptr, "string::assign recieved nullptr");
2348
2387
  return assign(__s, traits_type::length(__s));
2349
2388
  }
2350
2389
 
@@ -2354,9 +2393,7 @@ template <class _CharT, class _Traits, class _Allocator>
2354
2393
  basic_string<_CharT, _Traits, _Allocator>&
2355
2394
  basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
2356
2395
  {
2357
- #ifdef _LIBCPP_DEBUG
2358
- assert(__s != 0);
2359
- #endif
2396
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append recieved nullptr");
2360
2397
  size_type __cap = capacity();
2361
2398
  size_type __sz = size();
2362
2399
  if (__cap - __sz >= __n)
@@ -2472,7 +2509,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _For
2472
2509
  }
2473
2510
 
2474
2511
  template <class _CharT, class _Traits, class _Allocator>
2475
- _LIBCPP_INLINE_VISIBILITY inline
2512
+ inline _LIBCPP_INLINE_VISIBILITY
2476
2513
  basic_string<_CharT, _Traits, _Allocator>&
2477
2514
  basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2478
2515
  {
@@ -2493,9 +2530,7 @@ template <class _CharT, class _Traits, class _Allocator>
2493
2530
  basic_string<_CharT, _Traits, _Allocator>&
2494
2531
  basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
2495
2532
  {
2496
- #ifdef _LIBCPP_DEBUG
2497
- assert(__s != 0);
2498
- #endif
2533
+ _LIBCPP_ASSERT(__s != nullptr, "string::append recieved nullptr");
2499
2534
  return append(__s, traits_type::length(__s));
2500
2535
  }
2501
2536
 
@@ -2505,9 +2540,7 @@ template <class _CharT, class _Traits, class _Allocator>
2505
2540
  basic_string<_CharT, _Traits, _Allocator>&
2506
2541
  basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
2507
2542
  {
2508
- #ifdef _LIBCPP_DEBUG
2509
- assert(__s != 0);
2510
- #endif
2543
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert recieved nullptr");
2511
2544
  size_type __sz = size();
2512
2545
  if (__pos > __sz)
2513
2546
  this->__throw_out_of_range();
@@ -2576,13 +2609,22 @@ typename enable_if
2576
2609
  >::type
2577
2610
  basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2578
2611
  {
2612
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2613
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2614
+ "string::insert(iterator, range) called with an iterator not"
2615
+ " referring to this string");
2616
+ #endif
2579
2617
  size_type __old_sz = size();
2580
2618
  difference_type __ip = __pos - begin();
2581
2619
  for (; __first != __last; ++__first)
2582
2620
  push_back(*__first);
2583
2621
  pointer __p = __get_pointer();
2584
2622
  _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
2623
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2624
+ return iterator(this, __p + __ip);
2625
+ #else
2585
2626
  return iterator(__p + __ip);
2627
+ #endif
2586
2628
  }
2587
2629
 
2588
2630
  template <class _CharT, class _Traits, class _Allocator>
@@ -2594,6 +2636,11 @@ typename enable_if
2594
2636
  >::type
2595
2637
  basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2596
2638
  {
2639
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2640
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2641
+ "string::insert(iterator, range) called with an iterator not"
2642
+ " referring to this string");
2643
+ #endif
2597
2644
  size_type __ip = static_cast<size_type>(__pos - begin());
2598
2645
  size_type __sz = size();
2599
2646
  size_type __cap = capacity();
@@ -2623,7 +2670,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _Forward
2623
2670
  }
2624
2671
 
2625
2672
  template <class _CharT, class _Traits, class _Allocator>
2626
- _LIBCPP_INLINE_VISIBILITY inline
2673
+ inline _LIBCPP_INLINE_VISIBILITY
2627
2674
  basic_string<_CharT, _Traits, _Allocator>&
2628
2675
  basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2629
2676
  {
@@ -2645,9 +2692,7 @@ template <class _CharT, class _Traits, class _Allocator>
2645
2692
  basic_string<_CharT, _Traits, _Allocator>&
2646
2693
  basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
2647
2694
  {
2648
- #ifdef _LIBCPP_DEBUG
2649
- assert(__s != 0);
2650
- #endif
2695
+ _LIBCPP_ASSERT(__s != nullptr, "string::insert recieved nullptr");
2651
2696
  return insert(__pos, __s, traits_type::length(__s));
2652
2697
  }
2653
2698
 
@@ -2678,10 +2723,15 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_ty
2678
2723
  }
2679
2724
 
2680
2725
  template <class _CharT, class _Traits, class _Allocator>
2681
- _LIBCPP_INLINE_VISIBILITY inline
2726
+ inline _LIBCPP_INLINE_VISIBILITY
2682
2727
  typename basic_string<_CharT, _Traits, _Allocator>::iterator
2683
2728
  basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2684
2729
  {
2730
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2731
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2732
+ "string::insert(iterator, n, value) called with an iterator not"
2733
+ " referring to this string");
2734
+ #endif
2685
2735
  difference_type __p = __pos - begin();
2686
2736
  insert(static_cast<size_type>(__p), __n, __c);
2687
2737
  return begin() + __p;
@@ -2693,9 +2743,7 @@ template <class _CharT, class _Traits, class _Allocator>
2693
2743
  basic_string<_CharT, _Traits, _Allocator>&
2694
2744
  basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
2695
2745
  {
2696
- #ifdef _LIBCPP_DEBUG
2697
- assert(__s != 0);
2698
- #endif
2746
+ _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace recieved nullptr");
2699
2747
  size_type __sz = size();
2700
2748
  if (__pos > __sz)
2701
2749
  this->__throw_out_of_range();
@@ -2805,7 +2853,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
2805
2853
  }
2806
2854
 
2807
2855
  template <class _CharT, class _Traits, class _Allocator>
2808
- _LIBCPP_INLINE_VISIBILITY inline
2856
+ inline _LIBCPP_INLINE_VISIBILITY
2809
2857
  basic_string<_CharT, _Traits, _Allocator>&
2810
2858
  basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2811
2859
  {
@@ -2827,14 +2875,12 @@ template <class _CharT, class _Traits, class _Allocator>
2827
2875
  basic_string<_CharT, _Traits, _Allocator>&
2828
2876
  basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
2829
2877
  {
2830
- #ifdef _LIBCPP_DEBUG
2831
- assert(__s != 0);
2832
- #endif
2878
+ _LIBCPP_ASSERT(__s != nullptr, "string::replace recieved nullptr");
2833
2879
  return replace(__pos, __n1, __s, traits_type::length(__s));
2834
2880
  }
2835
2881
 
2836
2882
  template <class _CharT, class _Traits, class _Allocator>
2837
- _LIBCPP_INLINE_VISIBILITY inline
2883
+ inline _LIBCPP_INLINE_VISIBILITY
2838
2884
  basic_string<_CharT, _Traits, _Allocator>&
2839
2885
  basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
2840
2886
  {
@@ -2843,7 +2889,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
2843
2889
  }
2844
2890
 
2845
2891
  template <class _CharT, class _Traits, class _Allocator>
2846
- _LIBCPP_INLINE_VISIBILITY inline
2892
+ inline _LIBCPP_INLINE_VISIBILITY
2847
2893
  basic_string<_CharT, _Traits, _Allocator>&
2848
2894
  basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
2849
2895
  {
@@ -2851,7 +2897,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
2851
2897
  }
2852
2898
 
2853
2899
  template <class _CharT, class _Traits, class _Allocator>
2854
- _LIBCPP_INLINE_VISIBILITY inline
2900
+ inline _LIBCPP_INLINE_VISIBILITY
2855
2901
  basic_string<_CharT, _Traits, _Allocator>&
2856
2902
  basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
2857
2903
  {
@@ -2859,7 +2905,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
2859
2905
  }
2860
2906
 
2861
2907
  template <class _CharT, class _Traits, class _Allocator>
2862
- _LIBCPP_INLINE_VISIBILITY inline
2908
+ inline _LIBCPP_INLINE_VISIBILITY
2863
2909
  basic_string<_CharT, _Traits, _Allocator>&
2864
2910
  basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
2865
2911
  {
@@ -2891,10 +2937,17 @@ basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2891
2937
  }
2892
2938
 
2893
2939
  template <class _CharT, class _Traits, class _Allocator>
2894
- _LIBCPP_INLINE_VISIBILITY inline
2940
+ inline _LIBCPP_INLINE_VISIBILITY
2895
2941
  typename basic_string<_CharT, _Traits, _Allocator>::iterator
2896
2942
  basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2897
2943
  {
2944
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2945
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2946
+ "string::erase(iterator) called with an iterator not"
2947
+ " referring to this string");
2948
+ #endif
2949
+ _LIBCPP_ASSERT(__pos != end(),
2950
+ "string::erase(iterator) called with a non-dereferenceable iterator");
2898
2951
  iterator __b = begin();
2899
2952
  size_type __r = static_cast<size_type>(__pos - __b);
2900
2953
  erase(__r, 1);
@@ -2902,10 +2955,16 @@ basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2902
2955
  }
2903
2956
 
2904
2957
  template <class _CharT, class _Traits, class _Allocator>
2905
- _LIBCPP_INLINE_VISIBILITY inline
2958
+ inline _LIBCPP_INLINE_VISIBILITY
2906
2959
  typename basic_string<_CharT, _Traits, _Allocator>::iterator
2907
2960
  basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2908
2961
  {
2962
+ #if _LIBCPP_DEBUG_LEVEL >= 2
2963
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2964
+ "string::erase(iterator, iterator) called with an iterator not"
2965
+ " referring to this string");
2966
+ #endif
2967
+ _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
2909
2968
  iterator __b = begin();
2910
2969
  size_type __r = static_cast<size_type>(__first - __b);
2911
2970
  erase(__r, static_cast<size_type>(__last - __first));
@@ -2913,13 +2972,11 @@ basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_i
2913
2972
  }
2914
2973
 
2915
2974
  template <class _CharT, class _Traits, class _Allocator>
2916
- _LIBCPP_INLINE_VISIBILITY inline
2975
+ inline _LIBCPP_INLINE_VISIBILITY
2917
2976
  void
2918
2977
  basic_string<_CharT, _Traits, _Allocator>::pop_back()
2919
2978
  {
2920
- #ifdef _LIBCPP_DEBUG
2921
- assert(!empty());
2922
- #endif
2979
+ _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
2923
2980
  size_type __sz;
2924
2981
  if (__is_long())
2925
2982
  {
@@ -2937,7 +2994,7 @@ basic_string<_CharT, _Traits, _Allocator>::pop_back()
2937
2994
  }
2938
2995
 
2939
2996
  template <class _CharT, class _Traits, class _Allocator>
2940
- _LIBCPP_INLINE_VISIBILITY inline
2997
+ inline _LIBCPP_INLINE_VISIBILITY
2941
2998
  void
2942
2999
  basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
2943
3000
  {
@@ -2955,7 +3012,7 @@ basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
2955
3012
  }
2956
3013
 
2957
3014
  template <class _CharT, class _Traits, class _Allocator>
2958
- _LIBCPP_INLINE_VISIBILITY inline
3015
+ inline _LIBCPP_INLINE_VISIBILITY
2959
3016
  void
2960
3017
  basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2961
3018
  {
@@ -2984,15 +3041,15 @@ basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2984
3041
  }
2985
3042
 
2986
3043
  template <class _CharT, class _Traits, class _Allocator>
2987
- _LIBCPP_INLINE_VISIBILITY inline
3044
+ inline _LIBCPP_INLINE_VISIBILITY
2988
3045
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
2989
3046
  basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
2990
3047
  {
2991
3048
  size_type __m = __alloc_traits::max_size(__alloc());
2992
3049
  #if _LIBCPP_BIG_ENDIAN
2993
- return (__m <= ~__long_mask ? __m : __m/2) - 1;
3050
+ return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
2994
3051
  #else
2995
- return __m - 1;
3052
+ return __m - __alignment;
2996
3053
  #endif
2997
3054
  }
2998
3055
 
@@ -3060,24 +3117,20 @@ basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3060
3117
  }
3061
3118
 
3062
3119
  template <class _CharT, class _Traits, class _Allocator>
3063
- _LIBCPP_INLINE_VISIBILITY inline
3120
+ inline _LIBCPP_INLINE_VISIBILITY
3064
3121
  typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3065
3122
  basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3066
3123
  {
3067
- #ifdef __LIBCPP_DEBUG
3068
- assert(__pos <= size());
3069
- #endif
3124
+ _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3070
3125
  return *(data() + __pos);
3071
3126
  }
3072
3127
 
3073
3128
  template <class _CharT, class _Traits, class _Allocator>
3074
- _LIBCPP_INLINE_VISIBILITY inline
3129
+ inline _LIBCPP_INLINE_VISIBILITY
3075
3130
  typename basic_string<_CharT, _Traits, _Allocator>::reference
3076
3131
  basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3077
3132
  {
3078
- #ifdef __LIBCPP_DEBUG
3079
- assert(__pos < size());
3080
- #endif
3133
+ _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3081
3134
  return *(__get_pointer() + __pos);
3082
3135
  }
3083
3136
 
@@ -3100,46 +3153,38 @@ basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3100
3153
  }
3101
3154
 
3102
3155
  template <class _CharT, class _Traits, class _Allocator>
3103
- _LIBCPP_INLINE_VISIBILITY inline
3156
+ inline _LIBCPP_INLINE_VISIBILITY
3104
3157
  typename basic_string<_CharT, _Traits, _Allocator>::reference
3105
3158
  basic_string<_CharT, _Traits, _Allocator>::front()
3106
3159
  {
3107
- #ifdef _LIBCPP_DEBUG
3108
- assert(!empty());
3109
- #endif
3160
+ _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3110
3161
  return *__get_pointer();
3111
3162
  }
3112
3163
 
3113
3164
  template <class _CharT, class _Traits, class _Allocator>
3114
- _LIBCPP_INLINE_VISIBILITY inline
3165
+ inline _LIBCPP_INLINE_VISIBILITY
3115
3166
  typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3116
3167
  basic_string<_CharT, _Traits, _Allocator>::front() const
3117
3168
  {
3118
- #ifdef _LIBCPP_DEBUG
3119
- assert(!empty());
3120
- #endif
3169
+ _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3121
3170
  return *data();
3122
3171
  }
3123
3172
 
3124
3173
  template <class _CharT, class _Traits, class _Allocator>
3125
- _LIBCPP_INLINE_VISIBILITY inline
3174
+ inline _LIBCPP_INLINE_VISIBILITY
3126
3175
  typename basic_string<_CharT, _Traits, _Allocator>::reference
3127
3176
  basic_string<_CharT, _Traits, _Allocator>::back()
3128
3177
  {
3129
- #ifdef _LIBCPP_DEBUG
3130
- assert(!empty());
3131
- #endif
3178
+ _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3132
3179
  return *(__get_pointer() + size() - 1);
3133
3180
  }
3134
3181
 
3135
3182
  template <class _CharT, class _Traits, class _Allocator>
3136
- _LIBCPP_INLINE_VISIBILITY inline
3183
+ inline _LIBCPP_INLINE_VISIBILITY
3137
3184
  typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3138
3185
  basic_string<_CharT, _Traits, _Allocator>::back() const
3139
3186
  {
3140
- #ifdef _LIBCPP_DEBUG
3141
- assert(!empty());
3142
- #endif
3187
+ _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3143
3188
  return *(data() + size() - 1);
3144
3189
  }
3145
3190
 
@@ -3156,7 +3201,7 @@ basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n,
3156
3201
  }
3157
3202
 
3158
3203
  template <class _CharT, class _Traits, class _Allocator>
3159
- _LIBCPP_INLINE_VISIBILITY inline
3204
+ inline _LIBCPP_INLINE_VISIBILITY
3160
3205
  basic_string<_CharT, _Traits, _Allocator>
3161
3206
  basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3162
3207
  {
@@ -3164,18 +3209,21 @@ basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n
3164
3209
  }
3165
3210
 
3166
3211
  template <class _CharT, class _Traits, class _Allocator>
3167
- _LIBCPP_INLINE_VISIBILITY inline
3212
+ inline _LIBCPP_INLINE_VISIBILITY
3168
3213
  void
3169
3214
  basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3170
3215
  _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3171
3216
  __is_nothrow_swappable<allocator_type>::value)
3172
3217
  {
3218
+ #if _LIBCPP_DEBUG_LEVEL >= 2
3219
+ if (!__is_long())
3220
+ __get_db()->__invalidate_all(this);
3221
+ if (!__str.__is_long())
3222
+ __get_db()->__invalidate_all(&__str);
3223
+ __get_db()->swap(this, &__str);
3224
+ #endif
3173
3225
  _VSTD::swap(__r_.first(), __str.__r_.first());
3174
3226
  __swap_alloc(__alloc(), __str.__alloc());
3175
- #ifdef _LIBCPP_DEBUG
3176
- __invalidate_all_iterators();
3177
- __str.__invalidate_all_iterators();
3178
- #endif // _LIBCPP_DEBUG
3179
3227
  }
3180
3228
 
3181
3229
  // find
@@ -3195,9 +3243,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3195
3243
  size_type __pos,
3196
3244
  size_type __n) const _NOEXCEPT
3197
3245
  {
3198
- #ifdef _LIBCPP_DEBUG
3199
- assert(__s != 0);
3200
- #endif
3246
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): recieved nullptr");
3201
3247
  size_type __sz = size();
3202
3248
  if (__pos > __sz || __sz - __pos < __n)
3203
3249
  return npos;
@@ -3212,7 +3258,7 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3212
3258
  }
3213
3259
 
3214
3260
  template<class _CharT, class _Traits, class _Allocator>
3215
- _LIBCPP_INLINE_VISIBILITY inline
3261
+ inline _LIBCPP_INLINE_VISIBILITY
3216
3262
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3217
3263
  basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3218
3264
  size_type __pos) const _NOEXCEPT
@@ -3221,14 +3267,12 @@ basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3221
3267
  }
3222
3268
 
3223
3269
  template<class _CharT, class _Traits, class _Allocator>
3224
- _LIBCPP_INLINE_VISIBILITY inline
3270
+ inline _LIBCPP_INLINE_VISIBILITY
3225
3271
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3226
3272
  basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3227
3273
  size_type __pos) const _NOEXCEPT
3228
3274
  {
3229
- #ifdef _LIBCPP_DEBUG
3230
- assert(__s != 0);
3231
- #endif
3275
+ _LIBCPP_ASSERT(__s != nullptr, "string::find(): recieved nullptr");
3232
3276
  return find(__s, __pos, traits_type::length(__s));
3233
3277
  }
3234
3278
 
@@ -3255,9 +3299,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3255
3299
  size_type __pos,
3256
3300
  size_type __n) const _NOEXCEPT
3257
3301
  {
3258
- #ifdef _LIBCPP_DEBUG
3259
- assert(__s != 0);
3260
- #endif
3302
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): recieved nullptr");
3261
3303
  size_type __sz = size();
3262
3304
  __pos = _VSTD::min(__pos, __sz);
3263
3305
  if (__n < __sz - __pos)
@@ -3273,7 +3315,7 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3273
3315
  }
3274
3316
 
3275
3317
  template<class _CharT, class _Traits, class _Allocator>
3276
- _LIBCPP_INLINE_VISIBILITY inline
3318
+ inline _LIBCPP_INLINE_VISIBILITY
3277
3319
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3278
3320
  basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3279
3321
  size_type __pos) const _NOEXCEPT
@@ -3282,14 +3324,12 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3282
3324
  }
3283
3325
 
3284
3326
  template<class _CharT, class _Traits, class _Allocator>
3285
- _LIBCPP_INLINE_VISIBILITY inline
3327
+ inline _LIBCPP_INLINE_VISIBILITY
3286
3328
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3287
3329
  basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3288
3330
  size_type __pos) const _NOEXCEPT
3289
3331
  {
3290
- #ifdef _LIBCPP_DEBUG
3291
- assert(__s != 0);
3292
- #endif
3332
+ _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): recieved nullptr");
3293
3333
  return rfind(__s, __pos, traits_type::length(__s));
3294
3334
  }
3295
3335
 
@@ -3323,9 +3363,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3323
3363
  size_type __pos,
3324
3364
  size_type __n) const _NOEXCEPT
3325
3365
  {
3326
- #ifdef _LIBCPP_DEBUG
3327
- assert(__s != 0);
3328
- #endif
3366
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): recieved nullptr");
3329
3367
  size_type __sz = size();
3330
3368
  if (__pos >= __sz || __n == 0)
3331
3369
  return npos;
@@ -3338,7 +3376,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3338
3376
  }
3339
3377
 
3340
3378
  template<class _CharT, class _Traits, class _Allocator>
3341
- _LIBCPP_INLINE_VISIBILITY inline
3379
+ inline _LIBCPP_INLINE_VISIBILITY
3342
3380
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3343
3381
  basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3344
3382
  size_type __pos) const _NOEXCEPT
@@ -3347,19 +3385,17 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __s
3347
3385
  }
3348
3386
 
3349
3387
  template<class _CharT, class _Traits, class _Allocator>
3350
- _LIBCPP_INLINE_VISIBILITY inline
3388
+ inline _LIBCPP_INLINE_VISIBILITY
3351
3389
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3352
3390
  basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3353
3391
  size_type __pos) const _NOEXCEPT
3354
3392
  {
3355
- #ifdef _LIBCPP_DEBUG
3356
- assert(__s != 0);
3357
- #endif
3393
+ _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): recieved nullptr");
3358
3394
  return find_first_of(__s, __pos, traits_type::length(__s));
3359
3395
  }
3360
3396
 
3361
3397
  template<class _CharT, class _Traits, class _Allocator>
3362
- _LIBCPP_INLINE_VISIBILITY inline
3398
+ inline _LIBCPP_INLINE_VISIBILITY
3363
3399
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3364
3400
  basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3365
3401
  size_type __pos) const _NOEXCEPT
@@ -3375,9 +3411,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3375
3411
  size_type __pos,
3376
3412
  size_type __n) const _NOEXCEPT
3377
3413
  {
3378
- #ifdef _LIBCPP_DEBUG
3379
- assert(__s != 0);
3380
- #endif
3414
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): recieved nullptr");
3381
3415
  if (__n != 0)
3382
3416
  {
3383
3417
  size_type __sz = size();
@@ -3397,7 +3431,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3397
3431
  }
3398
3432
 
3399
3433
  template<class _CharT, class _Traits, class _Allocator>
3400
- _LIBCPP_INLINE_VISIBILITY inline
3434
+ inline _LIBCPP_INLINE_VISIBILITY
3401
3435
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3402
3436
  basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3403
3437
  size_type __pos) const _NOEXCEPT
@@ -3406,19 +3440,17 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __st
3406
3440
  }
3407
3441
 
3408
3442
  template<class _CharT, class _Traits, class _Allocator>
3409
- _LIBCPP_INLINE_VISIBILITY inline
3443
+ inline _LIBCPP_INLINE_VISIBILITY
3410
3444
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3411
3445
  basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3412
3446
  size_type __pos) const _NOEXCEPT
3413
3447
  {
3414
- #ifdef _LIBCPP_DEBUG
3415
- assert(__s != 0);
3416
- #endif
3448
+ _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): recieved nullptr");
3417
3449
  return find_last_of(__s, __pos, traits_type::length(__s));
3418
3450
  }
3419
3451
 
3420
3452
  template<class _CharT, class _Traits, class _Allocator>
3421
- _LIBCPP_INLINE_VISIBILITY inline
3453
+ inline _LIBCPP_INLINE_VISIBILITY
3422
3454
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3423
3455
  basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3424
3456
  size_type __pos) const _NOEXCEPT
@@ -3434,9 +3466,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _
3434
3466
  size_type __pos,
3435
3467
  size_type __n) const _NOEXCEPT
3436
3468
  {
3437
- #ifdef _LIBCPP_DEBUG
3438
- assert(__s != 0);
3439
- #endif
3469
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): recieved nullptr");
3440
3470
  size_type __sz = size();
3441
3471
  if (__pos < __sz)
3442
3472
  {
@@ -3450,7 +3480,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* _
3450
3480
  }
3451
3481
 
3452
3482
  template<class _CharT, class _Traits, class _Allocator>
3453
- _LIBCPP_INLINE_VISIBILITY inline
3483
+ inline _LIBCPP_INLINE_VISIBILITY
3454
3484
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3455
3485
  basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3456
3486
  size_type __pos) const _NOEXCEPT
@@ -3459,19 +3489,17 @@ basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string&
3459
3489
  }
3460
3490
 
3461
3491
  template<class _CharT, class _Traits, class _Allocator>
3462
- _LIBCPP_INLINE_VISIBILITY inline
3492
+ inline _LIBCPP_INLINE_VISIBILITY
3463
3493
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3464
3494
  basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3465
3495
  size_type __pos) const _NOEXCEPT
3466
3496
  {
3467
- #ifdef _LIBCPP_DEBUG
3468
- assert(__s != 0);
3469
- #endif
3497
+ _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): recieved nullptr");
3470
3498
  return find_first_not_of(__s, __pos, traits_type::length(__s));
3471
3499
  }
3472
3500
 
3473
3501
  template<class _CharT, class _Traits, class _Allocator>
3474
- _LIBCPP_INLINE_VISIBILITY inline
3502
+ inline _LIBCPP_INLINE_VISIBILITY
3475
3503
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3476
3504
  basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3477
3505
  size_type __pos) const _NOEXCEPT
@@ -3496,9 +3524,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __
3496
3524
  size_type __pos,
3497
3525
  size_type __n) const _NOEXCEPT
3498
3526
  {
3499
- #ifdef _LIBCPP_DEBUG
3500
- assert(__s != 0);
3501
- #endif
3527
+ _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): recieved nullptr");
3502
3528
  size_type __sz = size();
3503
3529
  if (__pos < __sz)
3504
3530
  ++__pos;
@@ -3512,7 +3538,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __
3512
3538
  }
3513
3539
 
3514
3540
  template<class _CharT, class _Traits, class _Allocator>
3515
- _LIBCPP_INLINE_VISIBILITY inline
3541
+ inline _LIBCPP_INLINE_VISIBILITY
3516
3542
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3517
3543
  basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3518
3544
  size_type __pos) const _NOEXCEPT
@@ -3521,19 +3547,17 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string&
3521
3547
  }
3522
3548
 
3523
3549
  template<class _CharT, class _Traits, class _Allocator>
3524
- _LIBCPP_INLINE_VISIBILITY inline
3550
+ inline _LIBCPP_INLINE_VISIBILITY
3525
3551
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3526
3552
  basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3527
3553
  size_type __pos) const _NOEXCEPT
3528
3554
  {
3529
- #ifdef _LIBCPP_DEBUG
3530
- assert(__s != 0);
3531
- #endif
3555
+ _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): recieved nullptr");
3532
3556
  return find_last_not_of(__s, __pos, traits_type::length(__s));
3533
3557
  }
3534
3558
 
3535
3559
  template<class _CharT, class _Traits, class _Allocator>
3536
- _LIBCPP_INLINE_VISIBILITY inline
3560
+ inline _LIBCPP_INLINE_VISIBILITY
3537
3561
  typename basic_string<_CharT, _Traits, _Allocator>::size_type
3538
3562
  basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3539
3563
  size_type __pos) const _NOEXCEPT
@@ -3553,7 +3577,7 @@ basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3553
3577
  // compare
3554
3578
 
3555
3579
  template <class _CharT, class _Traits, class _Allocator>
3556
- _LIBCPP_INLINE_VISIBILITY inline
3580
+ inline _LIBCPP_INLINE_VISIBILITY
3557
3581
  int
3558
3582
  basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
3559
3583
  {
@@ -3571,7 +3595,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) co
3571
3595
  }
3572
3596
 
3573
3597
  template <class _CharT, class _Traits, class _Allocator>
3574
- _LIBCPP_INLINE_VISIBILITY inline
3598
+ inline _LIBCPP_INLINE_VISIBILITY
3575
3599
  int
3576
3600
  basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3577
3601
  size_type __n1,
@@ -3599,9 +3623,7 @@ template <class _CharT, class _Traits, class _Allocator>
3599
3623
  int
3600
3624
  basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3601
3625
  {
3602
- #ifdef _LIBCPP_DEBUG
3603
- assert(__s != 0);
3604
- #endif
3626
+ _LIBCPP_ASSERT(__s != nullptr, "string::compare(): recieved nullptr");
3605
3627
  return compare(0, npos, __s, traits_type::length(__s));
3606
3628
  }
3607
3629
 
@@ -3611,9 +3633,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3611
3633
  size_type __n1,
3612
3634
  const value_type* __s) const
3613
3635
  {
3614
- #ifdef _LIBCPP_DEBUG
3615
- assert(__s != 0);
3616
- #endif
3636
+ _LIBCPP_ASSERT(__s != nullptr, "string::compare(): recieved nullptr");
3617
3637
  return compare(__pos1, __n1, __s, traits_type::length(__s));
3618
3638
  }
3619
3639
 
@@ -3624,9 +3644,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3624
3644
  const value_type* __s,
3625
3645
  size_type __n2) const
3626
3646
  {
3627
- #ifdef _LIBCPP_DEBUG
3628
- assert(__s != 0);
3629
- #endif
3647
+ _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): recieved nullptr");
3630
3648
  size_type __sz = size();
3631
3649
  if (__pos1 > __sz || __n2 == npos)
3632
3650
  this->__throw_out_of_range();
@@ -3645,7 +3663,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3645
3663
  // __invariants
3646
3664
 
3647
3665
  template<class _CharT, class _Traits, class _Allocator>
3648
- _LIBCPP_INLINE_VISIBILITY inline
3666
+ inline _LIBCPP_INLINE_VISIBILITY
3649
3667
  bool
3650
3668
  basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3651
3669
  {
@@ -3663,7 +3681,7 @@ basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3663
3681
  // operator==
3664
3682
 
3665
3683
  template<class _CharT, class _Traits, class _Allocator>
3666
- _LIBCPP_INLINE_VISIBILITY inline
3684
+ inline _LIBCPP_INLINE_VISIBILITY
3667
3685
  bool
3668
3686
  operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3669
3687
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3675,7 +3693,7 @@ operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3675
3693
  }
3676
3694
 
3677
3695
  template<class _Allocator>
3678
- _LIBCPP_INLINE_VISIBILITY inline
3696
+ inline _LIBCPP_INLINE_VISIBILITY
3679
3697
  bool
3680
3698
  operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3681
3699
  const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
@@ -3694,7 +3712,7 @@ operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3694
3712
  }
3695
3713
 
3696
3714
  template<class _CharT, class _Traits, class _Allocator>
3697
- _LIBCPP_INLINE_VISIBILITY inline
3715
+ inline _LIBCPP_INLINE_VISIBILITY
3698
3716
  bool
3699
3717
  operator==(const _CharT* __lhs,
3700
3718
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3703,7 +3721,7 @@ operator==(const _CharT* __lhs,
3703
3721
  }
3704
3722
 
3705
3723
  template<class _CharT, class _Traits, class _Allocator>
3706
- _LIBCPP_INLINE_VISIBILITY inline
3724
+ inline _LIBCPP_INLINE_VISIBILITY
3707
3725
  bool
3708
3726
  operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3709
3727
  const _CharT* __rhs) _NOEXCEPT
@@ -3714,7 +3732,7 @@ operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3714
3732
  // operator!=
3715
3733
 
3716
3734
  template<class _CharT, class _Traits, class _Allocator>
3717
- _LIBCPP_INLINE_VISIBILITY inline
3735
+ inline _LIBCPP_INLINE_VISIBILITY
3718
3736
  bool
3719
3737
  operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3720
3738
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3723,7 +3741,7 @@ operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3723
3741
  }
3724
3742
 
3725
3743
  template<class _CharT, class _Traits, class _Allocator>
3726
- _LIBCPP_INLINE_VISIBILITY inline
3744
+ inline _LIBCPP_INLINE_VISIBILITY
3727
3745
  bool
3728
3746
  operator!=(const _CharT* __lhs,
3729
3747
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3732,7 +3750,7 @@ operator!=(const _CharT* __lhs,
3732
3750
  }
3733
3751
 
3734
3752
  template<class _CharT, class _Traits, class _Allocator>
3735
- _LIBCPP_INLINE_VISIBILITY inline
3753
+ inline _LIBCPP_INLINE_VISIBILITY
3736
3754
  bool
3737
3755
  operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3738
3756
  const _CharT* __rhs) _NOEXCEPT
@@ -3743,7 +3761,7 @@ operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3743
3761
  // operator<
3744
3762
 
3745
3763
  template<class _CharT, class _Traits, class _Allocator>
3746
- _LIBCPP_INLINE_VISIBILITY inline
3764
+ inline _LIBCPP_INLINE_VISIBILITY
3747
3765
  bool
3748
3766
  operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3749
3767
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3752,7 +3770,7 @@ operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3752
3770
  }
3753
3771
 
3754
3772
  template<class _CharT, class _Traits, class _Allocator>
3755
- _LIBCPP_INLINE_VISIBILITY inline
3773
+ inline _LIBCPP_INLINE_VISIBILITY
3756
3774
  bool
3757
3775
  operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3758
3776
  const _CharT* __rhs) _NOEXCEPT
@@ -3761,7 +3779,7 @@ operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3761
3779
  }
3762
3780
 
3763
3781
  template<class _CharT, class _Traits, class _Allocator>
3764
- _LIBCPP_INLINE_VISIBILITY inline
3782
+ inline _LIBCPP_INLINE_VISIBILITY
3765
3783
  bool
3766
3784
  operator< (const _CharT* __lhs,
3767
3785
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3772,7 +3790,7 @@ operator< (const _CharT* __lhs,
3772
3790
  // operator>
3773
3791
 
3774
3792
  template<class _CharT, class _Traits, class _Allocator>
3775
- _LIBCPP_INLINE_VISIBILITY inline
3793
+ inline _LIBCPP_INLINE_VISIBILITY
3776
3794
  bool
3777
3795
  operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3778
3796
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3781,7 +3799,7 @@ operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3781
3799
  }
3782
3800
 
3783
3801
  template<class _CharT, class _Traits, class _Allocator>
3784
- _LIBCPP_INLINE_VISIBILITY inline
3802
+ inline _LIBCPP_INLINE_VISIBILITY
3785
3803
  bool
3786
3804
  operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3787
3805
  const _CharT* __rhs) _NOEXCEPT
@@ -3790,7 +3808,7 @@ operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3790
3808
  }
3791
3809
 
3792
3810
  template<class _CharT, class _Traits, class _Allocator>
3793
- _LIBCPP_INLINE_VISIBILITY inline
3811
+ inline _LIBCPP_INLINE_VISIBILITY
3794
3812
  bool
3795
3813
  operator> (const _CharT* __lhs,
3796
3814
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3801,7 +3819,7 @@ operator> (const _CharT* __lhs,
3801
3819
  // operator<=
3802
3820
 
3803
3821
  template<class _CharT, class _Traits, class _Allocator>
3804
- _LIBCPP_INLINE_VISIBILITY inline
3822
+ inline _LIBCPP_INLINE_VISIBILITY
3805
3823
  bool
3806
3824
  operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3807
3825
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3810,7 +3828,7 @@ operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3810
3828
  }
3811
3829
 
3812
3830
  template<class _CharT, class _Traits, class _Allocator>
3813
- _LIBCPP_INLINE_VISIBILITY inline
3831
+ inline _LIBCPP_INLINE_VISIBILITY
3814
3832
  bool
3815
3833
  operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3816
3834
  const _CharT* __rhs) _NOEXCEPT
@@ -3819,7 +3837,7 @@ operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3819
3837
  }
3820
3838
 
3821
3839
  template<class _CharT, class _Traits, class _Allocator>
3822
- _LIBCPP_INLINE_VISIBILITY inline
3840
+ inline _LIBCPP_INLINE_VISIBILITY
3823
3841
  bool
3824
3842
  operator<=(const _CharT* __lhs,
3825
3843
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3830,7 +3848,7 @@ operator<=(const _CharT* __lhs,
3830
3848
  // operator>=
3831
3849
 
3832
3850
  template<class _CharT, class _Traits, class _Allocator>
3833
- _LIBCPP_INLINE_VISIBILITY inline
3851
+ inline _LIBCPP_INLINE_VISIBILITY
3834
3852
  bool
3835
3853
  operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3836
3854
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3839,7 +3857,7 @@ operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3839
3857
  }
3840
3858
 
3841
3859
  template<class _CharT, class _Traits, class _Allocator>
3842
- _LIBCPP_INLINE_VISIBILITY inline
3860
+ inline _LIBCPP_INLINE_VISIBILITY
3843
3861
  bool
3844
3862
  operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3845
3863
  const _CharT* __rhs) _NOEXCEPT
@@ -3848,7 +3866,7 @@ operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3848
3866
  }
3849
3867
 
3850
3868
  template<class _CharT, class _Traits, class _Allocator>
3851
- _LIBCPP_INLINE_VISIBILITY inline
3869
+ inline _LIBCPP_INLINE_VISIBILITY
3852
3870
  bool
3853
3871
  operator>=(const _CharT* __lhs,
3854
3872
  const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
@@ -3920,7 +3938,7 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3920
3938
  #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3921
3939
 
3922
3940
  template<class _CharT, class _Traits, class _Allocator>
3923
- _LIBCPP_INLINE_VISIBILITY inline
3941
+ inline _LIBCPP_INLINE_VISIBILITY
3924
3942
  basic_string<_CharT, _Traits, _Allocator>
3925
3943
  operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3926
3944
  {
@@ -3928,7 +3946,7 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<
3928
3946
  }
3929
3947
 
3930
3948
  template<class _CharT, class _Traits, class _Allocator>
3931
- _LIBCPP_INLINE_VISIBILITY inline
3949
+ inline _LIBCPP_INLINE_VISIBILITY
3932
3950
  basic_string<_CharT, _Traits, _Allocator>
3933
3951
  operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3934
3952
  {
@@ -3936,7 +3954,7 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_
3936
3954
  }
3937
3955
 
3938
3956
  template<class _CharT, class _Traits, class _Allocator>
3939
- _LIBCPP_INLINE_VISIBILITY inline
3957
+ inline _LIBCPP_INLINE_VISIBILITY
3940
3958
  basic_string<_CharT, _Traits, _Allocator>
3941
3959
  operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3942
3960
  {
@@ -3944,7 +3962,7 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT
3944
3962
  }
3945
3963
 
3946
3964
  template<class _CharT, class _Traits, class _Allocator>
3947
- _LIBCPP_INLINE_VISIBILITY inline
3965
+ inline _LIBCPP_INLINE_VISIBILITY
3948
3966
  basic_string<_CharT, _Traits, _Allocator>
3949
3967
  operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3950
3968
  {
@@ -3952,7 +3970,7 @@ operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3952
3970
  }
3953
3971
 
3954
3972
  template<class _CharT, class _Traits, class _Allocator>
3955
- _LIBCPP_INLINE_VISIBILITY inline
3973
+ inline _LIBCPP_INLINE_VISIBILITY
3956
3974
  basic_string<_CharT, _Traits, _Allocator>
3957
3975
  operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3958
3976
  {
@@ -3961,7 +3979,7 @@ operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3961
3979
  }
3962
3980
 
3963
3981
  template<class _CharT, class _Traits, class _Allocator>
3964
- _LIBCPP_INLINE_VISIBILITY inline
3982
+ inline _LIBCPP_INLINE_VISIBILITY
3965
3983
  basic_string<_CharT, _Traits, _Allocator>
3966
3984
  operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3967
3985
  {
@@ -3969,7 +3987,7 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs
3969
3987
  }
3970
3988
 
3971
3989
  template<class _CharT, class _Traits, class _Allocator>
3972
- _LIBCPP_INLINE_VISIBILITY inline
3990
+ inline _LIBCPP_INLINE_VISIBILITY
3973
3991
  basic_string<_CharT, _Traits, _Allocator>
3974
3992
  operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3975
3993
  {
@@ -3982,7 +4000,7 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3982
4000
  // swap
3983
4001
 
3984
4002
  template<class _CharT, class _Traits, class _Allocator>
3985
- _LIBCPP_INLINE_VISIBILITY inline
4003
+ inline _LIBCPP_INLINE_VISIBILITY
3986
4004
  void
3987
4005
  swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
3988
4006
  basic_string<_CharT, _Traits, _Allocator>& __rhs)
@@ -3998,45 +4016,45 @@ typedef basic_string<char32_t> u32string;
3998
4016
 
3999
4017
  #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
4000
4018
 
4001
- int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4002
- long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4003
- unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4004
- long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4005
- unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
4006
-
4007
- float stof (const string& __str, size_t* __idx = 0);
4008
- double stod (const string& __str, size_t* __idx = 0);
4009
- long double stold(const string& __str, size_t* __idx = 0);
4010
-
4011
- string to_string(int __val);
4012
- string to_string(unsigned __val);
4013
- string to_string(long __val);
4014
- string to_string(unsigned long __val);
4015
- string to_string(long long __val);
4016
- string to_string(unsigned long long __val);
4017
- string to_string(float __val);
4018
- string to_string(double __val);
4019
- string to_string(long double __val);
4020
-
4021
- int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4022
- long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4023
- unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4024
- long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4025
- unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
4026
-
4027
- float stof (const wstring& __str, size_t* __idx = 0);
4028
- double stod (const wstring& __str, size_t* __idx = 0);
4029
- long double stold(const wstring& __str, size_t* __idx = 0);
4030
-
4031
- wstring to_wstring(int __val);
4032
- wstring to_wstring(unsigned __val);
4033
- wstring to_wstring(long __val);
4034
- wstring to_wstring(unsigned long __val);
4035
- wstring to_wstring(long long __val);
4036
- wstring to_wstring(unsigned long long __val);
4037
- wstring to_wstring(float __val);
4038
- wstring to_wstring(double __val);
4039
- wstring to_wstring(long double __val);
4019
+ _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4020
+ _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4021
+ _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4022
+ _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4023
+ _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
4024
+
4025
+ _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4026
+ _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4027
+ _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
4028
+
4029
+ _LIBCPP_FUNC_VIS string to_string(int __val);
4030
+ _LIBCPP_FUNC_VIS string to_string(unsigned __val);
4031
+ _LIBCPP_FUNC_VIS string to_string(long __val);
4032
+ _LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4033
+ _LIBCPP_FUNC_VIS string to_string(long long __val);
4034
+ _LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4035
+ _LIBCPP_FUNC_VIS string to_string(float __val);
4036
+ _LIBCPP_FUNC_VIS string to_string(double __val);
4037
+ _LIBCPP_FUNC_VIS string to_string(long double __val);
4038
+
4039
+ _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4040
+ _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4041
+ _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4042
+ _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4043
+ _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
4044
+
4045
+ _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4046
+ _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4047
+ _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
4048
+
4049
+ _LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4050
+ _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4051
+ _LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4052
+ _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4053
+ _LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4054
+ _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4055
+ _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4056
+ _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4057
+ _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
4040
4058
 
4041
4059
  template<class _CharT, class _Traits, class _Allocator>
4042
4060
  const typename basic_string<_CharT, _Traits, _Allocator>::size_type
@@ -4050,7 +4068,7 @@ size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
4050
4068
  }
4051
4069
 
4052
4070
  template<class _CharT, class _Traits, class _Allocator>
4053
- struct _LIBCPP_TYPE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
4071
+ struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
4054
4072
  : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4055
4073
  {
4056
4074
  size_t
@@ -4102,12 +4120,45 @@ getline(basic_istream<_CharT, _Traits>&& __is,
4102
4120
 
4103
4121
  #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4104
4122
 
4123
+ #if _LIBCPP_DEBUG_LEVEL >= 2
4124
+
4125
+ template<class _CharT, class _Traits, class _Allocator>
4126
+ bool
4127
+ basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4128
+ {
4129
+ return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4130
+ _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4131
+ }
4132
+
4133
+ template<class _CharT, class _Traits, class _Allocator>
4134
+ bool
4135
+ basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4136
+ {
4137
+ return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4138
+ _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4139
+ }
4140
+
4141
+ template<class _CharT, class _Traits, class _Allocator>
4142
+ bool
4143
+ basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4144
+ {
4145
+ const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4146
+ return this->data() <= __p && __p <= this->data() + this->size();
4147
+ }
4148
+
4149
+ template<class _CharT, class _Traits, class _Allocator>
4150
+ bool
4151
+ basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4152
+ {
4153
+ const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4154
+ return this->data() <= __p && __p < this->data() + this->size();
4155
+ }
4156
+
4157
+ #endif // _LIBCPP_DEBUG_LEVEL >= 2
4158
+
4105
4159
  #if _LIBCPP_STD_VER > 11
4106
4160
  // Literal suffixes for basic_string [basic.string.literals]
4107
- // inline // Deviation from N3690.
4108
- // We believe the inline to be a defect and have submitted an LWG issue.
4109
- // An LWG issue number has not yet been assigned.
4110
- namespace literals
4161
+ inline namespace literals
4111
4162
  {
4112
4163
  inline namespace string_literals
4113
4164
  {
@@ -4138,12 +4189,9 @@ namespace literals
4138
4189
  }
4139
4190
  #endif
4140
4191
 
4141
- _LIBCPP_EXTERN_TEMPLATE(class basic_string<char>)
4142
- _LIBCPP_EXTERN_TEMPLATE(class basic_string<wchar_t>)
4143
-
4144
- extern template
4145
- string
4146
- operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
4192
+ _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4193
+ _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
4194
+ _LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
4147
4195
 
4148
4196
  _LIBCPP_END_NAMESPACE_STD
4149
4197