CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
zero_allocator.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_zero_allocator_h
2 #define FWCore_Utilities_zero_allocator_h
3 /*
4  Copyright (c) 2005-2020 Intel Corporation
5 
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 */
18 
19 #include "oneapi/tbb/tbb_allocator.h"
20 #include <cstring>
21 
22 /* Copied from tbb_2020 branch's tbb/tbb_allocator linked here
23  https://github.com/oneapi-src/oneTBB/blob/tbb_2020/include/tbb/tbb_allocator.h
24  and renamed to edm namespace because it was removed from oneapi_2021 branch's
25  tbb/tbb_allocator.
26  */
27 
28 namespace edm {
29  template <typename T, template <typename X> class Allocator = oneapi::tbb::tbb_allocator>
30  class zero_allocator : public Allocator<T> {
31  public:
32  using value_type = T;
33  using base_allocator_type = Allocator<T>;
34  template <typename U>
35  struct rebind {
37  };
38 
41  template <typename U>
42  zero_allocator(const zero_allocator<U> &a) throw() : base_allocator_type(Allocator<U>(a)) {}
43 
44  T *allocate(const std::size_t n, const void *hint = nullptr) {
45  //T* ptr = base_allocator_type::allocate( n, hint );
46  T *ptr = base_allocator_type::allocate(n);
47  std::memset(static_cast<void *>(ptr), 0, n * sizeof(value_type));
48  return ptr;
49  }
50  };
51 
52  template <typename T1, template <typename X1> class B1, typename T2, template <typename X2> class B2>
54  return static_cast<B1<T1> >(a) == static_cast<B2<T2> >(b);
55  }
56  template <typename T1, template <typename X1> class B1, typename T2, template <typename X2> class B2>
58  return static_cast<B1<T1> >(a) != static_cast<B2<T2> >(b);
59  }
60 } // namespace edm
61 #endif
constexpr bool operator==(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
zero_allocator(const zero_allocator< U > &a)
Allocator< T > base_allocator_type
constexpr bool operator!=(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
double b
Definition: hdecay.h:118
zero_allocator< U, Allocator > other
zero_allocator(const zero_allocator &a)
double a
Definition: hdecay.h:119
T * allocate(const std::size_t n, const void *hint=nullptr)
long double T