Freigeben über


STL/CLR in Visual Studio codename Orcas March CTP

If you have not noticed yet, March CTP of Visual Studio Orcas has been released. It is available as Virtual PC image or as a self-extracting install. It contains a major refresh of STL/CLR with many bug fixes and two new adapters. Both of them help with data exchange between STL/CLR container and .Net container that implements .Net Collection interfaces.

 

First, let me introduce collection adapter. BCL collections adapter provides a unified mechanism to adapt IEnumerable, ICollection, IList and IDictionary interfaces and their generic counterparts as an STL/CLR container. These adapters provide iterator implementations and methods that are compatible with STL/CLR algorithms. Both adapters and iterators can only be used within one assembly and it is not supported to pass them to another assembly. Each adapter implements three basic methods:

- begin() - returns iterator that points to the first element in the collection. Type of iterator is ForwardIterator for IEnumerable and ICollection; RandomAccessIterator for IList and BidirectionalIterator for IDictionary.

- end() - returns iterator that addresses the location succeeding the last element. Type of iterator is ForwardIterator for IEnumerable and ICollection, RandomAccessIterator for IList and BidirectionalIterator for IDictionary

- size() - returns number of elements stored in the BCL collection. Not available in collection_adapter<> of IEnumerable and IEnumerable<T>

An example of using this adapter is below:

 

#include <cliext\list>

#include <cliext\adapter>

...

void MyFunction7(Generic:: IList<int>^ list )

{

    cliext::collection_adapter< Generic::IList<int> > cont( list );

 

    cliext::list<int> myList( cont.size() );

 

    cliext::transform( cont.begin(), cont.end() , myList.begin(),

                        cliext::bind2nd(cliext::plus<int>(),2));

}

 

Second adapter is designed to help with data exchange in opposite direction. make_collection<>() represents a pair of iterators as .Net ICollection or IEnumerable interface. A call to make_collectio<>() returns a class range_adapter which implements ICollection and IEnumerable interfaces and their generic versions. Range adapter can be applied to both template and generic iterators. Same as collection adapter, range adapter does not copy data from the original container. Range adapter can only be used for reading data from the original STL/CLR container. An example of using it is below:

 

#include <cliext\vector>

#include <cliext\adapter>

...

      cliext::vector<String^> vect1;

      cliext::vector<String^>::iterator itFirst = vect1.begin();

      cliext::vector<String^>::iterator itLast = vect1.end();

...

      ICollection^ piColl = cliext::make_collection (itFirst, itLast);

...

      Generic::ICollection<String^> ^ piColl2 = cliext::make_collection (itFirst, itLast);

 

The design specification has more details, it is going to be uploaded later this month to here: https://msdn2.microsoft.com/en-us/vstudio/aa948851.aspx

Comments

  • Anonymous
    March 01, 2007
    Orcas March CTP から、ATL Serverが除去 - ATL Server