小编ZSw*_*wat的帖子

你如何在Ada中为向量实现Generic_Sorting?

我正在尝试从许多月前做一些旧C++代码的基本翻译来学习Ada,我一直对如何使用内置Generic_Sorting对矢量进行排序感到困惑.我还没有找到任何具体的实际例子,最接近现在已经不复存在的丹麦维基文章看起来好像有一个完整的例子,但存档没有抓住它:https:// web.archive.org/web/20100222010428/http://wiki.ada-dk.org/index.php/Ada.Containers.Vectors#Vectors.Generic_Sorting

这是我认为应该从上面的链接工作的代码:

with Ada.Integer_Text_IO;    use Ada.Integer_Text_IO;
with Ada.Strings.Unbounded;  use Ada.Strings.Unbounded;
with Ada.Containers.Vectors; use Ada.Containers;

procedure Vectortest is
   package IntegerVector is new Vectors
     (Index_Type   => Natural,
      Element_Type => Integer);
   package IVSorter is new Generic_Sorting;

   IntVec : IntegerVector.Vector;
   Cursor : IntegerVector.Cursor;
begin
   IntVec.Append(3);
   IntVec.Append(43);
   IntVec.Append(34);
   IntVec.Append(8);

   IVSorter.Sort(Container => IntVec);

   Cursor := IntegerVector.First(Input);
   while IntegerVector.Has_Element(Cursor) loop
      Put(IntegerVector.Element(Cursor));
      IntegerVector.Next(Cursor);
   end loop;

end Vectortest;
Run Code Online (Sandbox Code Playgroud)

我试过这么多不同的组合usewith,但所有我能得到的各种错误代码.上面的代码给出了Generic_Sorting is not visible,但是当我尝试明确说明with Ada.Containers.Vectors.Generic_Sorting我得到了错误"Ada.Containers.Vectors.Generic_Sorting" is not a predefined library …

ada gnat gnat-gps ada2012

4
推荐指数
1
解决办法
134
查看次数

标签 统计

ada ×1

ada2012 ×1

gnat ×1

gnat-gps ×1