Allocator Builder
Policy Based C++ Template Allocator Library
 All Classes Functions Variables Enumerations Enumerator Groups Pages
memory_corruption_detector.hpp
1 //
3 // Copyright 2014 Felix Petriconi
4 //
5 // License: http://boost.org/LICENSE_1_0.txt, Boost License 1.0
6 //
7 // Authors: http://petriconi.net, Felix Petriconi
8 //
10 
11 #pragma once
12 
13 #include <cassert>
14 #include <cstdint>
15 #include <iostream>
16 
17 namespace alb {
18  inline namespace v_100 {
28  template <typename T, size_t Pattern>
30  {
31  static_assert(sizeof(char) < sizeof(T) && sizeof(T) <= sizeof(uint64_t),
32  "Memory check not for supported types");
33 
34  T pattern_;
35 
36  public:
37  using value_type = T;
38  static const size_t pattern = Pattern;
39 
41  : pattern_(Pattern)
42  {}
43 
45  {
46 #ifndef NDEBUG
47  if (pattern_ != Pattern)
48  {
49  std::cout << std::to_string(pattern_) << " is unequal to " << std::to_string(Pattern) << "!" << std::endl;
50  throw 42;
51  }
52 #endif
53  assert(pattern_ == Pattern);
54  }
55  };
56 
57  template <typename T, size_t Pattern>
59  }
60  using namespace v_100;
61 }