projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Suppress more warnings for MSVC
[folly.git]
/
folly
/
Indestructible.h
diff --git
a/folly/Indestructible.h
b/folly/Indestructible.h
index 686bbce3014b73fe94cd0fbc0323985446a18b34..285d9ed6a6d3529850de5ca31612aa5d3dcf9a36 100644
(file)
--- a/
folly/Indestructible.h
+++ b/
folly/Indestructible.h
@@
-16,10
+16,9
@@
#pragma once
#pragma once
+#include <cassert>
+#include <type_traits>
#include <utility>
#include <utility>
-#include <glog/logging.h>
-#include <folly/Likely.h>
-#include <folly/Portability.h>
namespace folly {
namespace folly {
@@
-60,10
+59,13
@@
template <typename T>
class Indestructible final {
public:
class Indestructible final {
public:
- template <typename... Args>
+ template <typename S = T, typename = decltype(S())>
+ constexpr Indestructible() noexcept(noexcept(T())) {}
+
+ template <typename... Args, typename = decltype(T(std::declval<Args&&>()...))>
explicit constexpr Indestructible(Args&&... args) noexcept(
std::is_nothrow_constructible<T, Args&&...>::value)
explicit constexpr Indestructible(Args&&... args) noexcept(
std::is_nothrow_constructible<T, Args&&...>::value)
- : storage_(std::forward<Args>(args)...)
, inited_(true)
{}
+ : storage_(std::forward<Args>(args)...) {}
~Indestructible() = default;
~Indestructible() = default;
@@
-73,12
+75,12
@@
class Indestructible final {
Indestructible(Indestructible&& other) noexcept(
std::is_nothrow_move_constructible<T>::value)
: storage_(std::move(other.storage_.value)) {
Indestructible(Indestructible&& other) noexcept(
std::is_nothrow_move_constructible<T>::value)
: storage_(std::move(other.storage_.value)) {
- other.
inited_ = fals
e;
+ other.
erased_ = tru
e;
}
Indestructible& operator=(Indestructible&& other) noexcept(
std::is_nothrow_move_assignable<T>::value) {
storage_.value = std::move(other.storage_.value);
}
Indestructible& operator=(Indestructible&& other) noexcept(
std::is_nothrow_move_assignable<T>::value) {
storage_.value = std::move(other.storage_.value);
- other.
inited_ = fals
e;
+ other.
erased_ = tru
e;
}
T* get() {
}
T* get() {
@@
-96,26
+98,25
@@
class Indestructible final {
private:
void check() const {
private:
void check() const {
- if (UNLIKELY(!inited_)) {
- fail();
- }
- }
-
- [[noreturn]] FOLLY_NOINLINE static void fail() {
- LOG(FATAL) << "Indestructible is not initialized";
+ assert(!erased_);
}
union Storage {
T value;
}
union Storage {
T value;
- template <typename... Args>
+ template <typename S = T, typename = decltype(S())>
+ constexpr Storage() noexcept(noexcept(T())) : value() {}
+
+ template <
+ typename... Args,
+ typename = decltype(T(std::declval<Args&&>()...))>
explicit constexpr Storage(Args&&... args)
: value(std::forward<Args>(args)...) {}
~Storage() {}
};
explicit constexpr Storage(Args&&... args)
: value(std::forward<Args>(args)...) {}
~Storage() {}
};
- Storage storage_;
- bool
init
ed_{false};
+ Storage storage_
{}
;
+ bool
eras
ed_{false};
};
}
};
}