次の方法で共有


map::map (STL/CLR)

Constructs a container object.

    map();
    explicit map(key_compare^ pred);
    map(map<Key, Mapped>% right);
    map(map<Key, Mapped>^ right);
    template<typename InIter>
        mapmap(InIter first, InIter last);
    template<typename InIter>
        map(InIter first, InIter last,
            key_compare^ pred);
    map(System::Collections::Generic::IEnumerable<GValue>^ right);
    map(System::Collections::Generic::IEnumerable<GValue>^ right,
        key_compare^ pred);

Parameters

  • first
    Beginning of range to insert.

  • last
    End of range to insert.

  • pred
    Ordering predicate for the controlled sequence.

  • right
    Object or range to insert.

Remarks

The constructor:

map();

initializes the controlled sequence with no elements, with the default ordering predicate key_compare(). You use it to specify an empty initial controlled sequence, with the default ordering predicate.

The constructor:

explicit map(key_compare^ pred);

initializes the controlled sequence with no elements, with the ordering predicate pred. You use it to specify an empty initial controlled sequence, with the specified ordering predicate.

The constructor:

map(map<Key, Mapped>% right);

initializes the controlled sequence with the sequence [right.map::begin (STL/CLR)(), right.map::end (STL/CLR)()), with the default ordering predicate. You use it to specify an initial controlled sequence that is a copy of the sequence controlled by the map object right, with the default ordering predicate.

The constructor:

map(map<Key, Mapped>^ right);

initializes the controlled sequence with the sequence [right->map::begin (STL/CLR)(), right->map::end (STL/CLR)()), with the default ordering predicate. You use it to specify an initial controlled sequence that is a copy of the sequence controlled by the map object right, with the default ordering predicate.

The constructor:

template<typename InIter>

map(InIter first, InIter last);

initializes the controlled sequence with the sequence [first, last), with the default ordering predicate. You use it to make the controlled sequence a copy of another sequence, with the default ordering predicate.

The constructor:

template<typename InIter>

map(InIter first, InIter last,

key_compare^ pred);

initializes the controlled sequence with the sequence [first, last), with the ordering predicate pred. You use it to make the controlled sequence a copy of another sequence, with the specified ordering predicate.

The constructor:

map(System::Collections::Generic::IEnumerable<Key>^ right);

initializes the controlled sequence with the sequence designated by the enumerator right, with the default ordering predicate. You use it to make the controlled sequence a copy of another sequence described by an enumerator, with the default ordering predicate.

The constructor:

map(System::Collections::Generic::IEnumerable<Key>^ right,

key_compare^ pred);

initializes the controlled sequence with the sequence designated by the enumerator right, with the ordering predicate pred. You use it to make the controlled sequence a copy of another sequence described by an enumerator, with the specified ordering predicate.

Example

// cliext_map_construct.cpp 
// compile with: /clr 
#include <cliext/map> 
 
typedef cliext::map<wchar_t, int> Mymap; 
int main() 
    { 
// construct an empty container 
    Mymap c1; 
    System::Console::WriteLine("size() = {0}", c1.size()); 
 
    c1.insert(Mymap::make_value(L'a', 1)); 
    c1.insert(Mymap::make_value(L'b', 2)); 
    c1.insert(Mymap::make_value(L'c', 3)); 
    for each (Mymap::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// construct with an ordering rule 
    Mymap c2 = cliext::greater_equal<wchar_t>(); 
    System::Console::WriteLine("size() = {0}", c2.size()); 
 
    c2.insert(c1.begin(), c1.end()); 
    for each (Mymap::value_type elem in c2) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// construct with an iterator range 
    Mymap c3(c1.begin(), c1.end()); 
    for each (Mymap::value_type elem in c3) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// construct with an iterator range and an ordering rule 
    Mymap c4(c1.begin(), c1.end(), 
        cliext::greater_equal<wchar_t>()); 
    for each (Mymap::value_type elem in c4) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// construct with an enumeration 
    Mymap c5(   // NOTE: cast is not needed 
        (System::Collections::Generic::IEnumerable< 
            Mymap::value_type>^)%c3); 
    for each (Mymap::value_type elem in c5) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// construct with an enumeration and an ordering rule 
    Mymap c6(   // NOTE: cast is not needed 
        (System::Collections::Generic::IEnumerable< 
            Mymap::value_type>^)%c3, 
                cliext::greater_equal<wchar_t>()); 
    for each (Mymap::value_type elem in c6) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// construct by copying another container 
    Mymap c7(c4); 
    for each (Mymap::value_type elem in c7) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// construct by copying a container handle 
    Mymap c8(%c3); 
    for each (Mymap::value_type elem in c8) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
    return (0); 
    } 
 
size() = 0
 [a 1] [b 2] [c 3]
size() = 0
 [c 3] [b 2] [a 1]
 [a 1] [b 2] [c 3]
 [c 3] [b 2] [a 1]
 [a 1] [b 2] [c 3]
 [c 3] [b 2] [a 1]
 [c 3] [b 2] [a 1]
 [a 1] [b 2] [c 3]

Requirements

Header: <cliext/map>

Namespace: cliext

See Also

Concepts

map (STL/CLR)

map::generic_container (STL/CLR)

map::operator= (STL/CLR)