Allocator Builder
Policy Based C++ Template Allocator Library
 All Classes Functions Variables Enumerations Enumerator Groups Pages
affix_helper.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 #pragma once
11 
12 #include <stddef.h>
13 
14 namespace alb {
15  inline namespace v_100 {
16  namespace affix_helper {
17 
18  template <typename Affix, typename Enabled = void>
19  struct affix_creator;
20 
21  template <typename Affix>
22  struct affix_creator<Affix, typename std::enable_if<std::is_default_constructible<Affix>::value>::type>
23  {
24  template <typename Allocator>
25  static constexpr void doIt(void *p, Allocator&)
26  {
27  new (p) Affix{};
28  }
29  };
30 
31  template <typename Affix>
32  struct affix_creator<Affix, typename std::enable_if<!std::is_default_constructible<Affix>::value>::type>
33  {
34  template <typename Allocator>
35  static constexpr void doIt(void *p, Allocator& a)
36  {
37  new (p) Affix(a);
38  }
39  };
40 
41  template <typename Affix, typename Allocator>
42  void create_affix_in_place(void *p, Allocator& a)
43  {
45  }
46 
47 
54  struct no_affix {
55  using value_type = int;
56  static const int pattern = 0;
57  };
58 
59  /* simple optional store of a Sufix if the sufix_size > 0 */
60  template <typename Sufix, size_t s>
62  {
63  Sufix o_;
64  void store(Sufix* o) noexcept {
65  o_ = *o;
66  }
67  void unload(Sufix* o) noexcept {
68  new (o) Sufix(o_);
69  }
70  };
71 
72  template <typename Sufix>
73  struct optinal_sufix_store<Sufix, 0>
74  {
75  void store(Sufix*) {}
76  void unload(Sufix*) {}
77  };
78 
79  }
80  }
81  using namespace v_100;
82 
83 }