bit::memory
AllocatorStorage.hpp
1 /*****************************************************************************
2  * \file
3  * \brief This header defines the concept of an 'AllocatorStorage', which is
4  * used to contain allocator types within composites.
5  *****************************************************************************/
6 
7 /*
8  The MIT License (MIT)
9 
10  Copyright (c) 2018 Matthew Rodusek
11 
12  Permission is hereby granted, free of charge, to any person obtaining a copy
13  of this software and associated documentation files (the "Software"), to deal
14  in the Software without restriction, including without limitation the rights
15  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the Software is
17  furnished to do so, subject to the following conditions:
18 
19  The above copyright notice and this permission notice shall be included in
20  all copies or substantial portions of the Software.
21 
22  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28  SOFTWARE.
29 */
30 #ifndef BIT_MEMORY_CONCEPTS_ALLOCATOR_STORAGE_HPP
31 #define BIT_MEMORY_CONCEPTS_ALLOCATOR_STORAGE_HPP
32 
33 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
34 # pragma once
35 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
36 
37 #include "detail/void_t.hpp" // detail::void_t
38 
39 #include "Allocator.hpp" // is_allocator
40 
41 #include <type_traits> // std::declval, std::true_type
42 
43 namespace bit {
44  namespace memory {
45 
93 #if __cplusplus >= 202000L
94  // TODO(bitwize) replace 202000L with the correct __cplusplus when certified
95 
96  template<typename T>
97  concept bool AllocatorStorage = requires( T& s, const T& cs )
98  {
99  { s.get_allocator() } -> typename T::allocator_type&;
100  { cs.get_allocator() } -> const typename T::allocator_type&;
101  } && std::is_nothrow_copy_constructible<T>::value &&
102  std::is_nothrow_move_constructible<T>::value &&
103  std::is_nothrow_copy_assignable<T>::value &&
104  std::is_nothrow_move_assignable<T>::value;
105 #endif
106 
107  namespace detail {
108 
109  template<typename T, typename = void>
110  struct is_allocator_storage_impl : std::false_type{};
111 
112  template<typename T>
113  struct is_allocator_storage_impl<T,
114  void_t<
115  decltype( std::declval<T&>().get_allocator() ),
116  decltype( std::declval<const T&>().get_allocator() )
117  >
118  > : std::integral_constant<bool,
119  is_allocator<typename T::allocator_type>::value &&
120  std::is_convertible<decltype( std::declval<T&>().get_allocator()),
121  typename T::allocator_type&>::value &&
122  std::is_convertible<decltype( std::declval<const T&>().get_allocator()),
123  const typename T::allocator_type&>::value &&
124  std::is_nothrow_copy_constructible<T>::value &&
125  std::is_nothrow_move_constructible<T>::value &&
126  std::is_nothrow_copy_assignable<T>::value &&
127  std::is_nothrow_move_assignable<T>::value>{};
128  } // namespace detail
129 
135  template<typename T>
136  struct is_allocator_storage : detail::is_allocator_storage_impl<T>{};
137 
142  template<typename T>
143  constexpr bool is_allocator_storage_v = is_allocator_storage<T>::value;
144 
145  } // namespace memory
146 } // namespace bit
147 
148 #endif /* BIT_MEMORY_CONCEPTS_ALLOCATOR_STORAGE_HPP */
Type trait to determine whether T is a AllocatorStorage.
STL namespace.