std::experi...erence_type(3)
π NAME π
std::experimental::ranges::difference_type β std::experimental::ranges::difference_type, bestie. We're deep in the C++ Standard Libary manual (yes, βLibaryβ is literally how it's spelled in the header, don't come for me π), and the title up top is all truncated like std::experi...erence_type(3). Anyway, this whole page is about that one template. Periodt.
π¦ Synopsis π¦
Defined in header <experimental/ranges/iterator>:
template< class I >
(1)
struct difference_type {};
template< class T >
(2)
struct difference_type<T*>;
template< class T >
(3)
struct difference_type<const T> : difference_type<std::decay_t<T>>
{};
template< class T >
requires requires { typename T::difference_type; }
(4)
struct difference_type<T>;
template< class T >
requires !requires { typename T::difference_type; } &&
(5)
requires(const T& a, const T& b) { {a - b} -> Integral;
}
struct difference_type<T>;
So it computes the associated difference type of the type I, if any. Users may specialize difference_type for a program-defined type. Slay.
Here's the full breakdown, no skipping:
- Primary template is an empty struct. π
- Specialization for pointers. If
Tis an object type, provides a member typetypeequal tostd::ptrdiff_t. Otherwise, there is no member type. No cap. - Specialization for const-qualified types. Simple, iconic.
- Specialization for types that define a public and accessible member type
difference_type. Provides a member typetypeequal toT::difference_type. - Specialization for types that do not define a public and accessible member type
difference_typebut do support subtraction. Provides a member typetypeequal tostd::make_signed_t<decltype(std::declval<T>() - std::declval<T>())>. The way this is so specific π
β¨ Helper alias template β¨
template< class T >
(ranges TS)
using difference_type_t = typename ranges::difference_type<T>::type;
That's the (ranges TS) cutie right there. Obsessed.
π Example π
This section is incomplete π
Reason: no example.
π See also π
WeaklyIncrementable(concept) β specifies that aSemiregulartype can be incremented with pre- and post-increment operators. Iconic.iterator_traits(alias template) β compatibility traits class that collects an iteratorβs associated types. We love a compatibility queen.
π Category π
Category: * Todo no example
Mwah π β sourced from http://cppreference.com, dated 2024.06.10, and the footer still says std::experi...erence_type(3). Stay slaying, bestie π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms