Location via proxy:
[ UP ]
[Report a bug]
[Manage cookies]
No cookies
No scripts
No ads
No referrer
Show this form
25
Ranges library
[ranges]
25.7
Range adaptors
[range.adaptors]
25.7.10
Take view
[range.take]
25.7.10.2
Class template
take_
view
[range.take.view]
🔗
namespace
std
::
ranges
{
template
<
view
V
>
class
take_view
:
public
view_interface
<
take_view
<
V
>
>
{
private
:
V
base_
=
V
(
)
;
//
exposition only
range_difference_t
<
V
>
count_
=
0
;
//
exposition only
//
[range.
take.
sentinel]
, class template
take_
view::
sentinel
template
<
bool
>
class
sentinel
;
//
exposition only
public
:
take_view
(
)
requires
default_
initializable
<
V
>
=
default
;
constexpr
explicit
take_view
(
V base, range_difference_t
<
V
>
count
)
;
constexpr
V base
(
)
const
&
requires
copy_
constructible
<
V
>
{
return
base_
;
}
constexpr
V base
(
)
&
&
{
return
std
::
move
(
base_
)
;
}
constexpr
auto
begin
(
)
requires
(
!
simple-view
<
V
>
)
{
if
constexpr
(
sized_
range
<
V
>
)
{
if
constexpr
(
random_
access_
range
<
V
>
)
{
return
ranges
::
begin
(
base_
)
;
}
else
{
auto
sz
=
range_difference_t
<
V
>
(
size
(
)
)
;
return
counted_iterator
(
ranges
::
begin
(
base_
)
, sz
)
;
}
}
else
if
constexpr
(
sized_
sentinel_
for
<
sentinel_t
<
V
>
, iterator_t
<
V
>
>
)
{
auto
it
=
ranges
::
begin
(
base_
)
;
auto
sz
=
std
::
min
(
count_
, ranges
::
end
(
base_
)
-
it
)
;
return
counted_iterator
(
std
::
move
(
it
)
, sz
)
;
}
else
{
return
counted_iterator
(
ranges
::
begin
(
base_
)
,
count_
)
;
}
}
constexpr
auto
begin
(
)
const
requires
range
<
const
V
>
{
if
constexpr
(
sized_
range
<
const
V
>
)
{
if
constexpr
(
random_
access_
range
<
const
V
>
)
{
return
ranges
::
begin
(
base_
)
;
}
else
{
auto
sz
=
range_difference_t
<
const
V
>
(
size
(
)
)
;
return
counted_iterator
(
ranges
::
begin
(
base_
)
, sz
)
;
}
}
else
if
constexpr
(
sized_
sentinel_
for
<
sentinel_t
<
const
V
>
, iterator_t
<
const
V
>
>
)
{
auto
it
=
ranges
::
begin
(
base_
)
;
auto
sz
=
std
::
min
(
count_
, ranges
::
end
(
base_
)
-
it
)
;
return
counted_iterator
(
std
::
move
(
it
)
, sz
)
;
}
else
{
return
counted_iterator
(
ranges
::
begin
(
base_
)
,
count_
)
;
}
}
constexpr
auto
end
(
)
requires
(
!
simple-view
<
V
>
)
{
if
constexpr
(
sized_
range
<
V
>
)
{
if
constexpr
(
random_
access_
range
<
V
>
)
return
ranges
::
begin
(
base_
)
+
range_difference_t
<
V
>
(
size
(
)
)
;
else
return
default_sentinel;
}
else
if
constexpr
(
sized_
sentinel_
for
<
sentinel_t
<
V
>
, iterator_t
<
V
>
>
)
{
return
default_sentinel;
}
else
{
return
sentinel
<
false
>
{
ranges
::
end
(
base_
)
}
;
}
}
constexpr
auto
end
(
)
const
requires
range
<
const
V
>
{
if
constexpr
(
sized_
range
<
const
V
>
)
{
if
constexpr
(
random_
access_
range
<
const
V
>
)
return
ranges
::
begin
(
base_
)
+
range_difference_t
<
const
V
>
(
size
(
)
)
;
else
return
default_sentinel;
}
else
if
constexpr
(
sized_
sentinel_
for
<
sentinel_t
<
const
V
>
, iterator_t
<
const
V
>
>
)
{
return
default_sentinel;
}
else
{
return
sentinel
<
true
>
{
ranges
::
end
(
base_
)
}
;
}
}
constexpr
auto
size
(
)
requires
sized_
range
<
V
>
{
auto
n
=
ranges
::
size
(
base_
)
;
return
ranges
::
min
(
n,
static_cast
<
decltype
(
n
)
>
(
count_
)
)
;
}
constexpr
auto
size
(
)
const
requires
sized_
range
<
const
V
>
{
auto
n
=
ranges
::
size
(
base_
)
;
return
ranges
::
min
(
n,
static_cast
<
decltype
(
n
)
>
(
count_
)
)
;
}
constexpr
auto
reserve_hint
(
)
{
if
constexpr
(
approximately_
sized_
range
<
V
>
)
{
auto
n
=
static_cast
<
range_difference_t
<
V
>
>
(
ranges
::
reserve_hint
(
base_
)
)
;
return
to-unsigned-like
(
ranges
::
min
(
n,
count_
)
)
;
}
return
to-unsigned-like
(
count_
)
;
}
constexpr
auto
reserve_hint
(
)
const
{
if
constexpr
(
approximately_
sized_
range
<
const
V
>
)
{
auto
n
=
static_cast
<
range_difference_t
<
const
V
>
>
(
ranges
::
reserve_hint
(
base_
)
)
;
return
to-unsigned-like
(
ranges
::
min
(
n,
count_
)
)
;
}
return
to-unsigned-like
(
count_
)
;
}
}
;
template
<
class
R
>
take_view
(
R
&
&
, range_difference_t
<
R
>
)
-
>
take_view
<
views
::
all_t
<
R
>
>
;
}
🔗
constexpr
explicit
take_view
(
V base, range_difference_t
<
V
>
count
)
;
1
#
Preconditions
:
count
>
=
0
is
true
.
2
#
Effects
: Initializes
base_
with
std
::
move
(
base
)
and
count_
with
count
.