다음을 통해 공유


<memory> 연산자

operator!=

개체 간의 같지 않음을 테스트합니다.

template <class Type, class Other>
bool operator!=(
    const allocator<Type>& left,
    const allocator<Other>& right) throw();

template <class T, class Del1, class U, class Del2>
bool operator!=(
    const unique_ptr<T, Del1>& left,
    const unique_ptr<U&, Del2>& right);

template <class Ty1, class Ty2>
bool operator!=(
    const shared_ptr<Ty1>& left,
    const shared_ptr<Ty2>& right);

매개 변수

left
같지 않음을 테스트할 개체 중 하나입니다.

right
같지 않음을 테스트할 개체 중 하나입니다.

Ty1
왼쪽 공유 포인터로 제어되는 형식입니다.

Ty2
오른쪽 공유 포인터로 제어되는 형식입니다.

Return Value

true 개체가 같지 않으면 false 개체가 같으면 입니다.

설명

첫 번째 템플릿 연산자는 false를 반환합니다. (모든 기본 할당자가 같습니다.)

두 번째 및 세 번째 템플릿 연산자는 !(left == right)을 반환합니다.

예시

첫 번째 코드 예제는 할당자 개체를 비교한 결과를 보여줍니다.

// memory_op_me.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <vector>

using namespace std;

int main( )
{
   allocator<double> Alloc;
   vector <char>:: allocator_type v1Alloc;

   if ( Alloc != v1Alloc )
      cout << "The allocator objects Alloc & v1Alloc not are equal."
           << endl;
   else
      cout << "The allocator objects Alloc & v1Alloc are equal."
           << endl;
}
The allocator objects Alloc & v1Alloc are equal.

다음 코드 예제에서는 공유 포인터를 할당된 개체와 비교합니다.

// std__memory__operator_ne.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>

int main()
    {
    std::shared_ptr<int> sp0(new int(0));
    std::shared_ptr<int> sp1(new int(0));

    std::cout << "sp0 != sp0 == " << std::boolalpha
        << (sp0 != sp0) << std::endl;
    std::cout << "sp0 != sp1 == " << std::boolalpha
        << (sp0 != sp1) << std::endl;

    return (0);
    }
sp0 != sp0 == false
sp0 != sp1 == true

연산자==

개체 간의 같음을 테스트합니다.

template <class Type, class Other>
bool operator==(
    const allocator<Type>& left,
    const allocator<Other>& right) throw();

template <class Ty1, class Del1, class Ty2, class Del2>
bool operator==(
    const unique_ptr<Ty1, Del1>& left,
    const unique_ptr<Ty2, Del2>& right);

template <class Ty1, class Ty2>
bool operator==(
    const shared_ptr<Ty1>& left;,
    const shared_ptr<Ty2>& right);

매개 변수

left
같은지 여부를 테스트할 개체 중 하나입니다.

right
같은지 여부를 테스트할 개체 중 하나입니다.

Ty1
왼쪽 공유 포인터로 제어되는 형식입니다.

Ty2
오른쪽 공유 포인터로 제어되는 형식입니다.

Return Value

개체가 같으면 true이고, 같지 않으면 false입니다.

설명

첫 번째 템플릿 연산자는 true를 반환합니다. (모든 기본 할당자가 같습니다.)

두 번째 및 세 번째 템플릿 연산자는 left.get() == right.get()을 반환합니다.

예시

첫 번째 코드 예제에서는 다양한 방식으로 생성된 할당자 개체를 비교한 결과를 보여 있습니다.

// memory_op_eq.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
#include <vector>

using namespace std;

int main( )
{
   allocator<char> Alloc;
   vector <int>:: allocator_type v1Alloc;

   allocator<char> cAlloc(Alloc);
   allocator<int> cv1Alloc(v1Alloc);

   if ( cv1Alloc == v1Alloc )
      cout << "The allocator objects cv1Alloc & v1Alloc are equal."
           << endl;
   else
      cout << "The allocator objects cv1Alloc & v1Alloc are not equal."
           << endl;

   if ( cAlloc == Alloc )
      cout << "The allocator objects cAlloc & Alloc are equal."
           << endl;
   else
      cout << "The allocator objects cAlloc & Alloc are not equal."
           << endl;
}
The allocator objects cv1Alloc & v1Alloc are equal.
The allocator objects cAlloc & Alloc are equal.

