@@ -11,50 +11,25 @@ namespace packed_data_access
1111 double  value;
1212 };
1313
14- #ifdef  WIN32
15- 
14+ #ifdef  _WIN32
1615#pragma  pack(push,1)
1716 struct  PackedStruct 
1817 {
1918 char  c;
2019 double  value;
2120 };
2221#pragma  pack(pop)
23- 
24-  template  <typename  S, int  Size>
25-  struct  StructCreator 
26-  {
27-  StructCreator () : size(Size - 1 )
28-  {
29-  auto  len = size;
30-  while  (--len > 0 )
31-  {
32-  arr[len].c  = ' a' 20 );
33-  arr[len].value  = len / 1000.0 ;
34-  }
35-  }
36-  std::size_t  size;
37-  S arr[Size];
38-  };
39-  //  Visual Studio compilers are crashing due to 
40-  //  their bugs when using nested constexpr structs
41-  //  bu sebepten dolayi derleyici zamani yerine programin 
42-  //  calistirildiginda static olarak yaratiyorum
43-  static  StructCreator<AlignedStruct, 1024  * 1024 > aligned_list;
44-  static  StructCreator<PackedStruct, 1024  * 1024 > packed_list;
45- 
4622#else 
47-  // #include <cstdint>
48- 
4923 struct  PackedStruct  {
5024 char  c;
5125 double  value;
5226 } __attribute__((packed));
27+ #endif 
5328
5429 template  <typename  S, int  Size>
5530 struct  StructCreator 
5631 {
57-  constexpr   StructCreator () : arr(),  size(Size - 1 )
32+  StructCreator () : size(Size - 1 )
5833 {
5934 auto  len = size;
6035 while  (--len > 0 )
@@ -66,8 +41,8 @@ namespace packed_data_access
6641 std::size_t  size;
6742 S arr[Size];
6843 };
69- # endif 
70- 
44+   static  StructCreator<AlignedStruct,  1024  *  1024 > aligned_list; 
45+   static  StructCreator<PackedStruct,  1024  *  1024 > packed_list; 
7146}
7247
7348//  iki yapinin icerdigi veriler ayni olsa da uzunluklari farkli olacaktir
@@ -81,18 +56,12 @@ auto sum_lambda = [](int sum, const auto& s) {
8156
8257CREATE_ELEMENT_WITH_CODE (AlignedStructAccess) {
8358 using  namespace  packed_data_access ; 
84- #ifndef  WIN32
85-  constexpr  auto  aligned_list = StructCreator<AlignedStruct, 1024  * 10 >();
86- #endif 
8759 unsigned  int  sum = std::accumulate (&aligned_list.arr [0 ], &aligned_list.arr [aligned_list.size ], 0 , sum_lambda);
8860 std::cout << " sum: " " \n " 
8961}
9062
9163CREATE_ELEMENT_WITH_CODE (PackedStructAccess) {
9264 using  namespace  packed_data_access ; 
93- #ifndef  WIN32
94-  constexpr  auto  packed_list = StructCreator<PackedStruct, 1024  * 10 >();
95- #endif 
9665 unsigned  int  sum = std::accumulate (&packed_list.arr [0 ], &packed_list.arr [packed_list.size ], 0 , sum_lambda);
9766 std::cout << " sum: " " \n " 
9867}
0 commit comments