summaryrefslogtreecommitdiff
path: root/include/o3tl/array_view.hxx
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/array_view.hxx
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/array_view.hxx')
-rw-r--r--include/o3tl/array_view.hxx36
1 files changed, 6 insertions, 30 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: */