다음 코드 예제에서는 공유 포인터를 할당된 개체와 비교합니다.

// std__memory__operator_eq.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>

int main()
    {
    std::shared_ptr<int> sp0(new int(0));
    std::shared_ptr<int> sp1(new int(0));

    std::cout << "sp0 == sp0 == " << std::boolalpha
        << (sp0 == sp0) << std::endl;
    std::cout << "sp0 == sp1 == " << std::boolalpha
        << (sp0 == sp1) << std::endl;

    return (0);
    }
sp0 == sp0 == true
sp0 == sp1 == false

operator>=

한 개체가 두 번째 개체보다 크거나 같은지 테스트합니다.

template <class T, class Del1, class U, class Del2>
bool operator>=(
    const unique_ptr<T, Del1>& left,
    const unique_ptr<U, Del2>& right);

template <class Ty1, class Ty2>
bool operator>=(
    const shared_ptr<Ty1>& left,
    const shared_ptr<Ty2>& right);

매개 변수

left
비교할 개체 중 하나입니다.

right
비교할 개체 중 하나입니다.

Ty1
왼쪽 공유 포인터로 제어되는 형식입니다.

Ty2
오른쪽 공유 포인터로 제어되는 형식입니다.

설명

템플릿 연산자는 left.get() >= right.get()을 반환합니다.

operator<

한 개체가 두 번째 개체보다 작은지 테스트합니다.

template <class T, class Del1, class U, class Del2>
bool operator<(
    const unique_ptr<T, Del1>& left,
    const unique_ptr<U&, Del2>& right);

template <class Ty1, class Ty2>
bool operator<(
    const shared_ptr<Ty1>& left,
    const shared_ptr<Ty2>& right);

매개 변수

left
비교할 개체 중 하나입니다.

right
비교할 개체 중 하나입니다.

Ty1
왼쪽 포인터에 의해 제어되는 형식입니다.

Ty2
오른쪽 포인터에 의해 제어되는 형식입니다.

operator<=

한 개체가 두 번째 개체보다 작거나 같은지 테스트합니다.

template <class T, class Del1, class U, class Del2>
bool operator<=(
    const unique_ptr<T, Del1>& left,
    const unique_ptr<U&, Del2>& right);

template <class Ty1, class Ty2>
bool operator<=(
    const shared_ptr<Ty1>& left,
    const shared_ptr<Ty2>& right);

매개 변수

left
비교할 개체 중 하나입니다.

right
비교할 개체 중 하나입니다.

Ty1
왼쪽 공유 포인터로 제어되는 형식입니다.

Ty2
오른쪽 공유 포인터로 제어되는 형식입니다.

설명

템플릿 연산자는 left.get() <= right.get()을 반환합니다.

operator>

한 개체가 두 번째 개체보다 큰지 테스트합니다.

template <class Ty1, class Del1, class Ty2, class Del2>
bool operator>(
    const unique_ptr<Ty1, Del1>& left,
    const unique_ptr<Ty2&, Del2gt;& right);

template <class Ty1, class Ty2>
bool operator>(
    const shared_ptr<Ty1>& left,
    const shared_ptr<Ty2>& right);

매개 변수

left
비교할 개체 중 하나입니다.

right
비교할 개체 중 하나입니다.

Ty1
왼쪽 공유 포인터로 제어되는 형식입니다.

Ty2
오른쪽 공유 포인터로 제어되는 형식입니다.

operator<<

공유 포인터를 스트림에 씁니다.

template <class Elem, class Tr, class Ty>
std::basic_ostream<Elem, Tr>& operator<<(std::basic_ostream<Elem, Tr>& out,
    shared_ptr<Ty>& sp);

매개 변수

Elem
스트림 요소의 형식입니다.

Tr
스트림 요소 특성의 형식입니다.

Ty
공유 포인터에 의해 제어되는 형식입니다.

out
출력 스트림입니다.

Sp
공유 포인터입니다.

설명

템플릿 함수가 out << sp.get()를 반환합니다.

예제

// std__memory__operator_sl.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>

int main()
    {
    std::shared_ptr<int> sp0(new int(5));

    std::cout << "sp0 == " << sp0 << " (varies)" << std::endl;

    return (0);
    }
sp0 == 3f3040 (varies)