diff --git a/include/boost/range/detail/mfc/carray.hpp b/include/boost/range/detail/mfc/carray.hpp index 546c010..83c8eb7 100755 --- a/include/boost/range/detail/mfc/carray.hpp +++ b/include/boost/range/detail/mfc/carray.hpp @@ -15,38 +15,47 @@ # pragma once #endif -#include // for CArray +#include // for CArray #include #include namespace boost { template< class T, class U > - struct iterator_of< CArray > + struct range_iterator< CArray > { typedef T* type; }; - + + // + // Why is this needed?!? + // template< class T, class U > - struct const_iterator_of< CArray > + struct range_iterator< const CArray > + { + typedef T* type; + }; + + template< class T, class U > + struct range_const_iterator< CArray > { typedef const T* type; }; template< class T, class U > - struct difference_type_of< CArray > + struct range_difference< CArray > { typedef std::ptrdiff_t type; }; template< class T, class U > - struct size_type_of< CArray > + struct range_size< CArray > { typedef int type; }; template< class T, class U > - struct value_type_of< CArray > + struct range_value< CArray > { typedef T type; }; diff --git a/include/boost/range/detail/mfc/cstring.hpp b/include/boost/range/detail/mfc/cstring.hpp index a420168..d3e9c04 100755 --- a/include/boost/range/detail/mfc/cstring.hpp +++ b/include/boost/range/detail/mfc/cstring.hpp @@ -17,43 +17,57 @@ #include // for CString #include -#include +#include namespace boost { - struct iterator_of< CString > + template<> + struct range_iterator< CString > { typedef TCHAR* type; }; - - struct const_iterator_of< CString > + + // + // Why is this needed?!? + // + template<> + struct range_iterator< const CString > + { + typedef TCHAR* type; + }; + + template<> + struct range_const_iterator< CString > { typedef const TCHAR* type; }; - - struct difference_type_of< CString > + + template<> + struct range_difference< CString > { typedef std::ptrdiff_t type; }; - - struct size_type_of< CString > + + template<> + struct range_size< CString > { typedef int type; }; - struct value_type_of< CString > + template<> + struct range_value< CString > { typedef TCHAR type; }; TCHAR* begin( CString& r ) { - return &r[0]; + return r.GetBuffer(0); } const TCHAR* begin( const CString& r ) { - return &r[0]; + return (LPCTSTR)r; } int size( const CString& r ) @@ -61,12 +75,12 @@ namespace boost return r.GetLength(); } - T* end( CString& r ) + TCHAR* end( CString& r ) { return begin( r ) + size( r ); } - const T* end( const CString& r ) + const TCHAR* end( const CString& r ) { return begin( r ) + size( r ); } diff --git a/test/mfc.cpp b/test/mfc.cpp index 5ce8af2..c429993 100755 --- a/test/mfc.cpp +++ b/test/mfc.cpp @@ -18,6 +18,18 @@ #endif #define BOOST_RANGE_ENABLE_MFC +#define BOOST_RANGE_ENABLE_MCF_CARRAY + +/* +#define WIN32 +#define _WINDOWS +#define _MBCS +#define _AFXDLL +#define _ATL_DLL +*/ + +///Od /D "WIN32" /D "_WINDOWS" /D "_DEBUG" /D "_MBCS" /D "_AFXDLL" /D "_ATL_DLL" /Gm /EHsc /RTC1 +// /MDd /Zc:wchar_t /Yu"stdafx.h" /Fp"Debug/Foo.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /Wp64 /ZI /TP #include #include @@ -25,9 +37,6 @@ #include #include -#include -#include -#include void check_mfc() @@ -36,7 +45,22 @@ void check_mfc() BOOST_CHECK( boost::begin( s ) + boost::size( s ) == boost::end( s ) ); BOOST_CHECK( boost::size( s ) == boost::size( "hello world" ) ); BOOST_CHECK( !boost::empty( s ) ); - + const CString cs( s ); + BOOST_CHECK( boost::begin( cs ) + boost::size( cs ) == boost::end( cs ) ); + BOOST_CHECK( boost::size( cs ) == boost::size( "hello world" ) ); + BOOST_CHECK( !boost::empty( cs ) ); + + CArray a; + BOOST_CHECK( boost::empty( a ) ); + a.Add( 5 ); + a.Add( 10 ); + BOOST_CHECK( boost::begin( a ) + boost::size( a ) == boost::end( a ) ); + BOOST_CHECK( boost::size( a ) == 2 ); + BOOST_CHECK( !boost::empty( a ) ); + const CArray& ca = a; + BOOST_CHECK( boost::begin( ca ) + boost::size( ca ) == boost::end( ca ) ); + BOOST_CHECK( boost::size( ca ) == 2 ); + BOOST_CHECK( !boost::empty( ca ) ); }