Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. iterator default value [modified]

iterator default value [modified]

Scheduled Pinned Locked Moved ATL / WTL / STL
questiontutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    liquid_
    wrote on last edited by
    #1

    How can I check whether an iterator was assigned a value or not? In other words, if I create an iterator with default constructor what value will it present which I could check against? It is not the trivial case such this:

    list::iterator it; //what does it contains?

    but this:

    map::iterator> aci;
    AClass *ptr=someinitializedaclassptr;
    if(aci[ptr]==UNINITIALIZED_ITERATOR)
    {
    dosomething();
    }

    In above example issuing aci[ptr] creates already an entry in the map with default constructed value list::iterator if there isn't a key of value ptr.

    modified on Friday, August 5, 2011 7:48 AM

    S 1 Reply Last reply
    0
    • L liquid_

      How can I check whether an iterator was assigned a value or not? In other words, if I create an iterator with default constructor what value will it present which I could check against? It is not the trivial case such this:

      list::iterator it; //what does it contains?

      but this:

      map::iterator> aci;
      AClass *ptr=someinitializedaclassptr;
      if(aci[ptr]==UNINITIALIZED_ITERATOR)
      {
      dosomething();
      }

      In above example issuing aci[ptr] creates already an entry in the map with default constructed value list::iterator if there isn't a key of value ptr.

      modified on Friday, August 5, 2011 7:48 AM

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      Read this thread on (ahem) stackoverflow: http://stackoverflow.com/questions/3395180/what-is-an-iterators-default-value[^]

      Steve

      L 1 Reply Last reply
      0
      • S Stephen Hewitt

        Read this thread on (ahem) stackoverflow: http://stackoverflow.com/questions/3395180/what-is-an-iterators-default-value[^]

        Steve

        L Offline
        L Offline
        liquid_
        wrote on last edited by
        #3

        Well, it is obvious it has no special value as int val;. The problem is how to check this. I'll try the below code:

        #include "list"
        #include "map"
        #include "iostream"

        using namespace std;

        int main()
        {
        list::iterator it,itnull;
        map::iterator> imap;

        it = imap\[1\]; //map creates entry with key '1' and default constructed iterator
        if(it==itnull) //checking with other default constructed iterator
            cout<<"it unitialized"<
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups