summaryrefslogtreecommitdiff
path: root/include/o3tl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-12-07 11:37:24 +0100
committerStephan Bergmann <sbergman@redhat.com>2018-12-07 22:46:49 +0100
commit7d928d8c6eb03c4e5e0d1961e9b62718ab53fb46 (patch)
tree43e827f3debcf3cfbc2c101c10ed2043bc880d9a /include/o3tl
parent74dd206e67c2efb1e56d817be9e42a1ed82e3239 (diff)
HAVE_CXX14_CONSTEXPR is always true now
...but for safety, leave the configure.ac check in for some longer. o3tl::array_view::max_size (include/o3tl/array_view.hxx) and o3tl::basic_string_view::max_size (include/o3tl/string_view.hxx) started to produce loplugin:staticmethods warnings, which I silenced by /not/ making the functions static. Those classes are meant to be temporary drop-in replacements for standard classes (std::span slated for C++20, prev. std::array_view; and std::basic_string_view, resp.), so should have the same behavior as their standard counterparts (and making the functions static would likely cause loplugin:staticaccess warnings at call sites). Change-Id: If21674dbf02886f453ca447544e37b184df5a25e Reviewed-on: https://gerrit.libreoffice.org/64768 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/o3tl')
-rw-r--r--include/o3tl/array_view.hxx36
-rw-r--r--include/o3tl/clamp.hxx4
-rw-r--r--include/o3tl/string_view.hxx81
-rw-r--r--include/o3tl/strong_int.hxx6
-rw-r--r--include/o3tl/typed_flags_set.hxx23
5 files changed, 23 insertions, 127 deletions
diff --git a/include/o3tl/array_view.hxx b/include/o3tl/array_view.hxx
index 563821a46f6d..dd6ca7fa94c0 100644
--- a/include/o3tl/array_view.hxx
+++ b/include/o3tl/array_view.hxx
@@ -22,17 +22,10 @@
#include <type_traits>
#include <utility>
-#include <config_global.h>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
#include <sal/types.h>
-#if HAVE_CXX14_CONSTEXPR
-#define CONSTEXPR constexpr
-#else
-#define CONSTEXPR
-#endif
-
namespace o3tl {
#if defined _MSC_VER
@@ -64,15 +57,13 @@ public:
constexpr array_view() noexcept : data_(nullptr), size_(0) {}
template<size_type N>
- CONSTEXPR array_view (T (&a)[N]) noexcept : data_(a), size_(N) {}
+ constexpr array_view (T (&a)[N]) noexcept : data_(a), size_(N) {}
- CONSTEXPR array_view (T *a, size_type len) noexcept
+ constexpr array_view (T *a, size_type len) noexcept
: data_(a), size_(len)
{
-#if HAVE_CXX14_CONSTEXPR
// not terribly sure about this, might need to relax it
assert((a == nullptr && len == 0) || (a != nullptr && len > 0));
-#endif
}
/// Allow for assigning array_view<T> to array_view<T const> i.e.
@@ -106,25 +97,17 @@ public:
constexpr size_type size() const noexcept { return size_; }
constexpr size_type length() const noexcept { return size(); }
-#if !defined __clang__ || HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- size_type max_size() const noexcept {
-#if defined __clang__ // avoid constexpr issues with other, older compilers
- (void) this; // loplugin:staticmethods
-#endif
+ constexpr size_type max_size() const noexcept {
+ (void) this; // silence loplugin:staticmethods
return npos - 1;
}
constexpr reference operator [](size_type pos) const {
-#if HAVE_CXX14_CONSTEXPR
assert(pos < size());
-#endif
return data_[pos];
}
- CONSTEXPR
- reference at(size_type pos) const {
+ constexpr reference at(size_type pos) const {
if (pos >= size()) {
throw std::out_of_range("o3tl::array_view::at");
}
@@ -132,22 +115,18 @@ public:
}
constexpr reference front() const {
-#if HAVE_CXX14_CONSTEXPR
assert(!empty());
-#endif
return operator [](0);
}
constexpr reference back() const {
-#if HAVE_CXX14_CONSTEXPR
assert(!empty());
-#endif
return operator [](size() - 1);
}
constexpr pointer data() const noexcept { return data_; }
- CONSTEXPR void swap(array_view & s) noexcept {
+ constexpr void swap(array_view & s) noexcept {
std::swap(data_, s.data_);
std::swap(size_, s.size_);
}
@@ -179,9 +158,6 @@ struct hash<o3tl::array_view<T>> {
} // namespace std
-
-#undef CONSTEXPR
-
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/include/o3tl/clamp.hxx b/include/o3tl/clamp.hxx
index 054de5e22517..06fa22e48cec 100644
--- a/include/o3tl/clamp.hxx
+++ b/include/o3tl/clamp.hxx
@@ -15,8 +15,6 @@
#include <algorithm>
#include <cassert>
-#include <config_global.h>
-
// C++17 std::clamp
namespace o3tl
@@ -29,9 +27,7 @@ using std::clamp;
template <typename T> constexpr const T& clamp(const T& v, const T& lo, const T& hi)
{
-#if HAVE_CXX14_CONSTEXPR
assert(!(hi < lo));
-#endif
return v < lo ? lo : (hi < v ? hi : v);
}
diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 4da7fcf0bf0f..b605da65ac90 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -22,7 +22,6 @@
#include <type_traits>
#include <utility>
-#include <config_global.h>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
#include <sal/types.h>
@@ -174,10 +173,7 @@ public:
constexpr basic_string_view(basic_string_view const &) noexcept = default;
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- basic_string_view & operator =(basic_string_view const & other) noexcept = default;
+ constexpr basic_string_view & operator =(basic_string_view const & other) noexcept = default;
// The various character types are handled below in the "LO specifics, to
// make up for traits::length not necessarily being constexpr yet for
@@ -217,29 +213,19 @@ public:
constexpr size_type length() const noexcept { return size(); }
-#if !defined __clang__ || HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- size_type max_size() const noexcept {
-#if defined __clang__ // avoid constexpr issues with other, older compilers
- (void) this; // loplugin:staticmethods
-#endif
+ constexpr size_type max_size() const noexcept {
+ (void) this; // silence loplugin:staticmethods
return npos - 1;
}
constexpr bool empty() const noexcept { return size_ == 0; }
constexpr const_reference operator [](size_type pos) const {
-#if HAVE_CXX14_CONSTEXPR
assert(pos < size());
-#endif
return data_[pos];
}
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- const_reference at(size_type pos) const {
+ constexpr const_reference at(size_type pos) const {
if (pos >= size()) {
throw std::out_of_range("o3tl::basic_string_view::at");
}
@@ -247,42 +233,29 @@ public:
}
constexpr const_reference front() const {
-#if HAVE_CXX14_CONSTEXPR
assert(!empty());
-#endif
return operator [](0);
}
constexpr const_reference back() const {
-#if HAVE_CXX14_CONSTEXPR
assert(!empty());
-#endif
return operator [](size() - 1);
}
constexpr const_pointer data() const noexcept { return data_; }
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- void remove_prefix(size_type n) {
+ constexpr void remove_prefix(size_type n) {
assert(n <= size());
data_ += n;
size_ -= n;
}
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- void remove_suffix(size_type n) {
+ constexpr void remove_suffix(size_type n) {
assert(n <= size());
size_ -= n;
}
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- void swap(basic_string_view & s) noexcept {
+ constexpr void swap(basic_string_view & s) noexcept {
std::swap(data_, s.data_);
std::swap(size_, s.size_);
}
@@ -296,10 +269,7 @@ public:
return rlen;
}
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- basic_string_view substr(size_type pos = 0, size_type n = npos) const {
+ constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const {
if (pos > size()) {
throw std::out_of_range("o3tl::basic_string_view::copy");
}
@@ -307,10 +277,7 @@ public:
data() + pos, std::min(n, size_type(size() - pos)));
}
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- int compare(basic_string_view s) const noexcept {
+ constexpr int compare(basic_string_view s) const noexcept {
auto n = traits::compare(data(), s.data(), std::min(size(), s.size()));
return n == 0
? (size() < s.size() ? -1 : size() == s.size() ? 0 : 1) : n;
@@ -335,10 +302,7 @@ public:
size_type pos1, size_type n1, charT const * s, size_type n2) const
{ return substr(pos1, n1).compare(basic_string_view(s, n2)); }
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- size_type find(basic_string_view s, size_type pos = 0) const noexcept {
+ constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept {
if (s.size() <= size()) {
for (auto xpos = pos; xpos <= size() - s.size(); ++xpos) {
bool match = true;
@@ -365,10 +329,7 @@ public:
constexpr size_type find(charT const * s, size_type pos = 0) const
{ return find(basic_string_view(s), pos); }
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- size_type rfind(basic_string_view s, size_type pos = npos) const noexcept {
+ constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept {
if (s.size() <= size()) {
for (auto xpos = std::min<size_type>(size() - s.size(), pos);;
--xpos)
@@ -400,10 +361,7 @@ public:
constexpr size_type rfind(charT const * s, size_type pos = npos) const
{ return rfind(basic_string_view(s), pos); }
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- size_type find_first_of(basic_string_view s, size_type pos = 0) const
+ constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const
noexcept
{
for (auto xpos = pos; xpos < size(); ++xpos) {
@@ -426,10 +384,7 @@ public:
constexpr size_type find_first_of(charT const * s, size_type pos = 0) const
{ return find_first_of(basic_string_view(s), pos); }
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- size_type find_last_of(basic_string_view s, size_type pos = npos) const
+ constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const
noexcept
{
if (!empty()) {
@@ -459,10 +414,7 @@ public:
const
{ return find_last_of(basic_string_view(s), pos); }
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- size_type find_first_not_of(basic_string_view s, size_type pos = 0) const
+ constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const
noexcept
{
for (auto xpos = pos; xpos < size(); ++xpos) {
@@ -492,10 +444,7 @@ public:
const
{ return find_first_not_of(basic_string_view(s), pos); }
-#if HAVE_CXX14_CONSTEXPR
- constexpr
-#endif
- size_type find_last_not_of(basic_string_view s, size_type pos = npos) const
+ constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const
noexcept
{
if (!empty()) {
diff --git a/include/o3tl/strong_int.hxx b/include/o3tl/strong_int.hxx
index fb00addfad08..006a36c8900f 100644
--- a/include/o3tl/strong_int.hxx
+++ b/include/o3tl/strong_int.hxx
@@ -25,12 +25,10 @@
#include <cassert>
#include <type_traits>
-#include <config_global.h>
-
namespace o3tl
{
-#if HAVE_CXX14_CONSTEXPR
+#if !defined __COVERITY__
namespace detail {
@@ -90,7 +88,7 @@ public:
typename std::enable_if<std::is_integral<T>::value, int>::type = 0):
m_value(value)
{
-#if !defined __COVERITY__ && HAVE_CXX14_CONSTEXPR
+#if !defined __COVERITY__
// catch attempts to pass in out-of-range values early
assert(detail::isInRange<UNDERLYING_TYPE>(value)
&& "out of range");
diff --git a/include/o3tl/typed_flags_set.hxx b/include/o3tl/typed_flags_set.hxx
index 09f0b61d8c01..188258febc58 100644
--- a/include/o3tl/typed_flags_set.hxx
+++ b/include/o3tl/typed_flags_set.hxx
@@ -25,7 +25,6 @@
#include <cassert>
#include <type_traits>
-#include <config_global.h>
#include <sal/types.h>
namespace o3tl {
@@ -76,14 +75,12 @@ struct is_typed_flags {
explicit constexpr Wrap(typename std::underlying_type<E>::type value):
value_(value)
{
-#if HAVE_CXX14_CONSTEXPR
assert(detail::isNonNegative(value));
assert(
static_cast<typename std::underlying_type<E>::type>(~0) == M
// avoid "operands don't affect result" warnings when M
// covers all bits of the underlying type
|| (value & ~M) == 0);
-#endif
}
constexpr operator E() const { return static_cast<E>(value_); }
@@ -105,11 +102,9 @@ struct is_typed_flags {
template<typename E>
constexpr typename o3tl::typed_flags<E>::Wrap operator ~(E rhs) {
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
o3tl::typed_flags<E>::mask
& ~static_cast<typename std::underlying_type<E>::type>(rhs));
@@ -126,14 +121,12 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ~(
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
E lhs, E rhs)
{
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs)));
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs)
^ static_cast<typename std::underlying_type<E>::type>(rhs));
@@ -142,11 +135,9 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
E lhs, typename o3tl::typed_flags<E>::Wrap rhs)
{
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs)
^ static_cast<typename std::underlying_type<E>::type>(rhs));
@@ -155,11 +146,9 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator ^(
typename o3tl::typed_flags<E>::Wrap lhs, E rhs)
{
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs)
^ static_cast<typename std::underlying_type<E>::type>(rhs));
@@ -180,14 +169,12 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator ^(
template<typename E>
constexpr typename o3tl::typed_flags<E>::Wrap operator &(E lhs, E rhs) {
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs)));
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs)
& static_cast<typename std::underlying_type<E>::type>(rhs));
@@ -196,11 +183,9 @@ constexpr typename o3tl::typed_flags<E>::Wrap operator &(E lhs, E rhs) {
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &(
E lhs, typename o3tl::typed_flags<E>::Wrap rhs)
{
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs)
& static_cast<typename std::underlying_type<E>::type>(rhs));
@@ -209,11 +194,9 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &(
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator &(
typename o3tl::typed_flags<E>::Wrap lhs, E rhs)
{
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs)
& static_cast<typename std::underlying_type<E>::type>(rhs));
@@ -234,14 +217,12 @@ typename o3tl::typed_flags<typename W::Unwrapped::Self>::Wrap operator &(
template<typename E>
constexpr typename o3tl::typed_flags<E>::Wrap operator |(E lhs, E rhs) {
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs)));
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs)
| static_cast<typename std::underlying_type<E>::type>(rhs));
@@ -250,11 +231,9 @@ constexpr typename o3tl::typed_flags<E>::Wrap operator |(E lhs, E rhs) {
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |(
E lhs, typename o3tl::typed_flags<E>::Wrap rhs)
{
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(lhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs)
| static_cast<typename std::underlying_type<E>::type>(rhs));
@@ -263,11 +242,9 @@ template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |(
template<typename E> constexpr typename o3tl::typed_flags<E>::Wrap operator |(
typename o3tl::typed_flags<E>::Wrap lhs, E rhs)
{
-#if HAVE_CXX14_CONSTEXPR
assert(
o3tl::detail::isNonNegative(
static_cast<typename std::underlying_type<E>::type>(rhs)));
-#endif
return static_cast<typename o3tl::typed_flags<E>::Wrap>(
static_cast<typename std::underlying_type<E>::type>(lhs)
| static_cast<typename std::underlying_type<E>::type>(rhs));