2626#include < sfl/detail/cpp.hpp>
2727
2828#include < algorithm> // copy, fill, move, move_backward
29- #include < cstddef> // size_t, nullptrt_t , ptrdiff_t
29+ #include < cstddef> // size_t, nullptr_t , ptrdiff_t
3030#include < iterator> // random_access_iterator_tag
3131#include < type_traits> // add_lvalue_reference, is_constant_evaluated, remove_cv
3232
@@ -36,14 +36,14 @@ namespace sfl
3636namespace dtl
3737{
3838
39- #if SFL_CPP_VERSION >= SFL_CPP_20
40-
4139// /////////////////////////////////////////////////////////////////////////////
4240// /////////////////////////////////////////////////////////////////////////////
4341// STATIC STORAGE BUCKET
4442// /////////////////////////////////////////////////////////////////////////////
4543// /////////////////////////////////////////////////////////////////////////////
4644
45+ #if SFL_CPP_VERSION >= SFL_CPP_20
46+
4747template <typename T>
4848union static_storage_bucket
4949{
@@ -58,12 +58,16 @@ union static_storage_bucket
5858 {}
5959};
6060
61+ #endif // SFL_CPP_VERSION >= SFL_CPP_20
62+
6163// /////////////////////////////////////////////////////////////////////////////
6264// /////////////////////////////////////////////////////////////////////////////
6365// STATIC STORAGE POINTER
6466// /////////////////////////////////////////////////////////////////////////////
6567// /////////////////////////////////////////////////////////////////////////////
6668
69+ #if SFL_CPP_VERSION >= SFL_CPP_20
70+
6771template <typename T>
6872class static_storage_pointer
6973{
@@ -84,9 +88,7 @@ class static_storage_pointer
8488
8589 using iterator_category = std::random_access_iterator_tag;
8690
87- #if SFL_CPP_VERSION >= SFL_CPP_20
8891 using iterator_concept = std::contiguous_iterator_tag;
89- #endif
9092
9193private:
9294
@@ -268,18 +270,22 @@ class static_storage_pointer
268270 }
269271};
270272
273+ #endif // SFL_CPP_VERSION >= SFL_CPP_20
274+
271275// /////////////////////////////////////////////////////////////////////////////
272276// /////////////////////////////////////////////////////////////////////////////
273277// STATIC STORAGE
274278// /////////////////////////////////////////////////////////////////////////////
275279// /////////////////////////////////////////////////////////////////////////////
276280
281+ #if SFL_CPP_VERSION >= SFL_CPP_20
282+
277283template <typename T, std::size_t N>
278284class static_storage
279285{
280286private:
281287
282- sfl::dtl::static_storage_bucket<T> buckets_ [N];
288+ sfl::dtl::static_storage_bucket<T> storage_ [N];
283289
284290public:
285291
@@ -301,23 +307,67 @@ class static_storage
301307 SFL_CONSTEXPR_20
302308 pointer data () noexcept
303309 {
304- return pointer (buckets_ );
310+ return pointer (storage_ );
305311 }
306312
307313 SFL_NODISCARD
308314 SFL_CONSTEXPR_20
309315 pointer data () const noexcept
310316 {
311- return pointer (buckets_ );
317+ return pointer (storage_ );
312318 }
313319};
314320
321+ #else // before C++20
322+
323+ template <typename T, std::size_t N>
324+ union static_storage
325+ {
326+ private:
327+
328+ T storage_[N];
329+
330+ public:
331+
332+ using pointer = T*;
333+
334+ using const_pointer = const T*;
335+
336+ public:
337+
338+ SFL_CONSTEXPR_20
339+ static_storage () noexcept
340+ {}
341+
342+ SFL_CONSTEXPR_20
343+ ~static_storage ()
344+ {}
345+
346+ SFL_NODISCARD
347+ SFL_CONSTEXPR_20
348+ pointer data () noexcept
349+ {
350+ return pointer (storage_);
351+ }
352+
353+ SFL_NODISCARD
354+ SFL_CONSTEXPR_20
355+ pointer data () const noexcept
356+ {
357+ return pointer (storage_);
358+ }
359+ };
360+
361+ #endif // before C++20
362+
315363// /////////////////////////////////////////////////////////////////////////////
316364// /////////////////////////////////////////////////////////////////////////////
317365// ALGORITHMS
318366// /////////////////////////////////////////////////////////////////////////////
319367// /////////////////////////////////////////////////////////////////////////////
320368
369+ #if SFL_CPP_VERSION >= SFL_CPP_20
370+
321371template <typename T>
322372SFL_CONSTEXPR_20
323373sfl::dtl::static_storage_pointer<T> copy
@@ -536,53 +586,7 @@ sfl::dtl::static_storage_pointer<T> move_backward
536586 }
537587}
538588
539- #else // before C++20
540-
541- // /////////////////////////////////////////////////////////////////////////////
542- // /////////////////////////////////////////////////////////////////////////////
543- // STATIC STORAGE
544- // /////////////////////////////////////////////////////////////////////////////
545- // /////////////////////////////////////////////////////////////////////////////
546-
547- template <typename T, std::size_t N>
548- union static_storage
549- {
550- private:
551-
552- T storage_[N];
553-
554- public:
555-
556- using pointer = T*;
557-
558- using const_pointer = const T*;
559-
560- public:
561-
562- SFL_CONSTEXPR_20
563- static_storage () noexcept
564- {}
565-
566- SFL_CONSTEXPR_20
567- ~static_storage ()
568- {}
569-
570- SFL_NODISCARD
571- SFL_CONSTEXPR_20
572- pointer data () noexcept
573- {
574- return pointer (storage_);
575- }
576-
577- SFL_NODISCARD
578- SFL_CONSTEXPR_20
579- pointer data () const noexcept
580- {
581- return pointer (storage_);
582- }
583- };
584-
585- #endif // before C++20
589+ #endif // SFL_CPP_VERSION >= SFL_CPP_20
586590
587591} // namespace dtl
588592
0 commit comments