Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cut FOLLY_USE_CPP14_CONSTEXPR and FOLLY_CPP14_CONSTEXPR #1029

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 61 additions & 61 deletions folly/FixedString.h

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions folly/Optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Optional {
!std::is_abstract<Value>::value,
"Optional may not be used with abstract types");

FOLLY_CPP14_CONSTEXPR Optional() noexcept {}
constexpr Optional() noexcept {}

Optional(const Optional& src) noexcept(
std::is_nothrow_copy_constructible<Value>::value) {
Expand All @@ -121,14 +121,14 @@ class Optional {
}
}

FOLLY_CPP14_CONSTEXPR /* implicit */ Optional(const None&) noexcept {}
constexpr /* implicit */ Optional(const None&) noexcept {}

FOLLY_CPP14_CONSTEXPR /* implicit */ Optional(Value&& newValue) noexcept(
constexpr /* implicit */ Optional(Value&& newValue) noexcept(
std::is_nothrow_move_constructible<Value>::value) {
construct(std::move(newValue));
}

FOLLY_CPP14_CONSTEXPR /* implicit */ Optional(const Value& newValue) noexcept(
constexpr /* implicit */ Optional(const Value& newValue) noexcept(
std::is_nothrow_copy_constructible<Value>::value) {
construct(newValue);
}
Expand All @@ -153,12 +153,12 @@ class Optional {
Null>::type) noexcept = delete;

template <typename... Args>
FOLLY_CPP14_CONSTEXPR explicit Optional(in_place_t, Args&&... args) noexcept(
constexpr explicit Optional(in_place_t, Args&&... args) noexcept(
std::is_nothrow_constructible<Value, Args...>::value)
: Optional{PrivateConstructor{}, std::forward<Args>(args)...} {}

template <typename U, typename... Args>
FOLLY_CPP14_CONSTEXPR explicit Optional(
constexpr explicit Optional(
in_place_t,
std::initializer_list<U> il,
Args&&... args) noexcept(std::
Expand Down Expand Up @@ -274,22 +274,22 @@ class Optional {
}
}

FOLLY_CPP14_CONSTEXPR const Value& value() const& {
constexpr const Value& value() const& {
require_value();
return storage_.value;
}

FOLLY_CPP14_CONSTEXPR Value& value() & {
constexpr Value& value() & {
require_value();
return storage_.value;
}

FOLLY_CPP14_CONSTEXPR Value&& value() && {
constexpr Value&& value() && {
require_value();
return std::move(storage_.value);
}

FOLLY_CPP14_CONSTEXPR const Value&& value() const&& {
constexpr const Value&& value() const&& {
require_value();
return std::move(storage_.value);
}
Expand All @@ -302,41 +302,41 @@ class Optional {
}
Value* get_pointer() && = delete;

FOLLY_CPP14_CONSTEXPR bool has_value() const noexcept {
constexpr bool has_value() const noexcept {
return storage_.hasValue;
}

FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept {
constexpr bool hasValue() const noexcept {
return has_value();
}

FOLLY_CPP14_CONSTEXPR explicit operator bool() const noexcept {
constexpr explicit operator bool() const noexcept {
return has_value();
}

FOLLY_CPP14_CONSTEXPR const Value& operator*() const& {
constexpr const Value& operator*() const& {
return value();
}
FOLLY_CPP14_CONSTEXPR Value& operator*() & {
constexpr Value& operator*() & {
return value();
}
FOLLY_CPP14_CONSTEXPR const Value&& operator*() const&& {
constexpr const Value&& operator*() const&& {
return std::move(value());
}
FOLLY_CPP14_CONSTEXPR Value&& operator*() && {
constexpr Value&& operator*() && {
return std::move(value());
}

FOLLY_CPP14_CONSTEXPR const Value* operator->() const {
constexpr const Value* operator->() const {
return &value();
}
FOLLY_CPP14_CONSTEXPR Value* operator->() {
constexpr Value* operator->() {
return &value();
}

// Return a copy of the value if set, or a given default if not.
template <class U>
FOLLY_CPP14_CONSTEXPR Value value_or(U&& dflt) const& {
constexpr Value value_or(U&& dflt) const& {
if (storage_.hasValue) {
return storage_.value;
}
Expand All @@ -345,7 +345,7 @@ class Optional {
}

template <class U>
FOLLY_CPP14_CONSTEXPR Value value_or(U&& dflt) && {
constexpr Value value_or(U&& dflt) && {
if (storage_.hasValue) {
return std::move(storage_.value);
}
Expand Down Expand Up @@ -373,7 +373,7 @@ class Optional {
explicit PrivateConstructor() = default;
};
template <typename... Args>
FOLLY_CPP14_CONSTEXPR Optional(PrivateConstructor, Args&&... args) noexcept(
constexpr Optional(PrivateConstructor, Args&&... args) noexcept(
std::is_constructible<Value, Args&&...>::value) {
construct(std::forward<Args>(args)...);
}
Expand Down Expand Up @@ -493,7 +493,7 @@ constexpr bool operator!=(const U& a, const Optional<V>& b) {
}

template <class U, class V>
FOLLY_CPP14_CONSTEXPR bool operator==(
constexpr bool operator==(
const Optional<U>& a,
const Optional<V>& b) {
if (a.hasValue() != b.hasValue()) {
Expand All @@ -511,7 +511,7 @@ constexpr bool operator!=(const Optional<U>& a, const Optional<V>& b) {
}

template <class U, class V>
FOLLY_CPP14_CONSTEXPR bool operator<(
constexpr bool operator<(
const Optional<U>& a,
const Optional<V>& b) {
if (a.hasValue() != b.hasValue()) {
Expand Down
28 changes: 0 additions & 28 deletions folly/Portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,24 +440,6 @@ constexpr auto kCpplibVer = 0;
#endif
} // namespace folly

// Define FOLLY_USE_CPP14_CONSTEXPR to be true if the compiler's C++14
// constexpr support is "good enough".
#ifndef FOLLY_USE_CPP14_CONSTEXPR
#if defined(__clang__)
#define FOLLY_USE_CPP14_CONSTEXPR __cplusplus >= 201300L
#elif defined(__GNUC__)
#define FOLLY_USE_CPP14_CONSTEXPR __cplusplus >= 201304L
#else
#define FOLLY_USE_CPP14_CONSTEXPR 0 // MSVC?
#endif
#endif

#if FOLLY_USE_CPP14_CONSTEXPR
#define FOLLY_CPP14_CONSTEXPR constexpr
#else
#define FOLLY_CPP14_CONSTEXPR inline
#endif

// MSVC does not permit:
//
// extern int const num;
Expand All @@ -471,19 +453,9 @@ constexpr auto kCpplibVer = 0;
// True as of MSVC 2017.
#if _MSC_VER
#define FOLLY_STORAGE_CONSTEXPR
#define FOLLY_STORAGE_CPP14_CONSTEXPR
#else
#if __ICC
#define FOLLY_STORAGE_CONSTEXPR
#else
#define FOLLY_STORAGE_CONSTEXPR constexpr
#endif
#if FOLLY_USE_CPP14_CONSTEXPR
#define FOLLY_STORAGE_CPP14_CONSTEXPR constexpr
#else
#define FOLLY_STORAGE_CPP14_CONSTEXPR
#endif
#endif

#if __cpp_coroutines >= 201703L && __has_include(<experimental/coroutine>)
#define FOLLY_HAS_COROUTINES 1
Expand Down
14 changes: 7 additions & 7 deletions folly/Replaceable.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class alignas(T) Replaceable
template <
class... Args,
std::enable_if_t<std::is_constructible<T, Args&&...>::value, int> = 0>
FOLLY_CPP14_CONSTEXPR explicit Replaceable(in_place_t, Args&&... args)
constexpr explicit Replaceable(in_place_t, Args&&... args)
// clang-format off
noexcept(std::is_nothrow_constructible<T, Args&&...>::value)
// clang-format on
Expand All @@ -453,7 +453,7 @@ class alignas(T) Replaceable
std::enable_if_t<
std::is_constructible<T, std::initializer_list<U>, Args&&...>::value,
int> = 0>
FOLLY_CPP14_CONSTEXPR explicit Replaceable(
constexpr explicit Replaceable(
in_place_t,
std::initializer_list<U> il,
Args&&... args)
Expand All @@ -475,7 +475,7 @@ class alignas(T) Replaceable
!std::is_same<Replaceable<T>, std::decay_t<U>>::value &&
std::is_convertible<U&&, T>::value,
int> = 0>
FOLLY_CPP14_CONSTEXPR /* implicit */ Replaceable(U&& other)
constexpr /* implicit */ Replaceable(U&& other)
// clang-format off
noexcept(std::is_nothrow_constructible<T, U&&>::value)
// clang-format on
Expand All @@ -491,7 +491,7 @@ class alignas(T) Replaceable
!std::is_same<Replaceable<T>, std::decay_t<U>>::value &&
!std::is_convertible<U&&, T>::value,
int> = 0>
FOLLY_CPP14_CONSTEXPR explicit Replaceable(U&& other)
constexpr explicit Replaceable(U&& other)
// clang-format off
noexcept(std::is_nothrow_constructible<T, U&&>::value)
// clang-format on
Expand Down Expand Up @@ -611,19 +611,19 @@ class alignas(T) Replaceable
return launder(reinterpret_cast<T const*>(storage_));
}

FOLLY_CPP14_CONSTEXPR T* operator->() {
constexpr T* operator->() {
return launder(reinterpret_cast<T*>(storage_));
}

constexpr const T& operator*() const& {
return *launder(reinterpret_cast<T const*>(storage_));
}

FOLLY_CPP14_CONSTEXPR T& operator*() & {
constexpr T& operator*() & {
return *launder(reinterpret_cast<T*>(storage_));
}

FOLLY_CPP14_CONSTEXPR T&& operator*() && {
constexpr T&& operator*() && {
return std::move(*launder(reinterpret_cast<T*>(storage_)));
}

Expand Down
4 changes: 2 additions & 2 deletions folly/container/Foreach-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,15 @@ decltype(auto) fetch_impl(RangeTag, Sequence&& sequence, Index&& index) {
} // namespace for_each_detail

template <typename Sequence, typename Func>
FOLLY_CPP14_CONSTEXPR Func for_each(Sequence&& sequence, Func func) {
constexpr Func for_each(Sequence&& sequence, Func func) {
namespace fed = for_each_detail;
using tag = fed::SequenceTag<Sequence>;
fed::for_each_impl(tag{}, std::forward<Sequence>(sequence), func);
return func;
}

template <typename Sequence, typename Index>
FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index) {
constexpr decltype(auto) fetch(Sequence&& sequence, Index&& index) {
namespace fed = for_each_detail;
using tag = fed::SequenceTag<Sequence>;
return for_each_detail::fetch_impl(
Expand Down
4 changes: 2 additions & 2 deletions folly/container/Foreach.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace folly {
* });
*/
template <typename Range, typename Func>
FOLLY_CPP14_CONSTEXPR Func for_each(Range&& range, Func func);
constexpr Func for_each(Range&& range, Func func);

/**
* The user should return loop_break and loop_continue if they want to iterate
Expand Down Expand Up @@ -119,7 +119,7 @@ constexpr auto loop_continue = for_each_detail::LoopControl::CONTINUE;
* required element.
*/
template <typename Sequence, typename Index>
FOLLY_CPP14_CONSTEXPR decltype(auto) fetch(Sequence&& sequence, Index&& index);
constexpr decltype(auto) fetch(Sequence&& sequence, Index&& index);

} // namespace folly

Expand Down
20 changes: 10 additions & 10 deletions folly/lang/PropagateConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class propagate_const {
std::remove_reference_t<decltype(*std::declval<Pointer&>())>;

constexpr propagate_const() = default;
FOLLY_CPP14_CONSTEXPR propagate_const(propagate_const&&) = default;
constexpr propagate_const(propagate_const&&) = default;
propagate_const(propagate_const const&) = delete;

template <
Expand Down Expand Up @@ -105,14 +105,14 @@ class propagate_const {
constexpr propagate_const(OtherPointer&& other)
: pointer_(static_cast<OtherPointer&&>(other)) {}

FOLLY_CPP14_CONSTEXPR propagate_const& operator=(propagate_const&&) = default;
constexpr propagate_const& operator=(propagate_const&&) = default;
propagate_const& operator=(propagate_const const&) = delete;

template <
typename OtherPointer,
typename =
std::enable_if_t<std::is_convertible<OtherPointer&&, Pointer>::value>>
FOLLY_CPP14_CONSTEXPR propagate_const& operator=(
constexpr propagate_const& operator=(
propagate_const<OtherPointer>&& other) {
pointer_ = static_cast<OtherPointer&&>(other.pointer_);
}
Expand All @@ -122,19 +122,19 @@ class propagate_const {
typename = std::enable_if_t<
!detail::is_decay_propagate_const<OtherPointer>::value &&
std::is_convertible<OtherPointer&&, Pointer>::value>>
FOLLY_CPP14_CONSTEXPR propagate_const& operator=(OtherPointer&& other) {
constexpr propagate_const& operator=(OtherPointer&& other) {
pointer_ = static_cast<OtherPointer&&>(other);
return *this;
}

FOLLY_CPP14_CONSTEXPR void swap(propagate_const& other) noexcept(
constexpr void swap(propagate_const& other) noexcept(
noexcept(detail::propagate_const_adl::adl_swap(
std::declval<Pointer&>(),
other.pointer_))) {
detail::propagate_const_adl::adl_swap(pointer_, other.pointer_);
}

FOLLY_CPP14_CONSTEXPR element_type* get() {
constexpr element_type* get() {
return get_(pointer_);
}

Expand All @@ -146,15 +146,15 @@ class propagate_const {
return static_cast<bool>(pointer_);
}

FOLLY_CPP14_CONSTEXPR element_type& operator*() {
constexpr element_type& operator*() {
return *get();
}

constexpr element_type const& operator*() const {
return *get();
}

FOLLY_CPP14_CONSTEXPR element_type* operator->() {
constexpr element_type* operator->() {
return get();
}

Expand All @@ -167,7 +167,7 @@ class propagate_const {
typename = std::enable_if_t<
std::is_pointer<OtherPointer>::value ||
std::is_convertible<OtherPointer, element_type*>::value>>
FOLLY_CPP14_CONSTEXPR operator element_type*() {
constexpr operator element_type*() {
return get();
}

Expand Down Expand Up @@ -199,7 +199,7 @@ class propagate_const {
};

template <typename Pointer>
FOLLY_CPP14_CONSTEXPR void swap(
constexpr void swap(
propagate_const<Pointer>& a,
propagate_const<Pointer>& b) noexcept(noexcept(a.swap(b))) {
a.swap(b);
Expand Down
Loading