Megosztás:


<array> operátorok

A <array> fejléc tartalmazza ezeket a tömb nem tag összehasonlító sablonfüggvényeket.

operator!=

Tömbök összehasonlítása, nem egyenlő.

template <class Ty, std::size_t N>
bool operator!=(
    const array<Ty, N>& left,
    const array<Ty, N>& right);

Paraméterek

Ty
Az elem típusa.

N
A tömb mérete.

left
Bal oldali tároló, amit össze kell hasonlítani.

right
Jobb tároló az összehasonlításhoz.

Megjegyzések

A sablonfüggvény ad !(left == right)vissza.

példa

// std__array__operator_ne.cpp
// compile with: /EHsc
#include <array>
#include <iostream>

typedef std::array<int, 4> Myarray;
int main()
    {
    Myarray c0 = {0, 1, 2, 3};

// display contents " 0 1 2 3"
    for (Myarray::const_iterator it = c0.begin();
        it != c0.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

    Myarray c1 = {4, 5, 6, 7};

// display contents " 4 5 6 7"
    for (Myarray::const_iterator it = c1.begin();
        it != c1.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

// display results of comparisons
    std::cout << std::boolalpha << " " << (c0 != c0);
    std::cout << std::endl;
    std::cout << std::boolalpha << " " << (c0 != c1);
    std::cout << std::endl;

    return (0);
    }
0 1 2 3
4 5 6 7
false
true

operator<

Tömbök összehasonlítása, kisebb mint.

template <class Ty, std::size_t N>
bool operator<(
    const array<Ty, N>& left,
    const array<Ty, N>& right);

Paraméterek

Ty
Az elem típusa.

N
A tömb mérete.

left
Bal oldali tároló, amit össze kell hasonlítani.

right
Jobb tároló az összehasonlításhoz.

Megjegyzések

A sablonfüggvény túlterheli operator< az osztálysablon arraykét objektumának összehasonlítását. A függvény ad lexicographical_compare(left.begin(), left.end(), right.begin())vissza .

példa

// std__array__operator_lt.cpp
// compile with: /EHsc
#include <array>
#include <iostream>

typedef std::array<int, 4> Myarray;
int main()
    {
    Myarray c0 = {0, 1, 2, 3};

// display contents " 0 1 2 3"
    for (Myarray::const_iterator it = c0.begin();
        it != c0.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

    Myarray c1 = {4, 5, 6, 7};

// display contents " 4 5 6 7"
    for (Myarray::const_iterator it = c1.begin();
        it != c1.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

// display results of comparisons
    std::cout << std::boolalpha << " " << (c0 < c0);
    std::cout << std::endl;
    std::cout << std::boolalpha << " " << (c0 < c1);
    std::cout << std::endl;

    return (0);
    }
0 1 2 3
4 5 6 7
false
true

operator<=

Tömbök összehasonlítása kisebb vagy egyenlő.

template <class Ty, std::size_t N>
bool operator<=(
    const array<Ty, N>& left,
    const array<Ty, N>& right);

Paraméterek

Ty
Az elem típusa.

N
A tömb mérete.

left
Bal oldali tároló, amit össze kell hasonlítani.

right
Jobb tároló az összehasonlításhoz.

Megjegyzések

A sablonfüggvény ad !(right < left)vissza.

példa

// std__array__operator_le.cpp
// compile with: /EHsc
#include <array>
#include <iostream>

typedef std::array<int, 4> Myarray;
int main()
    {
    Myarray c0 = {0, 1, 2, 3};

// display contents " 0 1 2 3"
    for (Myarray::const_iterator it = c0.begin();
        it != c0.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

    Myarray c1 = {4, 5, 6, 7};

// display contents " 4 5 6 7"
    for (Myarray::const_iterator it = c1.begin();
        it != c1.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

// display results of comparisons
    std::cout << std::boolalpha << " " << (c0 <= c0);
    std::cout << std::endl;
    std::cout << std::boolalpha << " " << (c1 <= c0);
    std::cout << std::endl;

    return (0);
    }
0 1 2 3
4 5 6 7
true
false

operator==

Tömbök összehasonlítása, egyenlő.

template <class Ty, std::size_t N>
bool operator==(
    const array<Ty, N>& left,
    const array<Ty, N>& right);

Paraméterek

Ty
Az elem típusa.

N
A tömb mérete.

left
Bal oldali tároló, amit össze kell hasonlítani.

right
Jobb tároló az összehasonlításhoz.

Megjegyzések

A sablonfüggvény túlterheli operator== az osztálysablon arraykét objektumának összehasonlítását. A függvény ad equal(left.begin(), left.end(), right.begin())vissza .

példa

// std__array__operator_eq.cpp
// compile with: /EHsc
#include <array>
#include <iostream>

typedef std::array<int, 4> Myarray;
int main()
    {
    Myarray c0 = {0, 1, 2, 3};

// display contents " 0 1 2 3"
    for (Myarray::const_iterator it = c0.begin();
        it != c0.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

    Myarray c1 = {4, 5, 6, 7};

// display contents " 4 5 6 7"
    for (Myarray::const_iterator it = c1.begin();
        it != c1.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

// display results of comparisons
    std::cout << std::boolalpha << " " << (c0 == c0);
    std::cout << std::endl;
    std::cout << std::boolalpha << " " << (c0 == c1);
    std::cout << std::endl;

    return (0);
    }
0 1 2 3
4 5 6 7
true
false

operator>

Tömbök összehasonlítása, nagyobb mint.

template <class Ty, std::size_t N>
bool operator>(
    const array<Ty, N>& left,
    const array<Ty, N>& right);

Paraméterek

Ty
Az elem típusa.

N
A tömb mérete.

left
Bal oldali tároló, amit össze kell hasonlítani.

right
Jobb tároló az összehasonlításhoz.

Megjegyzések

A sablonfüggvény ad (right < left)vissza.

példa

// std__array__operator_gt.cpp
// compile with: /EHsc
#include <array>
#include <iostream>

typedef std::array<int, 4> Myarray;
int main()
    {
    Myarray c0 = {0, 1, 2, 3};

// display contents " 0 1 2 3"
    for (Myarray::const_iterator it = c0.begin();
        it != c0.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

    Myarray c1 = {4, 5, 6, 7};

// display contents " 4 5 6 7"
    for (Myarray::const_iterator it = c1.begin();
        it != c1.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

// display results of comparisons
    std::cout << std::boolalpha << " " << (c0 > c0);
    std::cout << std::endl;
    std::cout << std::boolalpha << " " << (c1 > c0);
    std::cout << std::endl;

    return (0);
    }
0 1 2 3
4 5 6 7
false
true

operator>=

Tömbök összehasonlítása, nagyobb vagy egyenlő.

template <class Ty, std::size_t N>
bool operator>=(
    const array<Ty, N>& left,
    const array<Ty, N>& right);

Paraméterek

Ty
Az elem típusa.

N
A tömb mérete.

left
Bal oldali tároló, amit össze kell hasonlítani.

right
Jobb tároló az összehasonlításhoz.

Megjegyzések

A sablonfüggvény ad !(left < right)vissza.

példa

// std__array__operator_ge.cpp
// compile with: /EHsc
#include <array>
#include <iostream>

typedef std::array<int, 4> Myarray;
int main()
    {
    Myarray c0 = {0, 1, 2, 3};

// display contents " 0 1 2 3"
    for (Myarray::const_iterator it = c0.begin();
        it != c0.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

    Myarray c1 = {4, 5, 6, 7};

// display contents " 4 5 6 7"
    for (Myarray::const_iterator it = c1.begin();
        it != c1.end(); ++it)
        std::cout << " " << *it;
    std::cout << std::endl;

// display results of comparisons
    std::cout << std::boolalpha << " " << (c0 >= c0);
    std::cout << std::endl;
    std::cout << std::boolalpha << " " << (c0 >= c1);
    std::cout << std::endl;

    return (0);
    }
0 1 2 3
4 5 6 7
true
false

Lásd még

<array>