Commit cd3b981a authored by Joe Loser's avatar Joe Loser Committed by Facebook Github Bot

Cut FOLLY_USE_CPP14_CONSTEXPR and FOLLY_CPP14_CONSTEXPR (#1029)

Summary:
- `FOLLY_USE_CPP14_CONSTEXPR` macro is not needed as Folly requires a
  recent enough version of MSVC where its constexpr support is "good
  enough". For Clang and GCC, the min compiler versions supported would
  both evaluate the prior implementation of this macro to true in both
  cases. This is potentially slightly behavior changing since
  `FOLLY_USE_CPP14_CONSTEXPR` would be `inline` for ICC and I am not
  sure if its constexpr support is "good enough" for a min version of
  ICC we claim support for.
- Replace `FOLLY_CPP14_CONSTEXPR` with `constexpr` in all call sites and
  remove the `FOLLY_CPP14_CONSTEXPR` macro.
- Simplify how we define `FOLLY_STORAGE_CONSTEXPR` and
  `FOLLY_STORAGE_CPP14_CONSTEXPR` after cutting
  `FOLLY_USE_CPP14_CONSTEXPR`.
Pull Request resolved: https://github.com/facebook/folly/pull/1029

Reviewed By: Orvid

Differential Revision: D14199538

Pulled By: yfeldblum

fbshipit-source-id: 99daecf7d7ad0c4bf6735e74247112a78923602a
parent 02e56189
...@@ -307,7 +307,7 @@ struct Helper { ...@@ -307,7 +307,7 @@ struct Helper {
#endif #endif
template <class T> template <class T>
FOLLY_CPP14_CONSTEXPR void constexpr_swap(T& a, T& b) noexcept( constexpr void constexpr_swap(T& a, T& b) noexcept(
noexcept(a = T(std::move(a)))) { noexcept(a = T(std::move(a)))) {
T tmp((std::move(a))); T tmp((std::move(a)));
a = std::move(b); a = std::move(b);
...@@ -336,8 +336,7 @@ struct ReverseIterator { ...@@ -336,8 +336,7 @@ struct ReverseIterator {
constexpr ReverseIterator() = default; constexpr ReverseIterator() = default;
constexpr ReverseIterator(const ReverseIterator&) = default; constexpr ReverseIterator(const ReverseIterator&) = default;
FOLLY_CPP14_CONSTEXPR ReverseIterator& operator=(const ReverseIterator&) = constexpr ReverseIterator& operator=(const ReverseIterator&) = default;
default;
constexpr explicit ReverseIterator(T* p) noexcept : p_(p) {} constexpr explicit ReverseIterator(T* p) noexcept : p_(p) {}
constexpr /* implicit */ ReverseIterator(const other& that) noexcept constexpr /* implicit */ ReverseIterator(const other& that) noexcept
: p_(that.p_) {} : p_(that.p_) {}
...@@ -354,25 +353,25 @@ struct ReverseIterator { ...@@ -354,25 +353,25 @@ struct ReverseIterator {
constexpr reference operator*() const { constexpr reference operator*() const {
return *(p_ - 1); return *(p_ - 1);
} }
FOLLY_CPP14_CONSTEXPR ReverseIterator& operator++() noexcept { constexpr ReverseIterator& operator++() noexcept {
--p_; --p_;
return *this; return *this;
} }
FOLLY_CPP14_CONSTEXPR ReverseIterator operator++(int) noexcept { constexpr ReverseIterator operator++(int) noexcept {
auto tmp(*this); auto tmp(*this);
--p_; --p_;
return tmp; return tmp;
} }
FOLLY_CPP14_CONSTEXPR ReverseIterator& operator--() noexcept { constexpr ReverseIterator& operator--() noexcept {
++p_; ++p_;
return *this; return *this;
} }
FOLLY_CPP14_CONSTEXPR ReverseIterator operator--(int) noexcept { constexpr ReverseIterator operator--(int) noexcept {
auto tmp(*this); auto tmp(*this);
++p_; ++p_;
return tmp; return tmp;
} }
FOLLY_CPP14_CONSTEXPR ReverseIterator& operator+=(std::ptrdiff_t i) noexcept { constexpr ReverseIterator& operator+=(std::ptrdiff_t i) noexcept {
p_ -= i; p_ -= i;
return *this; return *this;
} }
...@@ -386,7 +385,7 @@ struct ReverseIterator { ...@@ -386,7 +385,7 @@ struct ReverseIterator {
std::ptrdiff_t i) noexcept { std::ptrdiff_t i) noexcept {
return ReverseIterator{that.p_ - i}; return ReverseIterator{that.p_ - i};
} }
FOLLY_CPP14_CONSTEXPR ReverseIterator& operator-=(std::ptrdiff_t i) noexcept { constexpr ReverseIterator& operator-=(std::ptrdiff_t i) noexcept {
p_ += i; p_ += i;
return *this; return *this;
} }
...@@ -728,8 +727,8 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -728,8 +727,8 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
constexpr BasicFixedString(std::initializer_list<Char> il) noexcept(false) constexpr BasicFixedString(std::initializer_list<Char> il) noexcept(false)
: BasicFixedString{il.begin(), il.size()} {} : BasicFixedString{il.begin(), il.size()} {}
FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=( constexpr BasicFixedString& operator=(const BasicFixedString&) noexcept =
const BasicFixedString&) noexcept = default; default;
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
* Assign from a `BasicFixedString<Char, M>`. * Assign from a `BasicFixedString<Char, M>`.
...@@ -745,7 +744,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -745,7 +744,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \return `*this` * \return `*this`
*/ */
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=( constexpr BasicFixedString& operator=(
const BasicFixedString<Char, M>& that) noexcept(M <= N) { const BasicFixedString<Char, M>& that) noexcept(M <= N) {
detail::fixedstring::checkOverflow(that.size_, N); detail::fixedstring::checkOverflow(that.size_, N);
size_ = that.copy(data_, that.size_); size_ = that.copy(data_, that.size_);
...@@ -764,8 +763,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -764,8 +763,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \return `*this` * \return `*this`
*/ */
template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type> template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type>
FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=( constexpr BasicFixedString& operator=(const Char (&that)[M]) noexcept {
const Char (&that)[M]) noexcept {
return assign(detail::fixedstring::checkNullTerminated(that), M - 1u); return assign(detail::fixedstring::checkNullTerminated(that), M - 1u);
} }
...@@ -778,7 +776,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -778,7 +776,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \throw std::out_of_range when il.size() > N * \throw std::out_of_range when il.size() > N
* \return `*this` * \return `*this`
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& operator=( constexpr BasicFixedString& operator=(
std::initializer_list<Char> il) noexcept(false) { std::initializer_list<Char> il) noexcept(false) {
detail::fixedstring::checkOverflow(il.size(), N); detail::fixedstring::checkOverflow(il.size(), N);
for (std::size_t i = 0u; i < il.size(); ++i) { for (std::size_t i = 0u; i < il.size(); ++i) {
...@@ -793,7 +791,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -793,7 +791,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* Conversion to folly::Range * Conversion to folly::Range
* \return `Range<Char*>{begin(), end()}` * \return `Range<Char*>{begin(), end()}`
*/ */
FOLLY_CPP14_CONSTEXPR Range<Char*> toRange() noexcept { constexpr Range<Char*> toRange() noexcept {
return {begin(), end()}; return {begin(), end()};
} }
...@@ -821,7 +819,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -821,7 +819,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
// to compile. But it creates ambiguities when passing a FixedString to an // to compile. But it creates ambiguities when passing a FixedString to an
// API that has overloads for `const char*` and `folly::Range`, for instance. // API that has overloads for `const char*` and `folly::Range`, for instance.
// using ArrayType = Char[N]; // using ArrayType = Char[N];
// FOLLY_CPP14_CONSTEXPR /* implicit */ operator ArrayType&() noexcept { // constexpr /* implicit */ operator ArrayType&() noexcept {
// return data_; // return data_;
// } // }
...@@ -841,9 +839,8 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -841,9 +839,8 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \throw std::out_of_range when count > N * \throw std::out_of_range when count > N
* \return `*this` * \return `*this`
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& assign( constexpr BasicFixedString& assign(std::size_t count, Char ch) noexcept(
std::size_t count, false) {
Char ch) noexcept(false) {
detail::fixedstring::checkOverflow(count, N); detail::fixedstring::checkOverflow(count, N);
for (std::size_t i = 0u; i < count; ++i) { for (std::size_t i = 0u; i < count; ++i) {
data_[i] = ch; data_[i] = ch;
...@@ -858,7 +855,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -858,7 +855,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to `assign(that, 0, that.size())` * \note Equivalent to `assign(that, 0, that.size())`
*/ */
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& assign( constexpr BasicFixedString& assign(
const BasicFixedString<Char, M>& that) noexcept(M <= N) { const BasicFixedString<Char, M>& that) noexcept(M <= N) {
return *this = that; return *this = that;
} }
...@@ -868,7 +865,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -868,7 +865,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
// N is a count of characters. In the latter, it would be a position, which // N is a count of characters. In the latter, it would be a position, which
// totally changes the meaning of the code. // totally changes the meaning of the code.
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& assign( constexpr BasicFixedString& assign(
const BasicFixedString<Char, M>& that, const BasicFixedString<Char, M>& that,
std::size_t pos) noexcept(false) = delete; std::size_t pos) noexcept(false) = delete;
...@@ -890,7 +887,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -890,7 +887,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \return `*this` * \return `*this`
*/ */
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& assign( constexpr BasicFixedString& assign(
const BasicFixedString<Char, M>& that, const BasicFixedString<Char, M>& that,
std::size_t pos, std::size_t pos,
std::size_t count) noexcept(false) { std::size_t count) noexcept(false) {
...@@ -907,8 +904,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -907,8 +904,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to `assign(that, M - 1)` * \note Equivalent to `assign(that, M - 1)`
*/ */
template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type> template <std::size_t M, class = typename std::enable_if<(M - 1u <= N)>::type>
FOLLY_CPP14_CONSTEXPR BasicFixedString& assign( constexpr BasicFixedString& assign(const Char (&that)[M]) noexcept {
const Char (&that)[M]) noexcept {
return assign(detail::fixedstring::checkNullTerminated(that), M - 1u); return assign(detail::fixedstring::checkNullTerminated(that), M - 1u);
} }
...@@ -924,7 +920,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -924,7 +920,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \throw std::out_of_range when count > N * \throw std::out_of_range when count > N
* \return `*this` * \return `*this`
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& assign( constexpr BasicFixedString& assign(
const Char* that, const Char* that,
std::size_t count) noexcept(false) { std::size_t count) noexcept(false) {
detail::fixedstring::checkOverflow(count, N); detail::fixedstring::checkOverflow(count, N);
...@@ -939,7 +935,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -939,7 +935,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
* Swap the contents of this string with `that`. * Swap the contents of this string with `that`.
*/ */
FOLLY_CPP14_CONSTEXPR void swap(BasicFixedString& that) noexcept { constexpr void swap(BasicFixedString& that) noexcept {
// less-than-or-equal here to copy the null terminator: // less-than-or-equal here to copy the null terminator:
for (std::size_t i = 0u; i <= folly::constexpr_max(size_, that.size_); for (std::size_t i = 0u; i <= folly::constexpr_max(size_, that.size_);
++i) { ++i) {
...@@ -952,7 +948,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -952,7 +948,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* Return a pointer to a range of `size()+1` characters, the last of which * Return a pointer to a range of `size()+1` characters, the last of which
* is `Char(0)`. * is `Char(0)`.
*/ */
FOLLY_CPP14_CONSTEXPR Char* data() noexcept { constexpr Char* data() noexcept {
return data_; return data_;
} }
...@@ -973,7 +969,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -973,7 +969,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
* \return `data()`. * \return `data()`.
*/ */
FOLLY_CPP14_CONSTEXPR Char* begin() noexcept { constexpr Char* begin() noexcept {
return data_; return data_;
} }
...@@ -994,7 +990,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -994,7 +990,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
/** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
* \return `data() + size()`. * \return `data() + size()`.
*/ */
FOLLY_CPP14_CONSTEXPR Char* end() noexcept { constexpr Char* end() noexcept {
return data_ + size_; return data_ + size_;
} }
...@@ -1016,7 +1012,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1016,7 +1012,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* Returns a reverse iterator to the first character of the reversed string. * Returns a reverse iterator to the first character of the reversed string.
* It corresponds to the last + 1 character of the non-reversed string. * It corresponds to the last + 1 character of the non-reversed string.
*/ */
FOLLY_CPP14_CONSTEXPR reverse_iterator rbegin() noexcept { constexpr reverse_iterator rbegin() noexcept {
return reverse_iterator{data_ + size_}; return reverse_iterator{data_ + size_};
} }
...@@ -1038,7 +1034,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1038,7 +1034,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* Returns a reverse iterator to the last + 1 character of the reversed * Returns a reverse iterator to the last + 1 character of the reversed
* string. It corresponds to the first character of the non-reversed string. * string. It corresponds to the first character of the non-reversed string.
*/ */
FOLLY_CPP14_CONSTEXPR reverse_iterator rend() noexcept { constexpr reverse_iterator rend() noexcept {
return reverse_iterator{data_}; return reverse_iterator{data_};
} }
...@@ -1102,7 +1098,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1102,7 +1098,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \return `*(data() + i)` * \return `*(data() + i)`
* \throw std::out_of_range when i > size() * \throw std::out_of_range when i > size()
*/ */
FOLLY_CPP14_CONSTEXPR Char& at(std::size_t i) noexcept(false) { constexpr Char& at(std::size_t i) noexcept(false) {
return i <= size_ ? data_[i] return i <= size_ ? data_[i]
: (throw_exception<std::out_of_range>( : (throw_exception<std::out_of_range>(
"Out of range in BasicFixedString::at"), "Out of range in BasicFixedString::at"),
...@@ -1124,7 +1120,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1124,7 +1120,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note `(*this)[size()]` is allowed will return `Char(0)`. * \note `(*this)[size()]` is allowed will return `Char(0)`.
* \return `*(data() + i)` * \return `*(data() + i)`
*/ */
FOLLY_CPP14_CONSTEXPR Char& operator[](std::size_t i) noexcept { constexpr Char& operator[](std::size_t i) noexcept {
#ifdef NDEBUG #ifdef NDEBUG
return data_[i]; return data_[i];
#else #else
...@@ -1146,7 +1142,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1146,7 +1142,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
/** /**
* \note Equivalent to `(*this)[0]` * \note Equivalent to `(*this)[0]`
*/ */
FOLLY_CPP14_CONSTEXPR Char& front() noexcept { constexpr Char& front() noexcept {
return (*this)[0u]; return (*this)[0u];
} }
...@@ -1161,7 +1157,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1161,7 +1157,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to `at(size()-1)` * \note Equivalent to `at(size()-1)`
* \pre `!empty()` * \pre `!empty()`
*/ */
FOLLY_CPP14_CONSTEXPR Char& back() noexcept { constexpr Char& back() noexcept {
#ifdef NDEBUG #ifdef NDEBUG
return data_[size_ - 1u]; return data_[size_ - 1u];
#else #else
...@@ -1185,7 +1181,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1185,7 +1181,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \post `size() == 0u` * \post `size() == 0u`
* \post `at(size()) == Char(0)` * \post `at(size()) == Char(0)`
*/ */
FOLLY_CPP14_CONSTEXPR void clear() noexcept { constexpr void clear() noexcept {
data_[0u] = Char(0); data_[0u] = Char(0);
size_ = 0u; size_ = 0u;
} }
...@@ -1193,7 +1189,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1193,7 +1189,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
/** /**
* \note Equivalent to `append(1u, ch)`. * \note Equivalent to `append(1u, ch)`.
*/ */
FOLLY_CPP14_CONSTEXPR void push_back(Char ch) noexcept(false) { constexpr void push_back(Char ch) noexcept(false) {
detail::fixedstring::checkOverflow(1u, N - size_); detail::fixedstring::checkOverflow(1u, N - size_);
data_[size_] = ch; data_[size_] = ch;
data_[++size_] = Char(0); data_[++size_] = Char(0);
...@@ -1214,7 +1210,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1214,7 +1210,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \post The characters in the half-open range `[0,size()-1)` are unmodified. * \post The characters in the half-open range `[0,size()-1)` are unmodified.
* \throw std::out_of_range if empty(). * \throw std::out_of_range if empty().
*/ */
FOLLY_CPP14_CONSTEXPR void pop_back() noexcept(false) { constexpr void pop_back() noexcept(false) {
detail::fixedstring::checkOverflow(1u, size_); detail::fixedstring::checkOverflow(1u, size_);
--size_; --size_;
data_[size_] = Char(0); data_[size_] = Char(0);
...@@ -1237,9 +1233,8 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1237,9 +1233,8 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \post `size() == old_size + count` * \post `size() == old_size + count`
* \throw std::out_of_range if count > N - size(). * \throw std::out_of_range if count > N - size().
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& append( constexpr BasicFixedString& append(std::size_t count, Char ch) noexcept(
std::size_t count, false) {
Char ch) noexcept(false) {
detail::fixedstring::checkOverflow(count, N - size_); detail::fixedstring::checkOverflow(count, N - size_);
for (std::size_t i = 0u; i < count; ++i) { for (std::size_t i = 0u; i < count; ++i) {
data_[size_ + i] = ch; data_[size_ + i] = ch;
...@@ -1253,7 +1248,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1253,7 +1248,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to `append(*this, 0, that.size())`. * \note Equivalent to `append(*this, 0, that.size())`.
*/ */
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& append( constexpr BasicFixedString& append(
const BasicFixedString<Char, M>& that) noexcept(false) { const BasicFixedString<Char, M>& that) noexcept(false) {
return append(that, 0u, that.size_); return append(that, 0u, that.size_);
} }
...@@ -1262,7 +1257,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1262,7 +1257,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
// append("null-terminated", N), where N would be a count instead // append("null-terminated", N), where N would be a count instead
// of a position. // of a position.
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& append( constexpr BasicFixedString& append(
const BasicFixedString<Char, M>& that, const BasicFixedString<Char, M>& that,
std::size_t pos) noexcept(false) = delete; std::size_t pos) noexcept(false) = delete;
...@@ -1283,7 +1278,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1283,7 +1278,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* `old_size + count > N`. * `old_size + count > N`.
*/ */
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& append( constexpr BasicFixedString& append(
const BasicFixedString<Char, M>& that, const BasicFixedString<Char, M>& that,
std::size_t pos, std::size_t pos,
std::size_t count) noexcept(false) { std::size_t count) noexcept(false) {
...@@ -1301,8 +1296,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1301,8 +1296,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
/** /**
* \note Equivalent to `append(that, strlen(that))`. * \note Equivalent to `append(that, strlen(that))`.
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& append(const Char* that) noexcept( constexpr BasicFixedString& append(const Char* that) noexcept(false) {
false) {
return append(that, folly::constexpr_strlen(that)); return append(that, folly::constexpr_strlen(that));
} }
...@@ -1315,7 +1309,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1315,7 +1309,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \post `at(size()) == Char(0)` * \post `at(size()) == Char(0)`
* \throw std::out_of_range if old_size + count > N. * \throw std::out_of_range if old_size + count > N.
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& append( constexpr BasicFixedString& append(
const Char* that, const Char* that,
std::size_t count) noexcept(false) { std::size_t count) noexcept(false) {
detail::fixedstring::checkOverflow(count, N - size_); detail::fixedstring::checkOverflow(count, N - size_);
...@@ -1401,8 +1395,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1401,8 +1395,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* Appends characters from a null-terminated string literal to this string. * Appends characters from a null-terminated string literal to this string.
* \note Equivalent to `append(that)`. * \note Equivalent to `append(that)`.
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(const Char* that) noexcept( constexpr BasicFixedString& operator+=(const Char* that) noexcept(false) {
false) {
return append(that); return append(that);
} }
...@@ -1411,7 +1404,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1411,7 +1404,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to `append(that)`. * \note Equivalent to `append(that)`.
*/ */
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=( constexpr BasicFixedString& operator+=(
const BasicFixedString<Char, M>& that) noexcept(false) { const BasicFixedString<Char, M>& that) noexcept(false) {
return append(that, 0u, that.size_); return append(that, 0u, that.size_);
} }
...@@ -1420,7 +1413,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1420,7 +1413,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* Appends a character to this string. * Appends a character to this string.
* \note Equivalent to `push_back(ch)`. * \note Equivalent to `push_back(ch)`.
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=(Char ch) noexcept(false) { constexpr BasicFixedString& operator+=(Char ch) noexcept(false) {
push_back(ch); push_back(ch);
return *this; return *this;
} }
...@@ -1429,7 +1422,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1429,7 +1422,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* Appends characters from an `initializer_list` to this string. * Appends characters from an `initializer_list` to this string.
* \note Equivalent to `append(il.begin(), il.size())`. * \note Equivalent to `append(il.begin(), il.size())`.
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& operator+=( constexpr BasicFixedString& operator+=(
std::initializer_list<Char> il) noexcept(false) { std::initializer_list<Char> il) noexcept(false) {
return append(il.begin(), il.size()); return append(il.begin(), il.size());
} }
...@@ -1439,7 +1432,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1439,7 +1432,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to `clear()` * \note Equivalent to `clear()`
* \return *this; * \return *this;
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& erase() noexcept { constexpr BasicFixedString& erase() noexcept {
clear(); clear();
return *this; return *this;
} }
...@@ -1454,7 +1447,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1454,7 +1447,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \return *this; * \return *this;
* \throw std::out_of_range when pos > size(). * \throw std::out_of_range when pos > size().
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& erase( constexpr BasicFixedString& erase(
std::size_t pos, std::size_t pos,
std::size_t count = npos) noexcept(false) { std::size_t count = npos) noexcept(false) {
using A = const Char[1]; using A = const Char[1];
...@@ -1471,7 +1464,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1471,7 +1464,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to `erase(first - data(), 1)` * \note Equivalent to `erase(first - data(), 1)`
* \return A pointer to the first character after the erased character. * \return A pointer to the first character after the erased character.
*/ */
FOLLY_CPP14_CONSTEXPR Char* erase(const Char* first) noexcept(false) { constexpr Char* erase(const Char* first) noexcept(false) {
erase(first - data_, 1u); erase(first - data_, 1u);
return data_ + (first - data_); return data_ + (first - data_);
} }
...@@ -1480,9 +1473,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1480,9 +1473,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to `erase(first - data(), last - first)` * \note Equivalent to `erase(first - data(), last - first)`
* \return A pointer to the first character after the erased characters. * \return A pointer to the first character after the erased characters.
*/ */
FOLLY_CPP14_CONSTEXPR Char* erase( constexpr Char* erase(const Char* first, const Char* last) noexcept(false) {
const Char* first,
const Char* last) noexcept(false) {
erase(first - data_, last - first); erase(first - data_, last - first);
return data_ + (first - data_); return data_ + (first - data_);
} }
...@@ -1661,7 +1652,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1661,7 +1652,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* `replace(first - data(), last - first, that.data(), that.size())` * `replace(first - data(), last - first, that.data(), that.size())`
*/ */
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& replace( constexpr BasicFixedString& replace(
const Char* first, const Char* first,
const Char* last, const Char* last,
const BasicFixedString<Char, M>& that) noexcept(false) { const BasicFixedString<Char, M>& that) noexcept(false) {
...@@ -1677,7 +1668,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1677,7 +1668,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* that.size() - that_pos)</tt> * that.size() - that_pos)</tt>
*/ */
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& replace( constexpr BasicFixedString& replace(
std::size_t this_pos, std::size_t this_pos,
std::size_t this_count, std::size_t this_count,
const BasicFixedString<Char, M>& that, const BasicFixedString<Char, M>& that,
...@@ -1694,7 +1685,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1694,7 +1685,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* `replace(this_pos, this_count, that.data() + that_pos, that_count)` * `replace(this_pos, this_count, that.data() + that_pos, that_count)`
*/ */
template <std::size_t M> template <std::size_t M>
FOLLY_CPP14_CONSTEXPR BasicFixedString& replace( constexpr BasicFixedString& replace(
std::size_t this_pos, std::size_t this_pos,
std::size_t this_count, std::size_t this_count,
const BasicFixedString<Char, M>& that, const BasicFixedString<Char, M>& that,
...@@ -1709,7 +1700,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1709,7 +1700,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to * \note Equivalent to
* `replace(this_pos, this_count, that, strlen(that))` * `replace(this_pos, this_count, that, strlen(that))`
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& replace( constexpr BasicFixedString& replace(
std::size_t this_pos, std::size_t this_pos,
std::size_t this_count, std::size_t this_count,
const Char* that) noexcept(false) { const Char* that) noexcept(false) {
...@@ -1724,7 +1715,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1724,7 +1715,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to * \note Equivalent to
* `replace(first - data(), last - first, that, strlen(that))` * `replace(first - data(), last - first, that, strlen(that))`
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& replace( constexpr BasicFixedString& replace(
const Char* first, const Char* first,
const Char* last, const Char* last,
const Char* that) noexcept(false) { const Char* that) noexcept(false) {
...@@ -1749,7 +1740,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1749,7 +1740,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* - `this_count > size() - this_pos` * - `this_count > size() - this_pos`
* - `size() - this_count + that_count > N` * - `size() - this_count + that_count > N`
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& replace( constexpr BasicFixedString& replace(
std::size_t this_pos, std::size_t this_pos,
std::size_t this_count, std::size_t this_count,
const Char* that, const Char* that,
...@@ -1772,7 +1763,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1772,7 +1763,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to * \note Equivalent to
* `replace(this_pos, this_count, BasicFixedString{that_count, ch})` * `replace(this_pos, this_count, BasicFixedString{that_count, ch})`
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& replace( constexpr BasicFixedString& replace(
std::size_t this_pos, std::size_t this_pos,
std::size_t this_count, std::size_t this_count,
std::size_t that_count, std::size_t that_count,
...@@ -1786,7 +1777,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1786,7 +1777,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to * \note Equivalent to
* `replace(first - data(), last - first, BasicFixedString{that_count, ch})` * `replace(first - data(), last - first, BasicFixedString{that_count, ch})`
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& replace( constexpr BasicFixedString& replace(
const Char* first, const Char* first,
const Char* last, const Char* last,
std::size_t that_count, std::size_t that_count,
...@@ -1803,7 +1794,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -1803,7 +1794,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \note Equivalent to * \note Equivalent to
* `replace(this_pos, this_count, il.begin(), il.size())` * `replace(this_pos, this_count, il.begin(), il.size())`
*/ */
FOLLY_CPP14_CONSTEXPR BasicFixedString& replace( constexpr BasicFixedString& replace(
const Char* first, const Char* first,
const Char* last, const Char* last,
std::initializer_list<Char> il) noexcept(false) { std::initializer_list<Char> il) noexcept(false) {
...@@ -2014,8 +2005,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -2014,8 +2005,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* from this string into the buffer pointed to by `dest`. * from this string into the buffer pointed to by `dest`.
* \return The number of characters copied. * \return The number of characters copied.
*/ */
FOLLY_CPP14_CONSTEXPR std::size_t copy(Char* dest, std::size_t count) const constexpr std::size_t copy(Char* dest, std::size_t count) const noexcept {
noexcept {
return copy(dest, count, 0u); return copy(dest, count, 0u);
} }
...@@ -2026,8 +2016,8 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -2026,8 +2016,8 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* \return The number of characters copied. * \return The number of characters copied.
* \throw std::out_of_range if `pos > size()` * \throw std::out_of_range if `pos > size()`
*/ */
FOLLY_CPP14_CONSTEXPR std::size_t constexpr std::size_t copy(Char* dest, std::size_t count, std::size_t pos)
copy(Char* dest, std::size_t count, std::size_t pos) const noexcept(false) { const noexcept(false) {
detail::fixedstring::checkOverflow(pos, size_); detail::fixedstring::checkOverflow(pos, size_);
for (std::size_t i = 0u; i < count; ++i) { for (std::size_t i = 0u; i < count; ++i) {
if (i + pos == size_) { if (i + pos == size_) {
...@@ -2042,7 +2032,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -2042,7 +2032,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* Resizes the current string. * Resizes the current string.
* \note Equivalent to `resize(count, Char(0))` * \note Equivalent to `resize(count, Char(0))`
*/ */
FOLLY_CPP14_CONSTEXPR void resize(std::size_t count) noexcept(false) { constexpr void resize(std::size_t count) noexcept(false) {
resize(count, Char(0)); resize(count, Char(0));
} }
...@@ -2051,8 +2041,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { ...@@ -2051,8 +2041,7 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase {
* `data()[count]` to `Char(0)`. If `count > old_size`, the characters * `data()[count]` to `Char(0)`. If `count > old_size`, the characters
* in the range [`old_size`,`count`) are set to `ch`. * in the range [`old_size`,`count`) are set to `ch`.
*/ */
FOLLY_CPP14_CONSTEXPR void resize(std::size_t count, Char ch) noexcept( constexpr void resize(std::size_t count, Char ch) noexcept(false) {
false) {
detail::fixedstring::checkOverflow(count, N); detail::fixedstring::checkOverflow(count, N);
if (count == size_) { if (count == size_) {
} else if (count < size_) { } else if (count < size_) {
...@@ -2998,7 +2987,7 @@ constexpr BasicFixedString<Char, N - 1u> makeFixedString( ...@@ -2998,7 +2987,7 @@ constexpr BasicFixedString<Char, N - 1u> makeFixedString(
* Swap function * Swap function
*/ */
template <class Char, std::size_t N> template <class Char, std::size_t N>
FOLLY_CPP14_CONSTEXPR void swap( constexpr void swap(
BasicFixedString<Char, N>& a, BasicFixedString<Char, N>& a,
BasicFixedString<Char, N>& b) noexcept { BasicFixedString<Char, N>& b) noexcept {
a.swap(b); a.swap(b);
......
...@@ -104,7 +104,7 @@ class Optional { ...@@ -104,7 +104,7 @@ class Optional {
!std::is_abstract<Value>::value, !std::is_abstract<Value>::value,
"Optional may not be used with abstract types"); "Optional may not be used with abstract types");
FOLLY_CPP14_CONSTEXPR Optional() noexcept {} constexpr Optional() noexcept {}
Optional(const Optional& src) noexcept( Optional(const Optional& src) noexcept(
std::is_nothrow_copy_constructible<Value>::value) { std::is_nothrow_copy_constructible<Value>::value) {
...@@ -121,14 +121,14 @@ class Optional { ...@@ -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) { std::is_nothrow_move_constructible<Value>::value) {
construct(std::move(newValue)); 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) { std::is_nothrow_copy_constructible<Value>::value) {
construct(newValue); construct(newValue);
} }
...@@ -153,12 +153,12 @@ class Optional { ...@@ -153,12 +153,12 @@ class Optional {
Null>::type) noexcept = delete; Null>::type) noexcept = delete;
template <typename... Args> 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) std::is_nothrow_constructible<Value, Args...>::value)
: Optional{PrivateConstructor{}, std::forward<Args>(args)...} {} : Optional{PrivateConstructor{}, std::forward<Args>(args)...} {}
template <typename U, typename... Args> template <typename U, typename... Args>
FOLLY_CPP14_CONSTEXPR explicit Optional( constexpr explicit Optional(
in_place_t, in_place_t,
std::initializer_list<U> il, std::initializer_list<U> il,
Args&&... args) noexcept(std:: Args&&... args) noexcept(std::
...@@ -274,22 +274,22 @@ class Optional { ...@@ -274,22 +274,22 @@ class Optional {
} }
} }
FOLLY_CPP14_CONSTEXPR const Value& value() const& { constexpr const Value& value() const& {
require_value(); require_value();
return storage_.value; return storage_.value;
} }
FOLLY_CPP14_CONSTEXPR Value& value() & { constexpr Value& value() & {
require_value(); require_value();
return storage_.value; return storage_.value;
} }
FOLLY_CPP14_CONSTEXPR Value&& value() && { constexpr Value&& value() && {
require_value(); require_value();
return std::move(storage_.value); return std::move(storage_.value);
} }
FOLLY_CPP14_CONSTEXPR const Value&& value() const&& { constexpr const Value&& value() const&& {
require_value(); require_value();
return std::move(storage_.value); return std::move(storage_.value);
} }
...@@ -302,41 +302,41 @@ class Optional { ...@@ -302,41 +302,41 @@ class Optional {
} }
Value* get_pointer() && = delete; Value* get_pointer() && = delete;
FOLLY_CPP14_CONSTEXPR bool has_value() const noexcept { constexpr bool has_value() const noexcept {
return storage_.hasValue; return storage_.hasValue;
} }
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept { constexpr bool hasValue() const noexcept {
return has_value(); return has_value();
} }
FOLLY_CPP14_CONSTEXPR explicit operator bool() const noexcept { constexpr explicit operator bool() const noexcept {
return has_value(); return has_value();
} }
FOLLY_CPP14_CONSTEXPR const Value& operator*() const& { constexpr const Value& operator*() const& {
return value(); return value();
} }
FOLLY_CPP14_CONSTEXPR Value& operator*() & { constexpr Value& operator*() & {
return value(); return value();
} }
FOLLY_CPP14_CONSTEXPR const Value&& operator*() const&& { constexpr const Value&& operator*() const&& {
return std::move(value()); return std::move(value());
} }
FOLLY_CPP14_CONSTEXPR Value&& operator*() && { constexpr Value&& operator*() && {
return std::move(value()); return std::move(value());
} }
FOLLY_CPP14_CONSTEXPR const Value* operator->() const { constexpr const Value* operator->() const {
return &value(); return &value();
} }
FOLLY_CPP14_CONSTEXPR Value* operator->() { constexpr Value* operator->() {
return &value(); return &value();
} }
// Return a copy of the value if set, or a given default if not. // Return a copy of the value if set, or a given default if not.
template <class U> template <class U>
FOLLY_CPP14_CONSTEXPR Value value_or(U&& dflt) const& { constexpr Value value_or(U&& dflt) const& {
if (storage_.hasValue) { if (storage_.hasValue) {
return storage_.value; return storage_.value;
} }
...@@ -345,7 +345,7 @@ class Optional { ...@@ -345,7 +345,7 @@ class Optional {
} }
template <class U> template <class U>
FOLLY_CPP14_CONSTEXPR Value value_or(U&& dflt) && { constexpr Value value_or(U&& dflt) && {
if (storage_.hasValue) { if (storage_.hasValue) {
return std::move(storage_.value); return std::move(storage_.value);
} }
...@@ -373,7 +373,7 @@ class Optional { ...@@ -373,7 +373,7 @@ class Optional {
explicit PrivateConstructor() = default; explicit PrivateConstructor() = default;
}; };
template <typename... Args> template <typename... Args>
FOLLY_CPP14_CONSTEXPR Optional(PrivateConstructor, Args&&... args) noexcept( constexpr Optional(PrivateConstructor, Args&&... args) noexcept(
std::is_constructible<Value, Args&&...>::value) { std::is_constructible<Value, Args&&...>::value) {
construct(std::forward<Args>(args)...); construct(std::forward<Args>(args)...);
} }
...@@ -493,9 +493,7 @@ constexpr bool operator!=(const U& a, const Optional<V>& b) { ...@@ -493,9 +493,7 @@ constexpr bool operator!=(const U& a, const Optional<V>& b) {
} }
template <class U, class V> template <class U, class V>
FOLLY_CPP14_CONSTEXPR bool operator==( constexpr bool operator==(const Optional<U>& a, const Optional<V>& b) {
const Optional<U>& a,
const Optional<V>& b) {
if (a.hasValue() != b.hasValue()) { if (a.hasValue() != b.hasValue()) {
return false; return false;
} }
...@@ -511,9 +509,7 @@ constexpr bool operator!=(const Optional<U>& a, const Optional<V>& b) { ...@@ -511,9 +509,7 @@ constexpr bool operator!=(const Optional<U>& a, const Optional<V>& b) {
} }
template <class U, class V> template <class U, class V>
FOLLY_CPP14_CONSTEXPR bool operator<( constexpr bool operator<(const Optional<U>& a, const Optional<V>& b) {
const Optional<U>& a,
const Optional<V>& b) {
if (a.hasValue() != b.hasValue()) { if (a.hasValue() != b.hasValue()) {
return a.hasValue() < b.hasValue(); return a.hasValue() < b.hasValue();
} }
......
...@@ -440,24 +440,6 @@ constexpr auto kCpplibVer = 0; ...@@ -440,24 +440,6 @@ constexpr auto kCpplibVer = 0;
#endif #endif
} // namespace folly } // 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: // MSVC does not permit:
// //
// extern int const num; // extern int const num;
...@@ -471,19 +453,9 @@ constexpr auto kCpplibVer = 0; ...@@ -471,19 +453,9 @@ constexpr auto kCpplibVer = 0;
// True as of MSVC 2017. // True as of MSVC 2017.
#if _MSC_VER #if _MSC_VER
#define FOLLY_STORAGE_CONSTEXPR #define FOLLY_STORAGE_CONSTEXPR
#define FOLLY_STORAGE_CPP14_CONSTEXPR
#else
#if __ICC
#define FOLLY_STORAGE_CONSTEXPR
#else #else
#define FOLLY_STORAGE_CONSTEXPR constexpr #define FOLLY_STORAGE_CONSTEXPR constexpr
#endif #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>) #if __cpp_coroutines >= 201703L && __has_include(<experimental/coroutine>)
#define FOLLY_HAS_COROUTINES 1 #define FOLLY_HAS_COROUTINES 1
......
...@@ -439,7 +439,7 @@ class alignas(T) Replaceable ...@@ -439,7 +439,7 @@ class alignas(T) Replaceable
template < template <
class... Args, class... Args,
std::enable_if_t<std::is_constructible<T, Args&&...>::value, int> = 0> 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 // clang-format off
noexcept(std::is_nothrow_constructible<T, Args&&...>::value) noexcept(std::is_nothrow_constructible<T, Args&&...>::value)
// clang-format on // clang-format on
...@@ -453,7 +453,7 @@ class alignas(T) Replaceable ...@@ -453,7 +453,7 @@ class alignas(T) Replaceable
std::enable_if_t< std::enable_if_t<
std::is_constructible<T, std::initializer_list<U>, Args&&...>::value, std::is_constructible<T, std::initializer_list<U>, Args&&...>::value,
int> = 0> int> = 0>
FOLLY_CPP14_CONSTEXPR explicit Replaceable( constexpr explicit Replaceable(
in_place_t, in_place_t,
std::initializer_list<U> il, std::initializer_list<U> il,
Args&&... args) Args&&... args)
...@@ -475,7 +475,7 @@ class alignas(T) Replaceable ...@@ -475,7 +475,7 @@ class alignas(T) Replaceable
!std::is_same<Replaceable<T>, std::decay_t<U>>::value && !std::is_same<Replaceable<T>, std::decay_t<U>>::value &&
std::is_convertible<U&&, T>::value, std::is_convertible<U&&, T>::value,
int> = 0> int> = 0>
FOLLY_CPP14_CONSTEXPR /* implicit */ Replaceable(U&& other) constexpr /* implicit */ Replaceable(U&& other)
// clang-format off // clang-format off
noexcept(std::is_nothrow_constructible<T, U&&>::value) noexcept(std::is_nothrow_constructible<T, U&&>::value)
// clang-format on // clang-format on
...@@ -491,7 +491,7 @@ class alignas(T) Replaceable ...@@ -491,7 +491,7 @@ class alignas(T) Replaceable
!std::is_same<Replaceable<T>, std::decay_t<U>>::value && !std::is_same<Replaceable<T>, std::decay_t<U>>::value &&
!std::is_convertible<U&&, T>::value, !std::is_convertible<U&&, T>::value,
int> = 0> int> = 0>
FOLLY_CPP14_CONSTEXPR explicit Replaceable(U&& other) constexpr explicit Replaceable(U&& other)
// clang-format off // clang-format off
noexcept(std::is_nothrow_constructible<T, U&&>::value) noexcept(std::is_nothrow_constructible<T, U&&>::value)
// clang-format on // clang-format on
...@@ -611,7 +611,7 @@ class alignas(T) Replaceable ...@@ -611,7 +611,7 @@ class alignas(T) Replaceable
return launder(reinterpret_cast<T const*>(storage_)); return launder(reinterpret_cast<T const*>(storage_));
} }
FOLLY_CPP14_CONSTEXPR T* operator->() { constexpr T* operator->() {
return launder(reinterpret_cast<T*>(storage_)); return launder(reinterpret_cast<T*>(storage_));
} }
...@@ -619,11 +619,11 @@ class alignas(T) Replaceable ...@@ -619,11 +619,11 @@ class alignas(T) Replaceable
return *launder(reinterpret_cast<T const*>(storage_)); return *launder(reinterpret_cast<T const*>(storage_));
} }
FOLLY_CPP14_CONSTEXPR T& operator*() & { constexpr T& operator*() & {
return *launder(reinterpret_cast<T*>(storage_)); return *launder(reinterpret_cast<T*>(storage_));
} }
FOLLY_CPP14_CONSTEXPR T&& operator*() && { constexpr T&& operator*() && {
return std::move(*launder(reinterpret_cast<T*>(storage_))); return std::move(*launder(reinterpret_cast<T*>(storage_)));
} }
......
...@@ -313,7 +313,7 @@ decltype(auto) fetch_impl(RangeTag, Sequence&& sequence, Index&& index) { ...@@ -313,7 +313,7 @@ decltype(auto) fetch_impl(RangeTag, Sequence&& sequence, Index&& index) {
} // namespace for_each_detail } // namespace for_each_detail
template <typename Sequence, typename Func> 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; namespace fed = for_each_detail;
using tag = fed::SequenceTag<Sequence>; using tag = fed::SequenceTag<Sequence>;
fed::for_each_impl(tag{}, std::forward<Sequence>(sequence), func); fed::for_each_impl(tag{}, std::forward<Sequence>(sequence), func);
...@@ -321,7 +321,7 @@ FOLLY_CPP14_CONSTEXPR Func for_each(Sequence&& sequence, Func func) { ...@@ -321,7 +321,7 @@ FOLLY_CPP14_CONSTEXPR Func for_each(Sequence&& sequence, Func func) {
} }
template <typename Sequence, typename Index> 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; namespace fed = for_each_detail;
using tag = fed::SequenceTag<Sequence>; using tag = fed::SequenceTag<Sequence>;
return for_each_detail::fetch_impl( return for_each_detail::fetch_impl(
......
...@@ -83,7 +83,7 @@ namespace folly { ...@@ -83,7 +83,7 @@ namespace folly {
* }); * });
*/ */
template <typename Range, typename Func> 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 * The user should return loop_break and loop_continue if they want to iterate
...@@ -119,7 +119,7 @@ constexpr auto loop_continue = for_each_detail::LoopControl::CONTINUE; ...@@ -119,7 +119,7 @@ constexpr auto loop_continue = for_each_detail::LoopControl::CONTINUE;
* required element. * required element.
*/ */
template <typename Sequence, typename Index> 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 } // namespace folly
......
...@@ -64,7 +64,7 @@ class propagate_const { ...@@ -64,7 +64,7 @@ class propagate_const {
std::remove_reference_t<decltype(*std::declval<Pointer&>())>; std::remove_reference_t<decltype(*std::declval<Pointer&>())>;
constexpr propagate_const() = default; constexpr propagate_const() = default;
FOLLY_CPP14_CONSTEXPR propagate_const(propagate_const&&) = default; constexpr propagate_const(propagate_const&&) = default;
propagate_const(propagate_const const&) = delete; propagate_const(propagate_const const&) = delete;
template < template <
...@@ -105,15 +105,14 @@ class propagate_const { ...@@ -105,15 +105,14 @@ class propagate_const {
constexpr propagate_const(OtherPointer&& other) constexpr propagate_const(OtherPointer&& other)
: pointer_(static_cast<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; propagate_const& operator=(propagate_const const&) = delete;
template < template <
typename OtherPointer, typename OtherPointer,
typename = typename =
std::enable_if_t<std::is_convertible<OtherPointer&&, Pointer>::value>> std::enable_if_t<std::is_convertible<OtherPointer&&, Pointer>::value>>
FOLLY_CPP14_CONSTEXPR propagate_const& operator=( constexpr propagate_const& operator=(propagate_const<OtherPointer>&& other) {
propagate_const<OtherPointer>&& other) {
pointer_ = static_cast<OtherPointer&&>(other.pointer_); pointer_ = static_cast<OtherPointer&&>(other.pointer_);
} }
...@@ -122,19 +121,19 @@ class propagate_const { ...@@ -122,19 +121,19 @@ class propagate_const {
typename = std::enable_if_t< typename = std::enable_if_t<
!detail::is_decay_propagate_const<OtherPointer>::value && !detail::is_decay_propagate_const<OtherPointer>::value &&
std::is_convertible<OtherPointer&&, Pointer>::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); pointer_ = static_cast<OtherPointer&&>(other);
return *this; 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( noexcept(detail::propagate_const_adl::adl_swap(
std::declval<Pointer&>(), std::declval<Pointer&>(),
other.pointer_))) { other.pointer_))) {
detail::propagate_const_adl::adl_swap(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_); return get_(pointer_);
} }
...@@ -146,7 +145,7 @@ class propagate_const { ...@@ -146,7 +145,7 @@ class propagate_const {
return static_cast<bool>(pointer_); return static_cast<bool>(pointer_);
} }
FOLLY_CPP14_CONSTEXPR element_type& operator*() { constexpr element_type& operator*() {
return *get(); return *get();
} }
...@@ -154,7 +153,7 @@ class propagate_const { ...@@ -154,7 +153,7 @@ class propagate_const {
return *get(); return *get();
} }
FOLLY_CPP14_CONSTEXPR element_type* operator->() { constexpr element_type* operator->() {
return get(); return get();
} }
...@@ -167,7 +166,7 @@ class propagate_const { ...@@ -167,7 +166,7 @@ class propagate_const {
typename = std::enable_if_t< typename = std::enable_if_t<
std::is_pointer<OtherPointer>::value || std::is_pointer<OtherPointer>::value ||
std::is_convertible<OtherPointer, element_type*>::value>> std::is_convertible<OtherPointer, element_type*>::value>>
FOLLY_CPP14_CONSTEXPR operator element_type*() { constexpr operator element_type*() {
return get(); return get();
} }
...@@ -199,7 +198,7 @@ class propagate_const { ...@@ -199,7 +198,7 @@ class propagate_const {
}; };
template <typename Pointer> template <typename Pointer>
FOLLY_CPP14_CONSTEXPR void swap( constexpr void swap(
propagate_const<Pointer>& a, propagate_const<Pointer>& a,
propagate_const<Pointer>& b) noexcept(noexcept(a.swap(b))) { propagate_const<Pointer>& b) noexcept(noexcept(a.swap(b))) {
a.swap(b); a.swap(b);
......
...@@ -159,7 +159,6 @@ TEST(FixedStringConcatTest, FromTwoStrings) { ...@@ -159,7 +159,6 @@ TEST(FixedStringConcatTest, FromTwoStrings) {
static_assert(res == "hello world!!!", ""); static_assert(res == "hello world!!!", "");
} }
#if FOLLY_USE_CPP14_CONSTEXPR
constexpr folly::FixedString<20> constexpr_swap_test() { constexpr folly::FixedString<20> constexpr_swap_test() {
folly::FixedString<10> tmp1{"hello"}, tmp2{"world!"}; folly::FixedString<10> tmp1{"hello"}, tmp2{"world!"};
tmp2.swap(tmp1); tmp2.swap(tmp1);
...@@ -169,7 +168,6 @@ constexpr folly::FixedString<20> constexpr_swap_test() { ...@@ -169,7 +168,6 @@ constexpr folly::FixedString<20> constexpr_swap_test() {
TEST(FixedStringSwapTest, ConstexprSwap) { TEST(FixedStringSwapTest, ConstexprSwap) {
static_assert(constexpr_swap_test() == "world!hello", ""); static_assert(constexpr_swap_test() == "world!hello", "");
} }
#endif
TEST(FixedStringSwapTest, RuntimeSwap) { TEST(FixedStringSwapTest, RuntimeSwap) {
folly::FixedString<10> tmp1{"hello"}, tmp2{"world!"}; folly::FixedString<10> tmp1{"hello"}, tmp2{"world!"};
...@@ -177,7 +175,6 @@ TEST(FixedStringSwapTest, RuntimeSwap) { ...@@ -177,7 +175,6 @@ TEST(FixedStringSwapTest, RuntimeSwap) {
EXPECT_STREQ((tmp1 + tmp2).c_str(), "world!hello"); EXPECT_STREQ((tmp1 + tmp2).c_str(), "world!hello");
} }
#if FOLLY_USE_CPP14_CONSTEXPR
constexpr folly::FixedString<10> constexpr_assign_string_test_1() { constexpr folly::FixedString<10> constexpr_assign_string_test_1() {
folly::FixedString<10> tmp1, tmp2{"world!"}; folly::FixedString<10> tmp1, tmp2{"world!"};
tmp1 = tmp2; tmp1 = tmp2;
...@@ -205,7 +202,6 @@ TEST(FixedStringAssignTest, ConstexprAssignString) { ...@@ -205,7 +202,6 @@ TEST(FixedStringAssignTest, ConstexprAssignString) {
static_assert(constexpr_assign_string_test_3() == "db", ""); static_assert(constexpr_assign_string_test_3() == "db", "");
static_assert(constexpr_assign_string_test_4() == "dbye", ""); static_assert(constexpr_assign_string_test_4() == "dbye", "");
} }
#endif
TEST(FixedStringAssignTest, RuntimeAssignString) { TEST(FixedStringAssignTest, RuntimeAssignString) {
folly::FixedString<10> tmp1, tmp2{"world!"}; folly::FixedString<10> tmp1, tmp2{"world!"};
...@@ -219,7 +215,6 @@ TEST(FixedStringAssignTest, RuntimeAssignString) { ...@@ -219,7 +215,6 @@ TEST(FixedStringAssignTest, RuntimeAssignString) {
EXPECT_STREQ("dby", tmp1.c_str()); EXPECT_STREQ("dby", tmp1.c_str());
} }
#if FOLLY_USE_CPP14_CONSTEXPR
constexpr folly::FixedString<10> constexpr_assign_literal_test_1() { constexpr folly::FixedString<10> constexpr_assign_literal_test_1() {
folly::FixedString<10> tmp{"aaaaaaaaaa"}; folly::FixedString<10> tmp{"aaaaaaaaaa"};
tmp = "hello"; tmp = "hello";
...@@ -244,7 +239,6 @@ TEST(FixedStringAssignTest, ConstexprAssignLiteral) { ...@@ -244,7 +239,6 @@ TEST(FixedStringAssignTest, ConstexprAssignLiteral) {
static_assert(constexpr_assign_literal_test_2() == "hello", ""); static_assert(constexpr_assign_literal_test_2() == "hello", "");
static_assert(constexpr_assign_literal_test_3() == "good", ""); static_assert(constexpr_assign_literal_test_3() == "good", "");
} }
#endif
TEST(FixedStringAssignTest, RuntimeAssignLiteral) { TEST(FixedStringAssignTest, RuntimeAssignLiteral) {
folly::FixedString<10> tmp{"aaaaaaaaaa"}; folly::FixedString<10> tmp{"aaaaaaaaaa"};
...@@ -333,7 +327,6 @@ TEST(FixedStringCompareTest, CompareStdString) { ...@@ -333,7 +327,6 @@ TEST(FixedStringCompareTest, CompareStdString) {
EXPECT_TRUE(tmp2 >= tmp1); EXPECT_TRUE(tmp2 >= tmp1);
} }
#if FOLLY_USE_CPP14_CONSTEXPR
constexpr folly::FixedString<20> constexpr_append_string_test() { constexpr folly::FixedString<20> constexpr_append_string_test() {
folly::FixedString<20> a{"hello"}, b{"X world!"}; folly::FixedString<20> a{"hello"}, b{"X world!"};
a.append(1u, ' '); a.append(1u, ' ');
...@@ -345,7 +338,6 @@ constexpr folly::FixedString<20> constexpr_append_string_test() { ...@@ -345,7 +338,6 @@ constexpr folly::FixedString<20> constexpr_append_string_test() {
TEST(FixedStringAssignTest, ConstexprAppendString) { TEST(FixedStringAssignTest, ConstexprAppendString) {
static_assert(constexpr_append_string_test() == "hello world!", ""); static_assert(constexpr_append_string_test() == "hello world!", "");
} }
#endif
TEST(FixedStringAssignTest, RuntimeAppendString) { TEST(FixedStringAssignTest, RuntimeAppendString) {
folly::FixedString<20> a{"hello"}, b{"X world!"}; folly::FixedString<20> a{"hello"}, b{"X world!"};
...@@ -355,7 +347,6 @@ TEST(FixedStringAssignTest, RuntimeAppendString) { ...@@ -355,7 +347,6 @@ TEST(FixedStringAssignTest, RuntimeAppendString) {
EXPECT_STREQ("hello world!", a.c_str()); EXPECT_STREQ("hello world!", a.c_str());
} }
#if FOLLY_USE_CPP14_CONSTEXPR
constexpr folly::FixedString<20> constexpr_append_literal_test() { constexpr folly::FixedString<20> constexpr_append_literal_test() {
folly::FixedString<20> a{"hello"}; folly::FixedString<20> a{"hello"};
a.append(1u, ' '); a.append(1u, ' ');
...@@ -367,7 +358,6 @@ constexpr folly::FixedString<20> constexpr_append_literal_test() { ...@@ -367,7 +358,6 @@ constexpr folly::FixedString<20> constexpr_append_literal_test() {
TEST(FixedStringAssignTest, ConstexprAppendLiteral) { TEST(FixedStringAssignTest, ConstexprAppendLiteral) {
static_assert(constexpr_append_literal_test() == "hello world!", ""); static_assert(constexpr_append_literal_test() == "hello world!", "");
} }
#endif
TEST(FixedStringAssignTest, RuntimeAppendLiteral) { TEST(FixedStringAssignTest, RuntimeAppendLiteral) {
folly::FixedString<20> a{"hello"}; folly::FixedString<20> a{"hello"};
...@@ -393,7 +383,6 @@ TEST(FixedStringCAppendTest, CAppendLiteral) { ...@@ -393,7 +383,6 @@ TEST(FixedStringCAppendTest, CAppendLiteral) {
static_assert(tmp3 == "hello world!", ""); static_assert(tmp3 == "hello world!", "");
} }
#if FOLLY_USE_CPP14_CONSTEXPR
constexpr folly::FixedString<10> constexpr_replace_string_test() { constexpr folly::FixedString<10> constexpr_replace_string_test() {
folly::FixedString<10> tmp{"abcdefghij"}; folly::FixedString<10> tmp{"abcdefghij"};
tmp.replace(1, 5, FS("XX")); tmp.replace(1, 5, FS("XX"));
...@@ -404,7 +393,6 @@ TEST(FixedStringReplaceTest, ConstexprReplaceString) { ...@@ -404,7 +393,6 @@ TEST(FixedStringReplaceTest, ConstexprReplaceString) {
static_assert(constexpr_replace_string_test().size() == 7u, ""); static_assert(constexpr_replace_string_test().size() == 7u, "");
static_assert(constexpr_replace_string_test() == "aXXghij", ""); static_assert(constexpr_replace_string_test() == "aXXghij", "");
} }
#endif
TEST(FixedStringReplaceTest, RuntimeReplaceString) { TEST(FixedStringReplaceTest, RuntimeReplaceString) {
folly::FixedString<10> tmp{"abcdefghij"}; folly::FixedString<10> tmp{"abcdefghij"};
...@@ -637,7 +625,6 @@ TEST(FixedStringConversionTest, ConversionToStdString) { ...@@ -637,7 +625,6 @@ TEST(FixedStringConversionTest, ConversionToStdString) {
EXPECT_STREQ("another string", str.c_str()); EXPECT_STREQ("another string", str.c_str());
} }
#if FOLLY_USE_CPP14_CONSTEXPR
constexpr std::size_t countSpacesReverse(folly::FixedString<50> s) { constexpr std::size_t countSpacesReverse(folly::FixedString<50> s) {
std::size_t count = 0u; std::size_t count = 0u;
auto i = s.rbegin(); auto i = s.rbegin();
...@@ -652,7 +639,6 @@ constexpr std::size_t countSpacesReverse(folly::FixedString<50> s) { ...@@ -652,7 +639,6 @@ constexpr std::size_t countSpacesReverse(folly::FixedString<50> s) {
TEST(FixedStringReverseIteratorTest, Cpp14ConstexprReverseIteration) { TEST(FixedStringReverseIteratorTest, Cpp14ConstexprReverseIteration) {
static_assert(3 == countSpacesReverse("This is a string"), ""); static_assert(3 == countSpacesReverse("This is a string"), "");
} }
#endif
TEST(FixedStringReverseIteratorTest, ConstexprReverseIteration) { TEST(FixedStringReverseIteratorTest, ConstexprReverseIteration) {
static constexpr auto alpha = FS("abcdefghijklmnopqrstuvwxyz"); static constexpr auto alpha = FS("abcdefghijklmnopqrstuvwxyz");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment