Use of C ++ and the list of auto

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/baiyibin0530/article/details/90543620

List

Template <Elem typename>
struct Link
{
    Link * PREV; // before becoming connected
    Link * succ; // subsequent (next) connected
    Elem val; // value
}


template<typename Elem>

class list
{
    
};


We were able to each container iterators are named literator.
In the presence of a standard library list <T> :: iterator, vector <T> :: iterator, map <K, V> :: iterator


Generalized vector again

using the statement create an alias for a type, that is, for our vector, iterator is used as a synonym for our iterator type T *, which
is another name.


auto

template<typename T> //要求Element<T>()
void user(vector<T>& v, list<T>& lst)
{
    for (vector<T>::iterator p = v.begin(); p!=v.end(); ++p) cout<<*p<<'\n';

    list<T>::iterator q = find(lst.begin(), lst.end(), T{42});

}

Variables can be declared as auto, showing the use of the type of iterator type as a variable.
template <typename T> // claim the Element <T> ()
void User (Vector <T> & V, List <T> & LST)
{
    for (P = v.begin Auto ();! P = v.end ( ); ++ p) cout << * p << '\ n';

    auto q = find(lst.begin(), lst.end(), T{42});

}
Here, P is a vector <T> :: iterator, q is a list <T> :: iterator.

Guess you like

Origin blog.csdn.net/baiyibin0530/article/details/90543620