Advertisement
matthewsammut

Allocator Test Code

Feb 15th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <vector>
  2. #include "stdio.h"
  3. #include "stopwatch.h"
  4. #include "stack_allocator.h"
  5.  
  6. using namespace std;
  7.  
  8. static constexpr size_t num = 1024;
  9.  
  10. class Custom {
  11. public:
  12.     size_t val;
  13.  
  14.     Custom() : val(0) {
  15.     }
  16.  
  17.     Custom(size_t value) : val(value) {
  18.     }
  19.  
  20.     ~Custom() {
  21.         val = 0;
  22.     }
  23. };
  24.  
  25. int main() {
  26.     init_stack_vector(Custom, v, num);
  27.     v.emplace_back(Custom(3));
  28.     v.emplace_back(Custom(5));
  29.     v.emplace_back(Custom(7));
  30.     v.emplace_back(Custom(9));
  31.  
  32.     for (size_t i = 0; i < v.size(); i++)
  33.         printf("Before: %zu\n", v[i].val);
  34.  
  35.     v.erase(v.begin() + 1);
  36.  
  37.     for (size_t i = 0; i < v.size(); i++)
  38.         printf("After: %zu\n", v[i].val);
  39.  
  40.     v.emplace_back(Custom(15));
  41.     v.insert(v.begin() + 1, Custom(11));
  42.  
  43.     for (size_t i = 0; i < v.size(); i++)
  44.         printf("After after: %zu\n", v[i].val);
  45.    
  46.     system("pause");
  47.     return 0;
  48. }
  49.  
  50. /* Output:
  51. Before: 3
  52. Before: 5
  53. Before: 7
  54. Before: 9
  55. After: 3
  56. After: 7
  57. After: 9
  58. After after: 3
  59. After after: 11
  60. After after: 7
  61. After after: 9
  62. After after: 15
  63. Press any key to continue . . .*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement