Boost logo

Boost Users :

From: Angus Leeming (yg-boost-users_at_[hidden])
Date: 2003-08-12 10:26:59


Hello.

I am just beginning to look at the spirit library, but am confused by the
way file_iterator is working.

Could anyone explain to me why this works:
        typedef spirit::file_iterator <char_t> iterator_t;
        iterator_t first(argv[1]);
        // check first is valid
        ...
        iterator_t last = first.make_end();

but this doesn't:
        typedef spirit::file_iterator <char_t> iterator_t;
        iterator_t first;
        iterator_t last;
        boost::tie(first, last) = open_file(argv[1]);
        // check first is valid
        ...

Both codes compile, but only the first method results in the file being
read. In the second instance, the correct number of chars are read, but
only the first char is output (multiple times).

The open_file function is simply:
std::pair<iterator_t, iterator_t> open_file(char const * name)
{
        iterator_t first(name);
        iterator_t last = first ? first.make_end() : iterator_t();
        return std::make_pair(first, last);
}

Minimal sample code attached. My tests have been with boost 1.30.1.

Changing the line
        #define FAILURE_MODE 1
toggles between the two cases.

Best regards,
Angus

[Non-text portions of this message have been removed]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net