xref: /aosp_15_r20/external/pigweed/pw_span/public/pw_span/span.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 // pw::span is an implementation of std::span for C++17 or newer. The
16 // implementation is shared with the std::span polyfill class.
17 #pragma once
18 
19 #include "pw_span/internal/config.h"
20 
21 #if __has_include(<version>)
22 #include <version>
23 #endif  // __has_include(<version>)
24 
25 // If the C++ library fully supports <span>, pw::span is an alias of std::span,
26 // but only if PW_SPAN_ENABLE_ASSERTS is not enabled.
27 #if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L && \
28     !PW_SPAN_ENABLE_ASSERTS
29 
30 #include <span>
31 
32 namespace pw {
33 
34 using std::as_bytes;
35 using std::as_writable_bytes;
36 using std::dynamic_extent;
37 using std::span;
38 
39 }  // namespace pw
40 
41 #else
42 
43 // If std::span is not available, use Pigweed's span implementation.
44 #include "pw_span/internal/span_impl.h"  // IWYU pragma: export
45 
46 #endif  // defined(__cpp_lib_span) && __cpp_lib_span >= 202002L
47