/*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <boost/operators.hpp>
+#include <folly/Portability.h>
namespace folly {
: hasValue_(false) {
}
- Optional(const Optional& src) {
+ Optional(const Optional& src)
+ noexcept(std::is_nothrow_copy_constructible<Value>::value) {
+
if (src.hasValue()) {
construct(src.value());
} else {
}
}
- Optional(Optional&& src) {
+ Optional(Optional&& src)
+ noexcept(std::is_nothrow_move_constructible<Value>::value) {
+
if (src.hasValue()) {
construct(std::move(src.value()));
src.clear();
}
}
- /* implicit */ Optional(const None&)
+ /* implicit */ Optional(const None&) noexcept
: hasValue_(false) {
}
- /* implicit */ Optional(Value&& newValue) {
+ /* implicit */ Optional(Value&& newValue)
+ noexcept(std::is_nothrow_move_constructible<Value>::value) {
construct(std::move(newValue));
}
- /* implicit */ Optional(const Value& newValue) {
+ /* implicit */ Optional(const Value& newValue)
+ noexcept(std::is_nothrow_copy_constructible<Value>::value) {
construct(newValue);
}
- ~Optional() {
+ ~Optional() noexcept {
clear();
}
}
void assign(Optional&& src) {
- if (src.hasValue()) {
- assign(std::move(src.value()));
- src.clear();
- } else {
- clear();
+ if (this != &src) {
+ if (src.hasValue()) {
+ assign(std::move(src.value()));
+ src.clear();
+ } else {
+ clear();
+ }
}
}
return *this;
}
- Optional& operator=(Optional &&other) {
+ Optional& operator=(Optional &&other)
+ noexcept (std::is_nothrow_move_assignable<Value>::value) {
+
assign(std::move(other));
return *this;
}
- Optional& operator=(const Optional &other) {
+ Optional& operator=(const Optional &other)
+ noexcept (std::is_nothrow_copy_assignable<Value>::value) {
+
assign(other);
return *this;
}