Boost logo

Boost :

Subject: [boost] [filesystem] #6521 Directory listing using C++11 range-based for loops
From: Beman Dawes (bdawes_at_[hidden])
Date: 2012-04-19 09:57:16


Ticket #6521 requests adding:

        class directory{
            path p_;
            public:
                inline directory(path p):p_(p){}
                directory_iterator begin(){
                    return directory_iterator(p_);
                }
                directory_iterator end(){
                    return directory_iterator();
                }
        };

so that that a range-based for loop can be used:

     for (auto itr : directory("."))
     {
         cout << itr.path() << endl;
     }

The above works as expected on GCC 4.6 and VC++ 11 beta.

Is that the best way for filesystem directory iteration to support
range-based for?

Provide a class directory_tree for recursive iteration?

--Beman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk