forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http2_reconstruct_object_impl.h
34 lines (26 loc) · 1.03 KB
/
http2_reconstruct_object_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_HTTP2_PLATFORM_IMPL_HTTP2_RECONSTRUCT_OBJECT_IMPL_H_
#define NET_HTTP2_PLATFORM_IMPL_HTTP2_RECONSTRUCT_OBJECT_IMPL_H_
#include <utility>
namespace http2 {
namespace test {
class Http2Random;
// Reconstruct an object so that it is initialized as when it was first
// constructed. Runs the destructor to handle objects that might own resources,
// and runs the constructor with the provided arguments, if any.
template <class T, class... Args>
void Http2ReconstructObjectImpl(T* ptr, Http2Random* rng, Args&&... args) {
ptr->~T();
::new (ptr) T(std::forward<Args>(args)...);
}
// This version applies default-initialization to the object.
template <class T>
void Http2DefaultReconstructObjectImpl(T* ptr, Http2Random* rng) {
ptr->~T();
::new (ptr) T;
}
} // namespace test
} // namespace http2
#endif // NET_HTTP2_PLATFORM_IMPL_HTTP2_RECONSTRUCT_OBJECT_IMPL_H_