InputIterator

This is a discussion on InputIterator within the C++ Programming forums, part of the General Programming Boards category; Is anyone familiar with the concept of InputIterator? I am searching google for examples and got nothing! I want to ...

  1. #1
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678

    InputIterator

    Is anyone familiar with the concept of InputIterator? I am searching google for examples and got nothing!

    I want to create a point in d dimensions - let d be 3 for example - with CGAL.
    The appropriate constructor is this, I believe.

    As you can see, it states
    Code:
     	int  	d, //dimension
    	InputIterator  	first,
    	InputIterator  	last
    I am not quite sure how to use them.
    It says: The value type of InputIterator is RT.

    As for the Inputiterator, it directs me here.

    Any idea? How would for example define a point in 4 or 3 dimensions, with all the coordinates equal to one?
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Looks like you need some container with coords values and put begin() and end() iterators

    Code:
    int coords[3] = {1,2,3}
    
    CGAL::Point_d< Kernel >::Point_d  d	(3,coords, coords+3);
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    InputIterator isn't a type. An iterator (any that you happen to have lying around) is an InputIterator if putting a * in front of it gives you a value, and ++ moves it along to the "next" one (whatever "next" means in this context). So a double* pointing to some memory would work, or just about any ::iterator type, etc.

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Quote Originally Posted by std10093 View Post
    It says: The value type of InputIterator is RT.
    I don't understand what isn't clear here. It means exactly what it says - the value type of InputIterator must be RT.

    It doesn't matter what is the exact type of the supplied iterator of type, let's say, IteratorType, as long as IteratorType meets the InputIterator requirements defined in the C++ standard and IteratorType::value_type is RT. It doesn't matter whether you supply an instance of std::vector<RT>::iterator or an instance of std::deque<RT>::iterator. Both can be used; and raw pointers can be used too.
    Last edited by kmdv; 10-18-2013 at 11:54 AM.
    I never put signature, but I decided to make an exception.

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678
    I just love this forum. I had think of defining a vector of mine, but what should the type of it be? I was confused, but now everything is clear.

    Thanks!
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  6. #6
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678
    When I lied on the bed, two questions were arised to me. Yet, unanswered!

    1)What's an RT?

    2)How to elegantly and efficiently read from a file four points per line and use them to create 4 "CGAL" points.

    What I have until now is:
    1)The closest result I found in google (Route distingusher). I think I shouldn't be happy with this.

    2)
    In four dimensions.
    Code:
    while(std::getline(infile, line))
        {
                std::istringstream iss(line);
                if (!(iss >> a >> b >> c >> d))
                { //Error
                    std::cout << "Error while reading file!" << std::endl; break;
                }
                createArrayWithElements_a_b_c_d;
                createCGALpoint;
       }
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by std10093 View Post
    When I lied on the bed, two questions were arised to me. Yet, unanswered!

    1)What's an RT?
    This is why there is such a thing as API documentation. You may want to seek out section 2.1, although if you are going to use this package you should really read the whole thing, as much as possible. Remember, just like InputIterator, some things do not specify a particular type.

    Quote Originally Posted by std10093 View Post
    2)How to elegantly and efficiently read from a file four points per line and use them to create 4 "CGAL" points.
    Your code here only reads one point per line, which means you seem to be three points short. Since according to the documentation there is a constructor that takes four values and constructs a 3-D point from them (using homogeneous coordinates), that may be the one you want. (I don't know whether you want 3-D homogeneous coordinates or 4-D "plain" coordinates.)

  8. #8
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678
    Yes, you are right, I should.

    The code reads four doubles per line. I see what you mean, but ok, let's assume that I know the dimension from a previous line of the file.
    So, in case of 4D, I want to read 4 coordinates (not that I said points before, which was a mistake) per line.
    So, the code does so, but it has to create first an array, vector, or similar and then create the Point.
    I was wondering if I could skip the creating of the array..
    The points I will have to read will be many.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by std10093 View Post
    Yes, you are right, I should.

    The code reads four doubles per line. I see what you mean, but ok, let's assume that I know the dimension from a previous line of the file.
    So, in case of 4D, I want to read 4 coordinates (not that I said points before, which was a mistake) per line.
    So, the code does so, but it has to create first an array, vector, or similar and then create the Point.
    I was wondering if I could skip the creating of the array..
    The points I will have to read will be many.
    The docs only show "nice" constructors for 2D and 3D (including x,y,z,w for homogeneous), so if you want echte 4D you'll have to use the iterator constructor it seems. I was thinking you might be able to use the istream_iterator constructor, but a few experiments suggest maybe not.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21