Fix compile in C++20 mode.

* std::result_of is deprecated; switch to std::invoke_result
* Add use of std::string_view::(starts,ends)_with as appropriate
  (see https://issuetracker.google.com/issues/253467211 )

Test: Compiles with -std=c++20
Signed-off-by: Peter Kasting <pkasting@chromium.org>
Change-Id: I8b6bf79b3fb663e2151145cc1eec260fd3e2e2b4
diff --git a/libartbase/base/safe_map.h b/libartbase/base/safe_map.h
index 7ae85d4..c6d4353 100644
--- a/libartbase/base/safe_map.h
+++ b/libartbase/base/safe_map.h
@@ -149,7 +149,7 @@
 
   template <typename CreateFn>
   V& GetOrCreate(const K& k, CreateFn create) {
-    static_assert(std::is_same_v<V, std::result_of_t<CreateFn()>>,
+    static_assert(std::is_same_v<V, std::invoke_result_t<CreateFn>>,
                   "Argument `create` should return a value of type V.");
     auto lb = lower_bound(k);
     if (lb != end() && !key_comp()(k, lb->first)) {
diff --git a/libartbase/base/string_view_cpp20.h b/libartbase/base/string_view_cpp20.h
index 2c11a2f..9bd29d5 100644
--- a/libartbase/base/string_view_cpp20.h
+++ b/libartbase/base/string_view_cpp20.h
@@ -21,18 +21,23 @@
 
 namespace art {
 
-// Replacement functions for std::string_view::starts_with(), ends_with()
-// which shall be available in C++20.
-#if __cplusplus >= 202000L
-#error "When upgrading to C++20, remove this error and file a bug to remove this workaround."
-#endif
+// When this code is only compiled on C++20+, these wrappers can be removed and
+// calling code changed to call the string_view methods directly.
 
 inline bool StartsWith(std::string_view sv, std::string_view prefix) {
+#if !defined(__cpp_lib_starts_ends_with) || __cpp_lib_starts_ends_with < 201711L
   return sv.substr(0u, prefix.size()) == prefix;
+#else
+  return sv.starts_with(prefix);
+#endif
 }
 
 inline bool EndsWith(std::string_view sv, std::string_view suffix) {
+#if !defined(__cpp_lib_starts_ends_with) || __cpp_lib_starts_ends_with < 201711L
   return sv.size() >= suffix.size() && sv.substr(sv.size() - suffix.size()) == suffix;
+#else
+  return sv.ends_with(suffix);
+#endif
 }
 
 }  // namespace art