项目作者: SunMaungOo

项目描述 :
C# port of Standard Template Library (STL)
高级语言: C#
项目地址: git://github.com/SunMaungOo/LibNavigate.git
创建时间: 2019-12-17T21:09:11Z
项目社区:https://github.com/SunMaungOo/LibNavigate

开源协议:MIT License

下载


LibNavigate

Build status

C# port of Standard Template Library (STL)

Attempt on porting C++ STL library to C#.

Please notice some of the algorithm from STL are not ported to C#

Most of your time using the library is in implementation InputIterator ( to get the data from) and the OutputIterator to output the data. Therefore you need to be familiar with the InputIterator type and OutputIterator type.

There are only two namespace (LibNavigate.Iterator and LibNavigate.Iterator.Extend) you need to know in implementation.LibNavigate.Iterator contains the interface of the iterator and LibNavigate.Iterator.Extend contains the default implementation of iterator.

  1. IIteratorBase = base type of all iterator
  2. IInputIterator = base type of input iterator
  3. IOutputIterator = base type of output iterator
  4. IForwardIterator = base type of iterator which both read and write
  5. IBidirectionalIterator = base type of iterator which goes both way (forward and backward)
  6. IRandomAccessIterator = base type of iterator which can have random access
  7. OutputIterator = generic output iterator
  8. ConsoleOutputIterator = output to console
  9. FileOutputIterator = output to file
  10. MultiOutputIterator = output to multiple source
  11. OutputIteratorAdapter = change output to another type
  12. BackInsertIterator = output to collection
  13. FileInputIterator = read from file and convert data
  14. SimpleFileInputIterator = read from file
  15. InputIteratorAdapter = change input to another type
  16. RangeInputIterator = read data only from certain range
  17. LimitInputIterator = subset the input
  18. InputIterator = default implementation of IInputIterator
  19. ForwardIterator = default implementation of IForwardIterator
  20. BidirectionalIterator = default implementation of IBidirectionalIterator
  21. RandomAccessIterator = default implementation of IRandomAccessIterator

Usage

  1. // Copying data from input to output
  2. int[] data = { 1, 2, 3 };
  3. IList<int> lst = new List<int>();
  4. using (IInputIterator<int> inputIterator = new InputIterator<int>(data))
  5. {
  6. using(IOutputIterator<int> outputIterator=new BackInsertIterator<int>(lst))
  7. {
  8. Algorithm.Copy(inputIterator, outputIterator);
  9. }
  10. }
  11. //Display the data into the Console
  12. int[] data = { 1, 2, 3 };
  13. using (IInputIterator<int> inputIterator = new InputIterator<int>(data))
  14. {
  15. using(IOutputIterator<int> outputIterator=new ConsoleOutputIterator<int>())
  16. {
  17. Algorithm.Copy(inputIterator, outputIterator);
  18. }
  19. }

Documentation

The best place to find documentation about STL is in https://en.cppreference.com/w/cpp/header/algorithm

Differences

There are some thing what is different from C++ STL.I have made the resource cleanup part explicit. In C++ it is your choice whether you put a destructor or not. In my port, I have add IDisposable interface which force you think about resource management (you can still ignore it if you want).

Since there is no concept of moving (std::move) in C# , I have add an interface IRemoveable which implementation need to remove the current element in the iterator.

For cloning method , there is two interface IShallowClone which does not clone the underlying data and IPartialClone which clone the underlying data.

Alternative project

https://sourceforge.net/projects/cstl/