std::ranges:: empty
|
||||||||||||||||||||||
| Range primitives | |||||||
|
|||||||
| Range concepts | |||||||||||||||||||
|
|||||||||||||||||||
| Range factories | |||||||||
|
|||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||
| Helper items | |||||||||||||||||
|
|
||||||||||||||||
|
헤더에 정의됨
<ranges>
|
||
|
헤더에 정의됨
<iterator>
|
||
|
inline
namespace
/*unspecified*/
{
inline
constexpr
auto
empty
=
/*unspecified*/
;
|
(C++20 이후)
(customization point object) |
|
|
호출 시그니처
|
||
|
template
<
class
T
>
requires
/* see below */
|
(C++20 이후) | |
t 에 요소가 있는지 여부를 결정합니다.
ranges::empty
에 대한 호출은
표현식 동등성
에 따라 다음과 동등합니다:
- bool ( t. empty ( ) ) , 해당 표현식이 유효한 경우.
- 그렇지 않은 경우, ( ranges:: size ( t ) == 0 ) , 해당 표현식이 유효한 경우.
- 그렇지 않은 경우, bool ( ranges:: begin ( t ) == ranges:: end ( t ) ) , 해당 표현식이 유효하고 decltype ( ranges:: begin ( t ) ) 이 std::forward_iterator 를 모델로 하는 경우.
다른 모든 경우에서
ranges::empty
호출은 형식에 맞지 않으며, 이는 템플릿 인스턴스화의 직접적 문맥에서
ranges
::
empty
(
t
)
가 나타날 때
치환 실패
를 초래할 수 있습니다.
커스터마이제이션 포인트 객체
ranges::empty
라는 이름은
커스터마이제이션 포인트 객체
를 나타내며,
이는 리터럴
LiteralType
semiregular
클래스 타입의 const
FunctionObject
입니다. 자세한 내용은
CustomizationPointObject
를 참조하십시오.
예제
#include <iostream> #include <ranges> #include <vector> template<std::ranges::input_range R> void print(char id, R&& r) { if (std::ranges::empty(r)) { std::cout << '\t' << id << ") Empty\n"; return; } std::cout << '\t' << id << ") Elements:"; for (const auto& element : r) std::cout << ' ' << element; std::cout << '\n'; } int main() { { auto v = std::vector<int>{1, 2, 3}; std::cout << "(1) ranges::empty uses std::vector::empty:\n"; print('a', v); v.clear(); print('b', v); } { std::cout << "(2) ranges::empty uses ranges::size(initializer_list):\n"; auto il = {7, 8, 9}; print('a', il); print('b', std::initializer_list<int>{}); } { std::cout << "(2) ranges::empty on a raw array uses ranges::size:\n"; int array[] = {4, 5, 6}; // array has a known bound print('a', array); } { struct Scanty : private std::vector<int> { using std::vector<int>::begin; using std::vector<int>::end; using std::vector<int>::push_back; // Note: both empty() and size() are hidden }; std::cout << "(3) calling ranges::empty on an object w/o empty() or size():\n"; Scanty y; print('a', y); y.push_back(42); print('b', y); } }
출력:
(1) ranges::empty uses std::vector::empty:
a) Elements: 1 2 3
b) Empty
(2) ranges::empty uses ranges::size(initializer_list):
a) Elements: 7 8 9
b) Empty
(2) ranges::empty on a raw array uses ranges::size:
a) Elements: 4 5 6
(3) calling ranges::empty on an object w/o empty() or size():
a) Empty
b) Elements: 42
참고 항목
|
(C++17)
|
컨테이너가 비어 있는지 확인합니다
(함수 템플릿) |