Click here to Skip to main content
11,631,906 members (69,057 online)
Click here to Skip to main content
Add your own
alternative version

Win32 File Name Iteration Boost Way

, 3 Nov 2005 CPOL 39.8K 362 17
A Port of ::FindFirstFile to Boost.Range and Boost.Foreach
#pragma once

// Model of:
//   Readable and Single Pass (Input) Range of WIN32_FIND_DATA

#include <cassert>
#include <boost/mpl/bool.hpp>
#include <boost/noncopyable.hpp>
#include <boost/range/iterator_range.hpp>
#include "find_file_iterator.hpp"

namespace find_file {

	namespace detail {

		// See: Boost.BaseFromMember
		struct find_file_range_initializer
			HANDLE m_hFind;
			WIN32_FIND_DATA m_data;

			explicit find_file_range_initializer(LPCTSTR pszName)
				m_hFind = ::FindFirstFile(pszName, &m_data);

				if (m_hFind != INVALID_HANDLE_VALUE)

	} // namespace detail

struct find_file_range  :
	private boost::noncopyable,
	private detail::find_file_range_initializer,
	typedef boost::iterator_range<find_file_iterator> super_t;

	explicit find_file_range(LPCTSTR pszName) :
			find_file_iterator(m_hFind, m_data),
	{ }

} // namespace find_file

// Workaround:
//   As find_file_range is derived from iterator_range,
//   foreach-engine mistakes find_file_range for iterator_range
//   that is copyable. Caution!
namespace boost { namespace foreach_detail_ {

inline boost::mpl::false_ *cheap_copy(find_file::find_file_range *) { return 0; }

} } // namespace boost::foreach_detail_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Japan Japan
I am worried about my poor English...

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150728.1 | Last Updated 4 Nov 2005
Article Copyright 2005 by mb2sync
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid