GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::ranges::cdata(3) C++ Standard Libary std::ranges::cdata(3)

std::ranges::cdata - std::ranges::cdata


Defined in header <ranges>
inline namespace /*unspecified*/ {
(since C++20)
inline constexpr /*unspecified*/ cdata = /*unspecified*/; (customization
point object)
}
Call signature
template< class T >


requires /* see below */
(since C++20)
constexpr
std::remove_reference_t<ranges::range_reference_t</*CT*/>>* cdata(
T&& t );


Returns a pointer to the first element of a contiguous range denoted by a
const-qualified argument.


Let CT be


1. const std::remove_reference_t<T>& if the argument is an lvalue (i.e. T is an
lvalue reference type),
2. const T otherwise,


a call to ranges::cdata is expression-equivalent to
ranges::data(static_cast<CT&&>(t)).


If ranges::cdata(t) is valid, then it returns a pointer to a object.


Expression-equivalent


Expression e is expression-equivalent to expression f, if


* e and f have the same effects, and
* either both are constant subexpressions or else neither is a constant
subexpression, and
* either both are potentially-throwing or else neither is potentially-throwing
(i.e. noexcept(e) == noexcept(f)).


Customization point objects


The name ranges::cdata denotes a customization point object, which is a const
function object of a literal semiregular class type. For exposition purposes, the
cv-unqualified version of its type is denoted as __cdata_fn.


All instances of __cdata_fn are equal. The effects of invoking different instances
of type __cdata_fn on the same arguments are equivalent, regardless of whether the
expression denoting the instance is an lvalue or rvalue, and is const-qualified or
not (however, a volatile-qualified instance is not required to be invocable). Thus,
ranges::cdata can be copied freely and its copies can be used interchangeably.


Given a set of types Args..., if std::declval<Args>()... meet the requirements for
arguments to ranges::cdata above, __cdata_fn models


* std::invocable<__cdata_fn, Args...>,
* std::invocable<const __cdata_fn, Args...>,
* std::invocable<__cdata_fn&, Args...>, and
* std::invocable<const __cdata_fn&, Args...>.


Otherwise, no function call operator of __cdata_fn participates in overload
resolution.

// Run this code


#include <cstring>
#include <iostream>
#include <ranges>
#include <string>


int main()
{
std::string src {"hello world!\n"};


// std::ranges::cdata(src)[0] = 'H'; // error, src.data() is treated as read-only
std::ranges::data(src)[0] = 'H'; // OK, src.data() is a non-const storage


char dst[20]; // storage for a C-style string
std::strcpy(dst, std::ranges::cdata(src));
// [data(src), data(src) + size(src)] is guaranteed to be an NTBS


std::cout << dst;
}


Hello world!


ranges::data obtains a pointer to the beginning of a contiguous range
(C++20) (customization point object)
data obtains the pointer to the underlying array
(C++17) (function template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.