@@ -748,6 +748,41 @@ struct __can_be_converted_to_string_view
748
748
struct __uninitialized_size_tag {};
749
749
struct __init_with_sentinel_tag {};
750
750
751
+ #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
752
+ template <class _CharT , size_t __min_cap, size_t _Padding = sizeof (_CharT) - 1 >
753
+ struct __short_impl {
754
+ _CharT __data_[__min_cap];
755
+ unsigned char __padding_[_Padding];
756
+ unsigned char __size_ : 7 ;
757
+ unsigned char __is_long_ : 1 ;
758
+ };
759
+
760
+ template <class _CharT , size_t __min_cap>
761
+ struct __short_impl <_CharT, __min_cap, 0 > {
762
+ value_type __data_[__min_cap];
763
+ unsigned char __size_ : 7 ;
764
+ unsigned char __is_long_ : 1 ;
765
+ };
766
+ #else
767
+ template <class _CharT , size_t __min_cap, size_t _Padding = sizeof (_CharT) - 1 >
768
+ struct __short_impl {
769
+ struct _LIBCPP_PACKED {
770
+ unsigned char __is_long_ : 1 ;
771
+ unsigned char __size_ : 7 ;
772
+ };
773
+ char __padding_[_Padding];
774
+ _CharT __data_[__min_cap];
775
+ };
776
+ template <class _CharT , size_t __min_cap>
777
+ struct __short_impl <_CharT, __min_cap, 0 > {
778
+ struct _LIBCPP_PACKED {
779
+ unsigned char __is_long_ : 1 ;
780
+ unsigned char __size_ : 7 ;
781
+ };
782
+ _CharT __data_[__min_cap];
783
+ };
784
+ #endif
785
+
751
786
template <class _CharT , class _Traits , class _Allocator >
752
787
class basic_string {
753
788
private:
@@ -850,13 +885,6 @@ private:
850
885
851
886
enum { __min_cap = (sizeof (__long) - 1 ) / sizeof (value_type) > 2 ? (sizeof (__long) - 1 ) / sizeof (value_type) : 2 };
852
887
853
- struct __short {
854
- value_type __data_[__min_cap];
855
- unsigned char __padding_[sizeof (value_type) - 1 ];
856
- unsigned char __size_ : 7 ;
857
- unsigned char __is_long_ : 1 ;
858
- };
859
-
860
888
// The __endian_factor is required because the field we use to store the size
861
889
// has one fewer bit than it would if it were not a bitfield.
862
890
//
@@ -899,17 +927,9 @@ private:
899
927
900
928
enum { __min_cap = (sizeof (__long) - 1 ) / sizeof (value_type) > 2 ? (sizeof (__long) - 1 ) / sizeof (value_type) : 2 };
901
929
902
- struct __short {
903
- struct _LIBCPP_PACKED {
904
- unsigned char __is_long_ : 1 ;
905
- unsigned char __size_ : 7 ;
906
- };
907
- char __padding_[sizeof (value_type) - 1 ];
908
- value_type __data_[__min_cap];
909
- };
910
-
911
930
#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
912
931
932
+ using __short = __short_impl<value_type, __min_cap>;
913
933
static_assert (sizeof (__short) == (sizeof (value_type) * (__min_cap + 1 )), " __short has an unexpected size." );
914
934
915
935
union __rep {
0 commit comments