Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
enable_borrowed_range.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_RANGES_ENABLE_BORROWED_RANGE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_RANGES_ENABLE_BORROWED_RANGE_HPP_
7
8// IWYU pragma: private, include "arene/base/ranges.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11#include "arene/base/stdlib_choice/integral_constant.hpp"
12
13namespace arene {
14namespace base {
15namespace ranges {
16
17/// @brief An opt-in trait to indicate that a range type is a borrowed range.
18///
19/// @tparam Rng The range type to check.
20///
21/// A borrowed range is a range whose iterators remain valid even after the range object is destroyed: for example
22/// @c arene::base::span and @c arene::base::string_view are borrowed ranges, while @c arene::base::inline_vector and
23/// @c arene::base::inline_string are not.
24///
25/// Users may specialize @c enable_borrowed_range for their range types to indicate that they are borrowed ranges by
26/// providing a static @c value member of type @c bool which indicates if the range type is a borrowed range or not
27/// (typically by inheriting from @c std::true_type if it is unconditional). The default specialization is @c false .
28///
29/// \snippet docs/examples/subpackages/ranges/type_traits_examples.cpp specialize_borrowed_range
30template <typename Rng>
32
33template <typename Rng>
34/// @brief Query if a range type has opted into being a borrowed range.
35///
36/// @tparam Rng The range type to check.
37/// @return bool Equivalent to @c enable_borrowed_range<Rng>::value .
38/// @note Users should generally not query @c enable_borrowed_range_v directly; it is intended for use by the range
39/// library to detect @c enable_borrowed_range customizations, and should only be used for that purpose. Instead, use
40/// @c arene::base::is_borrowed_range_v<Rng> to query if a type qualifies as a borrowed range when implementing generic
41/// algorithms.
43
44} // namespace ranges
45} // namespace base
46} // namespace arene
47
48#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_RANGES_ENABLE_BORROWED_RANGE_HPP_
An opt-in trait to indicate that a range type is a borrowed range.
Definition enable_borrowed_range.hpp:31
static constexpr value_type value
Definition integral_constant.hpp:34
Definition external_vector.hpp:803
constexpr bool enable_borrowed_range_v
Query if a range type has opted into being a borrowed range.
Definition accumulate.hpp:37
Definition accumulate.hpp:36
bool_constant< false > false_type
An alias for bool_constant<false>
Definition integral_constant.hpp:79