1- /*
2- MIT License
3-
4- Copyright (c) 2021 Eyal Z
5-
6- Permission is hereby granted, free of charge, to any person obtaining a copy
7- */
81#ifndef ZPP_BITS_H
92#define ZPP_BITS_H
103
@@ -2687,8 +2680,12 @@ class in
26872680 {
26882681 using type = std::remove_cvref_t <decltype (container)>;
26892682 using value_type = typename type::value_type;
2690- constexpr auto is_const = std::is_const_v<
2691- std::remove_reference_t <decltype (container[0 ])>>;
2683+ constexpr auto is_const =
2684+ std::is_const_v<std::remove_reference_t <value_type>> ||
2685+ requires {
2686+ requires std::is_const_v<
2687+ std::remove_reference_t <decltype (container[0 ])>>;
2688+ };
26922689
26932690 if constexpr (!std::is_void_v<SizeType> &&
26942691 (requires (type container) { container.resize (1 ); } ||
@@ -2827,9 +2824,7 @@ class in
28272824 if constexpr (requires { typename type::mapped_type; }) {
28282825 using value_type = std::pair<typename type::key_type,
28292826 typename type::mapped_type>;
2830- std::aligned_storage_t <sizeof (value_type),
2831- alignof (value_type)>
2832- storage;
2827+ alignas (value_type) std::byte storage[sizeof (value_type)];
28332828
28342829 auto object = access::placement_new<value_type>(
28352830 std::addressof (storage));
@@ -2843,9 +2838,7 @@ class in
28432838 } else {
28442839 using value_type = typename type::value_type;
28452840
2846- std::aligned_storage_t <sizeof (value_type),
2847- alignof (value_type)>
2848- storage;
2841+ alignas (value_type) std::byte storage[sizeof (value_type)];
28492842
28502843 auto object = access::placement_new<value_type>(
28512844 std::addressof (storage));
@@ -2903,8 +2896,7 @@ class in
29032896 return result;
29042897 }
29052898 } else {
2906- std::aligned_storage_t <sizeof (value_type), alignof (value_type)>
2907- storage;
2899+ alignas (value_type) std::byte storage[sizeof (value_type)];
29082900
29092901 auto object =
29102902 access::placement_new<value_type>(std::addressof (storage));
@@ -2947,9 +2939,7 @@ class in
29472939 }
29482940 return serialize_one (*std::get_if<element_type>(&variant));
29492941 } else {
2950- std::aligned_storage_t <sizeof (element_type),
2951- alignof (element_type)>
2952- storage;
2942+ alignas (element_type) std::byte storage[sizeof (element_type)];
29532943
29542944 auto object = access::placement_new<element_type>(
29552945 std::addressof (storage));
@@ -2996,8 +2986,7 @@ class in
29962986 return self.serialize_one (
29972987 *std::get_if<Types>(&variant));
29982988 } else {
2999- std::aligned_storage_t <sizeof (Types), alignof (Types)>
3000- storage;
2989+ alignas (Types) std::byte storage[sizeof (Types)];
30012990
30022991 auto object = access::placement_new<Types>(
30032992 std::addressof (storage));
@@ -3008,6 +2997,7 @@ class in
30082997 return result;
30092998 }
30102999 variant = std::move (*object);
3000+ return errc{};
30113001 }
30123002 }...};
30133003
@@ -3307,7 +3297,7 @@ struct known_dynamic_id_variant
33073297 ZPP_BITS_INLINE constexpr static auto serialize (auto & serializer,
33083298 auto & self)
33093299 {
3310- return serializer.template serialize_one (self.variant , self.id );
3300+ return serializer.serialize_one (self.variant , self.id );
33113301 }
33123302
33133303 Variant & variant;
@@ -3448,7 +3438,8 @@ struct [[nodiscard]] value_or_errc
34483438 }
34493439
34503440 constexpr explicit value_or_errc (error_type error) :
3451- m_error (std::forward<decltype (error)>(error))
3441+ m_error (std::forward<decltype (error)>(error)),
3442+ m_failure (true )
34523443 {
34533444 }
34543445
@@ -5029,9 +5020,7 @@ struct pb
50295020 serialize use ();
50305021 };
50315022
5032- std::aligned_storage_t <sizeof (value_type),
5033- alignof (value_type)>
5034- storage;
5023+ alignas (value_type) std::byte storage[sizeof (value_type)];
50355024
50365025 auto object =
50375026 access::placement_new<value_type>(std::addressof (storage));
@@ -5111,9 +5100,7 @@ struct pb
51115100 return errc{};
51125101 }
51135102 } else {
5114- std::aligned_storage_t <sizeof (value_type),
5115- alignof (value_type)>
5116- storage;
5103+ alignas (value_type) std::byte storage[sizeof (value_type)];
51175104
51185105 auto object = access::placement_new<value_type>(
51195106 std::addressof (storage));
@@ -5382,47 +5369,47 @@ constexpr auto sha256()
53825369 };
53835370 auto align = [](auto v, auto a) { return (v + (a - 1 )) / a * a; };
53845371
5385- auto h0 = big_endian{0x6a09e667u };
5386- auto h1 = big_endian{0xbb67ae85u };
5387- auto h2 = big_endian{0x3c6ef372u };
5388- auto h3 = big_endian{0xa54ff53au };
5389- auto h4 = big_endian{0x510e527fu };
5390- auto h5 = big_endian{0x9b05688cu };
5391- auto h6 = big_endian{0x1f83d9abu };
5392- auto h7 = big_endian{0x5be0cd19u };
5393-
5394- std::array k{big_endian{0x428a2f98u }, big_endian{0x71374491u },
5395- big_endian{0xb5c0fbcfu }, big_endian{0xe9b5dba5u },
5396- big_endian{0x3956c25bu }, big_endian{0x59f111f1u },
5397- big_endian{0x923f82a4u }, big_endian{0xab1c5ed5u },
5398- big_endian{0xd807aa98u }, big_endian{0x12835b01u },
5399- big_endian{0x243185beu }, big_endian{0x550c7dc3u },
5400- big_endian{0x72be5d74u }, big_endian{0x80deb1feu },
5401- big_endian{0x9bdc06a7u }, big_endian{0xc19bf174u },
5402- big_endian{0xe49b69c1u }, big_endian{0xefbe4786u },
5403- big_endian{0x0fc19dc6u }, big_endian{0x240ca1ccu },
5404- big_endian{0x2de92c6fu }, big_endian{0x4a7484aau },
5405- big_endian{0x5cb0a9dcu }, big_endian{0x76f988dau },
5406- big_endian{0x983e5152u }, big_endian{0xa831c66du },
5407- big_endian{0xb00327c8u }, big_endian{0xbf597fc7u },
5408- big_endian{0xc6e00bf3u }, big_endian{0xd5a79147u },
5409- big_endian{0x06ca6351u }, big_endian{0x14292967u },
5410- big_endian{0x27b70a85u }, big_endian{0x2e1b2138u },
5411- big_endian{0x4d2c6dfcu }, big_endian{0x53380d13u },
5412- big_endian{0x650a7354u }, big_endian{0x766a0abbu },
5413- big_endian{0x81c2c92eu }, big_endian{0x92722c85u },
5414- big_endian{0xa2bfe8a1u }, big_endian{0xa81a664bu },
5415- big_endian{0xc24b8b70u }, big_endian{0xc76c51a3u },
5416- big_endian{0xd192e819u }, big_endian{0xd6990624u },
5417- big_endian{0xf40e3585u }, big_endian{0x106aa070u },
5418- big_endian{0x19a4c116u }, big_endian{0x1e376c08u },
5419- big_endian{0x2748774cu }, big_endian{0x34b0bcb5u },
5420- big_endian{0x391c0cb3u }, big_endian{0x4ed8aa4au },
5421- big_endian{0x5b9cca4fu }, big_endian{0x682e6ff3u },
5422- big_endian{0x748f82eeu }, big_endian{0x78a5636fu },
5423- big_endian{0x84c87814u }, big_endian{0x8cc70208u },
5424- big_endian{0x90befffau }, big_endian{0xa4506cebu },
5425- big_endian{0xbef9a3f7u }, big_endian{0xc67178f2u }};
5372+ auto h0 = big_endian{std:: uint32_t { 0x6a09e667u } };
5373+ auto h1 = big_endian{std:: uint32_t { 0xbb67ae85u } };
5374+ auto h2 = big_endian{std:: uint32_t { 0x3c6ef372u } };
5375+ auto h3 = big_endian{std:: uint32_t { 0xa54ff53au } };
5376+ auto h4 = big_endian{std:: uint32_t { 0x510e527fu } };
5377+ auto h5 = big_endian{std:: uint32_t { 0x9b05688cu } };
5378+ auto h6 = big_endian{std:: uint32_t { 0x1f83d9abu } };
5379+ auto h7 = big_endian{std:: uint32_t { 0x5be0cd19u } };
5380+
5381+ std::array k{big_endian{std:: uint32_t { 0x428a2f98u }} , big_endian{std:: uint32_t { 0x71374491u } },
5382+ big_endian{std:: uint32_t { 0xb5c0fbcfu }} , big_endian{std:: uint32_t { 0xe9b5dba5u } },
5383+ big_endian{std:: uint32_t { 0x3956c25bu }} , big_endian{std:: uint32_t { 0x59f111f1u } },
5384+ big_endian{std:: uint32_t { 0x923f82a4u }} , big_endian{std:: uint32_t { 0xab1c5ed5u } },
5385+ big_endian{std:: uint32_t { 0xd807aa98u }} , big_endian{std:: uint32_t { 0x12835b01u } },
5386+ big_endian{std:: uint32_t { 0x243185beu }} , big_endian{std:: uint32_t { 0x550c7dc3u } },
5387+ big_endian{std:: uint32_t { 0x72be5d74u }} , big_endian{std:: uint32_t { 0x80deb1feu } },
5388+ big_endian{std:: uint32_t { 0x9bdc06a7u }} , big_endian{std:: uint32_t { 0xc19bf174u } },
5389+ big_endian{std:: uint32_t { 0xe49b69c1u }} , big_endian{std:: uint32_t { 0xefbe4786u } },
5390+ big_endian{std:: uint32_t { 0x0fc19dc6u }} , big_endian{std:: uint32_t { 0x240ca1ccu } },
5391+ big_endian{std:: uint32_t { 0x2de92c6fu }} , big_endian{std:: uint32_t { 0x4a7484aau } },
5392+ big_endian{std:: uint32_t { 0x5cb0a9dcu }} , big_endian{std:: uint32_t { 0x76f988dau } },
5393+ big_endian{std:: uint32_t { 0x983e5152u }} , big_endian{std:: uint32_t { 0xa831c66du } },
5394+ big_endian{std:: uint32_t { 0xb00327c8u }} , big_endian{std:: uint32_t { 0xbf597fc7u } },
5395+ big_endian{std:: uint32_t { 0xc6e00bf3u }} , big_endian{std:: uint32_t { 0xd5a79147u } },
5396+ big_endian{std:: uint32_t { 0x06ca6351u }} , big_endian{std:: uint32_t { 0x14292967u } },
5397+ big_endian{std:: uint32_t { 0x27b70a85u }} , big_endian{std:: uint32_t { 0x2e1b2138u } },
5398+ big_endian{std:: uint32_t { 0x4d2c6dfcu }} , big_endian{std:: uint32_t { 0x53380d13u } },
5399+ big_endian{std:: uint32_t { 0x650a7354u }} , big_endian{std:: uint32_t { 0x766a0abbu } },
5400+ big_endian{std:: uint32_t { 0x81c2c92eu }} , big_endian{std:: uint32_t { 0x92722c85u } },
5401+ big_endian{std:: uint32_t { 0xa2bfe8a1u }} , big_endian{std:: uint32_t { 0xa81a664bu } },
5402+ big_endian{std:: uint32_t { 0xc24b8b70u }} , big_endian{std:: uint32_t { 0xc76c51a3u } },
5403+ big_endian{std:: uint32_t { 0xd192e819u }} , big_endian{std:: uint32_t { 0xd6990624u } },
5404+ big_endian{std:: uint32_t { 0xf40e3585u }} , big_endian{std:: uint32_t { 0x106aa070u } },
5405+ big_endian{std:: uint32_t { 0x19a4c116u }} , big_endian{std:: uint32_t { 0x1e376c08u } },
5406+ big_endian{std:: uint32_t { 0x2748774cu }} , big_endian{std:: uint32_t { 0x34b0bcb5u } },
5407+ big_endian{std:: uint32_t { 0x391c0cb3u }} , big_endian{std:: uint32_t { 0x4ed8aa4au } },
5408+ big_endian{std:: uint32_t { 0x5b9cca4fu }} , big_endian{std:: uint32_t { 0x682e6ff3u } },
5409+ big_endian{std:: uint32_t { 0x748f82eeu }} , big_endian{std:: uint32_t { 0x78a5636fu } },
5410+ big_endian{std:: uint32_t { 0x84c87814u }} , big_endian{std:: uint32_t { 0x8cc70208u } },
5411+ big_endian{std:: uint32_t { 0x90befffau }} , big_endian{std:: uint32_t { 0xa4506cebu } },
5412+ big_endian{std:: uint32_t { 0xbef9a3f7u }} , big_endian{std:: uint32_t { 0xc67178f2u } }};
54265413
54275414 constexpr auto original_message = to_bytes<Object>();
54285415 constexpr auto chunk_size = 512 / CHAR_BIT;
0 commit comments