DPC++ Runtime
Runtime libraries for oneAPI DPC++
string_view.hpp
Go to the documentation of this file.
1 //==-------------- string_view.hpp - SYCL standard header file -------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <string>
10 
11 #pragma once
12 
13 namespace sycl {
14 inline namespace _V1 {
15 namespace detail {
16 
17 // This class and detail::string class are intended to support
18 // different ABIs between libsycl and the user program.
19 // This class is not inteded to replace std::string_view for general purpose
20 // usage.
21 class string_view {
22  const char *str = nullptr;
23 
24 public:
25  string_view() noexcept = default;
26  string_view(const string_view &strn) noexcept = default;
27  string_view(string_view &&strn) noexcept = default;
28  string_view(std::string_view strn) noexcept : str(strn.data()) {}
29 
31  string_view &operator=(const string_view &strn) noexcept = default;
32 
33  string_view &operator=(std::string_view strn) noexcept {
34  str = strn.data();
35  return *this;
36  }
37 
38  const char *data() const noexcept { return str; }
39 
40  friend bool operator==(const string_view &lhs,
41  std::string_view rhs) noexcept {
42  return rhs == lhs.data();
43  }
44  friend bool operator==(std::string_view lhs,
45  const string_view &rhs) noexcept {
46  return lhs == rhs.data();
47  }
48 };
49 
50 } // namespace detail
51 } // namespace _V1
52 } // namespace sycl
const char * data() const noexcept
Definition: string_view.hpp:38
string_view & operator=(string_view &&strn) noexcept=default
string_view & operator=(std::string_view strn) noexcept
Definition: string_view.hpp:33
friend bool operator==(const string_view &lhs, std::string_view rhs) noexcept
Definition: string_view.hpp:40
string_view() noexcept=default
string_view & operator=(const string_view &strn) noexcept=default
friend bool operator==(std::string_view lhs, const string_view &rhs) noexcept
Definition: string_view.hpp:44
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324