WeixiangYan/CodeTransOcean huggingface dataset:
Task: Parametric polymorphism

C: #include <stdio.h>
#include <stdlib.h>

#define decl_tree_type(T)                                                       \
        typedef struct node_##T##_t node_##T##_t, *node_##T;                    \
        struct node_##T##_t { node_##T left, right; T value; };                 \
                                                                                \
        node_##T node_##T##_new(T v) {                                          \
                node_##T node = malloc(sizeof(node_##T##_t));                   \
                node->value = v;                                                \
                node->left = node->right = 0;                                   \
                return node;                                                    \
        }                                                                       \
        node_##T node_##T##_insert(node_##T root, T v) {                        \
                node_##T n = node_##T##_new(v);                                 \
                while (root) {                                                  \
                        if (root->value < n->value)                             \
                                if (!root->left) return root->left = n;         \
                                else root = root->left;                         \
                        else                                                    \
                                if (!root->right) return root->right = n;       \
                                else root = root->right;                        \
                }                                                               \
                return 0;                                                       \
        }

#define tree_node(T) node_##T
#define node_insert(T, r, x) node_##T##_insert(r, x)
#define node_new(T, x) node_##T##_new(x)

decl_tree_type(double);
decl_tree_type(int);

int main()
{
        int i;
        tree_node(double) root_d = node_new(double, (double)rand() / RAND_MAX);

        for (i = 0; i < 10000; i++)
                node_insert(double, root_d, (double)rand() / RAND_MAX);

        tree_node(int) root_i = node_new(int, rand());
        for (i = 0; i < 10000; i++)
                node_insert(int, root_i, rand());

        return 0;
}










Fortran:       MODULE SORTSEARCH		

       INTERFACE FIND			
        MODULE PROCEDURE
     1   FINDI4,				
     2   FINDF4,FINDF8,				
     3          FINDTTI2,FINDTTI4		
       END INTERFACE FIND

      CONTAINS
      INTEGER FUNCTION FINDI4(THIS,NUMB,N)	
       USE ASSISTANCE		
       INTENT(IN) THIS,NUMB,N	
       INTEGER*4 THIS,NUMB(1:*)	
       INTEGER N		
       INTEGER L,R,P		
Chop away.
        L = 0			
        R = N + 1		
    1   P = (R - L)/2		
        IF (P.LE.0) THEN	
          FINDI4 = -L		
          RETURN		
        END IF			
        P = P + L		
        IF (THIS - NUMB(P)) 3,4,2	
    2   L = P			
        GO TO 1			
    3   R = P			
        GO TO 1			
Caught it
    4   FINDI4 = P		
      END FUNCTION FINDI4	

      END MODULE SORTSEARCH
Task: Parametric polymorphism





Java: public class Tree<T>{
	private T value;
	private Tree<T> left;
	private Tree<T> right;

	public void replaceAll(T value){
		this.value = value;
		if (left != null)
			left.replaceAll(value);
		if (right != null)
			right.replaceAll(value);
	}
}






Fortran:       MODULE SORTSEARCH		

       INTERFACE FIND			
        MODULE PROCEDURE
     1   FINDI4,				
     2   FINDF4,FINDF8,				
     3          FINDTTI2,FINDTTI4		
       END INTERFACE FIND

      CONTAINS
      INTEGER FUNCTION FINDI4(THIS,NUMB,N)	
       USE ASSISTANCE		
       INTENT(IN) THIS,NUMB,N	
       INTEGER*4 THIS,NUMB(1:*)	
       INTEGER N		
       INTEGER L,R,P		
Chop away.
        L = 0			
        R = N + 1		
    1   P = (R - L)/2		
        IF (P.LE.0) THEN	
          FINDI4 = -L		
          RETURN		
        END IF			
        P = P + L		
        IF (THIS - NUMB(P)) 3,4,2	
    2   L = P			
        GO TO 1			
    3   R = P			
        GO TO 1			
Caught it
    4   FINDI4 = P		
      END FUNCTION FINDI4	

      END MODULE SORTSEARCH
Task: Parametric polymorphism








VB: Class BinaryTree(Of T)
    ReadOnly Property Left As BinaryTree(Of T)
    ReadOnly Property Right As BinaryTree(Of T)
    ReadOnly Property Value As T

    Sub New(value As T, Optional left As BinaryTree(Of T) = Nothing, Optional right As BinaryTree(Of T) = Nothing)
        Me.Value = value
        Me.Left = left
        Me.Right = right
    End Sub

    Function Map(Of U)(f As Func(Of T, U)) As BinaryTree(Of U)
        Return New BinaryTree(Of U)(f(Me.Value), Me.Left?.Map(f), Me.Right?.Map(f))
    End Function

    Overrides Function ToString() As String
        Dim sb As New Text.StringBuilder()
        Me.ToString(sb, 0)
        Return sb.ToString()
    End Function

    Private Overloads Sub ToString(sb As Text.StringBuilder, depth As Integer)
        sb.Append(New String(ChrW(AscW(vbTab)), depth))
        sb.AppendLine(Me.Value?.ToString())
        Me.Left?.ToString(sb, depth + 1)
        Me.Right?.ToString(sb, depth + 1)
    End Sub
End Class

Module Program
    Sub Main()
        Dim b As New BinaryTree(Of Integer)(6, New BinaryTree(Of Integer)(5), New BinaryTree(Of Integer)(7))
        Dim b2 As BinaryTree(Of Double) = b.Map(Function(x) x * 0.5)

        Console.WriteLine(b)
        Console.WriteLine(b2)
    End Sub
End Module



Fortran:       MODULE SORTSEARCH		

       INTERFACE FIND			
        MODULE PROCEDURE
     1   FINDI4,				
     2   FINDF4,FINDF8,				
     3          FINDTTI2,FINDTTI4		
       END INTERFACE FIND

      CONTAINS
      INTEGER FUNCTION FINDI4(THIS,NUMB,N)	
       USE ASSISTANCE		
       INTENT(IN) THIS,NUMB,N	
       INTEGER*4 THIS,NUMB(1:*)	
       INTEGER N		
       INTEGER L,R,P		
Chop away.
        L = 0			
        R = N + 1		
    1   P = (R - L)/2		
        IF (P.LE.0) THEN	
          FINDI4 = -L		
          RETURN		
        END IF			
        P = P + L		
        IF (THIS - NUMB(P)) 3,4,2	
    2   L = P			
        GO TO 1			
    3   R = P			
        GO TO 1			
Caught it
    4   FINDI4 = P		
      END FUNCTION FINDI4	

      END MODULE SORTSEARCH
Task: Write float arrays to a text file



C#: using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var x = new double[] { 1, 2, 3, 1e11 };
        var y = new double[] { 1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791 };

        int xprecision = 3;
        int yprecision = 5;

        string formatString = "{0:G" + xprecision + "}\t{1:G" + yprecision + "}";

        using (var outf = new StreamWriter("FloatArrayColumns.txt"))
            for (int i = 0; i < x.Length; i++)
                outf.WriteLine(formatString, x[i], y[i]);
    }
}









Ada: with Ada.Text_IO;                       use Ada.Text_IO;
with Ada.Float_Text_IO;                 use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;

procedure Write_Float_Array is
   type Float_Array is array (1..4) of Float;
   procedure Write_Columns
             (  File   : File_Type;
                X      : Float_Array;
                Y      : Float_Array;
                X_Pres : Natural := 3;
                Y_Pres : Natural := 5
             ) is
   begin
      for I in Float_Array'range loop
         Put (File => File, Item => X(I), Fore => 1, Aft => X_Pres - 1);
         Put (File, " ");
         Put (File => File, Item => Y(I), Fore => 1, Aft => Y_Pres - 1);
         New_Line (File);
      end loop;
   end Write_Columns;
   
   File : File_Type;
   X : Float_Array := (1.0, 2.0, 3.0, 1.0e11);
   Y : Float_Array;
begin
   Put ("Tell us the file name to write:");
   Create (File, Out_File, Get_Line);
   for I in Float_Array'range loop
      Y(I) := Sqrt (X (I));
   end loop;
   Write_columns (File, X, Y);
   Close (File);
end Write_Float_Array;
Task: Write float arrays to a text file

C: #include <stdio.h>
#include <math.h>

int main(int argc, char **argv) {

   float x[4] = {1,2,3,1e11}, y[4];
   int i = 0;
   FILE *filePtr;

   filePtr = fopen("floatArray","w");

   for (i = 0; i < 4; i++) {
      y[i] = sqrt(x[i]);
      fprintf(filePtr, "%.3g\t%.5g\n", x[i], y[i]);
   }

   return 0;
}











Ada: with Ada.Text_IO;                       use Ada.Text_IO;
with Ada.Float_Text_IO;                 use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;

procedure Write_Float_Array is
   type Float_Array is array (1..4) of Float;
   procedure Write_Columns
             (  File   : File_Type;
                X      : Float_Array;
                Y      : Float_Array;
                X_Pres : Natural := 3;
                Y_Pres : Natural := 5
             ) is
   begin
      for I in Float_Array'range loop
         Put (File => File, Item => X(I), Fore => 1, Aft => X_Pres - 1);
         Put (File, " ");
         Put (File => File, Item => Y(I), Fore => 1, Aft => Y_Pres - 1);
         New_Line (File);
      end loop;
   end Write_Columns;
   
   File : File_Type;
   X : Float_Array := (1.0, 2.0, 3.0, 1.0e11);
   Y : Float_Array;
begin
   Put ("Tell us the file name to write:");
   Create (File, Out_File, Get_Line);
   for I in Float_Array'range loop
      Y(I) := Sqrt (X (I));
   end loop;
   Write_columns (File, X, Y);
   Close (File);
end Write_Float_Array;
Task: Write float arrays to a text file


C++: template<class InputIterator, class InputIterator2>
void writedat(const char* filename,
              InputIterator xbegin, InputIterator xend,
              InputIterator2 ybegin, InputIterator2 yend,
              int xprecision=3, int yprecision=5)
{
  std::ofstream f;
  f.exceptions(std::ofstream::failbit | std::ofstream::badbit);
  f.open(filename);
  for ( ; xbegin != xend and ybegin != yend; ++xbegin, ++ybegin)
    f << std::setprecision(xprecision) << *xbegin << '\t'
      << std::setprecision(yprecision) << *ybegin << '\n';
}










Ada: with Ada.Text_IO;                       use Ada.Text_IO;
with Ada.Float_Text_IO;                 use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;

procedure Write_Float_Array is
   type Float_Array is array (1..4) of Float;
   procedure Write_Columns
             (  File   : File_Type;
                X      : Float_Array;
                Y      : Float_Array;
                X_Pres : Natural := 3;
                Y_Pres : Natural := 5
             ) is
   begin
      for I in Float_Array'range loop
         Put (File => File, Item => X(I), Fore => 1, Aft => X_Pres - 1);
         Put (File, " ");
         Put (File => File, Item => Y(I), Fore => 1, Aft => Y_Pres - 1);
         New_Line (File);
      end loop;
   end Write_Columns;
   
   File : File_Type;
   X : Float_Array := (1.0, 2.0, 3.0, 1.0e11);
   Y : Float_Array;
begin
   Put ("Tell us the file name to write:");
   Create (File, Out_File, Get_Line);
   for I in Float_Array'range loop
      Y(I) := Sqrt (X (I));
   end loop;
   Write_columns (File, X, Y);
   Close (File);
end Write_Float_Array;
Task: Write float arrays to a text file




Go: package main

import (
    "fmt"
    "os"
)

var (
    x = []float64{1, 2, 3, 1e11}
    y = []float64{1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791}

    xprecision = 3
    yprecision = 5
)

func main() {
    if len(x) != len(y) {
        fmt.Println("x, y different length")
        return
    }
    f, err := os.Create("filename")
    if err != nil {
        fmt.Println(err)
        return
    }
    for i := range x {
        fmt.Fprintf(f, "%.*e, %.*e\n", xprecision-1, x[i], yprecision-1, y[i])
    }
    f.Close()
}








Ada: with Ada.Text_IO;                       use Ada.Text_IO;
with Ada.Float_Text_IO;                 use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;

procedure Write_Float_Array is
   type Float_Array is array (1..4) of Float;
   procedure Write_Columns
             (  File   : File_Type;
                X      : Float_Array;
                Y      : Float_Array;
                X_Pres : Natural := 3;
                Y_Pres : Natural := 5
             ) is
   begin
      for I in Float_Array'range loop
         Put (File => File, Item => X(I), Fore => 1, Aft => X_Pres - 1);
         Put (File, " ");
         Put (File => File, Item => Y(I), Fore => 1, Aft => Y_Pres - 1);
         New_Line (File);
      end loop;
   end Write_Columns;
   
   File : File_Type;
   X : Float_Array := (1.0, 2.0, 3.0, 1.0e11);
   Y : Float_Array;
begin
   Put ("Tell us the file name to write:");
   Create (File, Out_File, Get_Line);
   for I in Float_Array'range loop
      Y(I) := Sqrt (X (I));
   end loop;
   Write_columns (File, X, Y);
   Close (File);
end Write_Float_Array;
Task: Write float arrays to a text file





Java: import java.io.*;

public class FloatArray {
    public static void writeDat(String filename, double[] x, double[] y,
                                int xprecision, int yprecision)
        throws IOException {
        assert x.length == y.length;
        PrintWriter out = new PrintWriter(filename);
        for (int i = 0; i < x.length; i++)
            out.printf("%."+xprecision+"g\t%."+yprecision+"g\n", x[i], y[i]);
        out.close();
    }

    public static void main(String[] args) {
        double[] x = {1, 2, 3, 1e11};
        double[] y = new double[x.length];
        for (int i = 0; i < x.length; i++)
            y[i] = Math.sqrt(x[i]);
        
        try {
            writeDat("sqrt.dat", x, y, 3, 5);
        } catch (IOException e) {
            System.err.println("writeDat: exception: "+e);
        }

        try {
            BufferedReader br = new BufferedReader(new FileReader("sqrt.dat"));
            String line;
            while ((line = br.readLine()) != null)
                System.out.println(line);
        } catch (IOException e) { }
    }
}







Ada: with Ada.Text_IO;                       use Ada.Text_IO;
with Ada.Float_Text_IO;                 use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;

procedure Write_Float_Array is
   type Float_Array is array (1..4) of Float;
   procedure Write_Columns
             (  File   : File_Type;
                X      : Float_Array;
                Y      : Float_Array;
                X_Pres : Natural := 3;
                Y_Pres : Natural := 5
             ) is
   begin
      for I in Float_Array'range loop
         Put (File => File, Item => X(I), Fore => 1, Aft => X_Pres - 1);
         Put (File, " ");
         Put (File => File, Item => Y(I), Fore => 1, Aft => Y_Pres - 1);
         New_Line (File);
      end loop;
   end Write_Columns;
   
   File : File_Type;
   X : Float_Array := (1.0, 2.0, 3.0, 1.0e11);
   Y : Float_Array;
begin
   Put ("Tell us the file name to write:");
   Create (File, Out_File, Get_Line);
   for I in Float_Array'range loop
      Y(I) := Sqrt (X (I));
   end loop;
   Write_columns (File, X, Y);
   Close (File);
end Write_Float_Array;
Task: Write float arrays to a text file







Python: import itertools
def writedat(filename, x, y, xprecision=3, yprecision=5):
    with open(filename,'w') as f:
        for a, b in itertools.izip(x, y):
            print >> f, "%.*g\t%.*g" % (xprecision, a, yprecision, b)





Ada: with Ada.Text_IO;                       use Ada.Text_IO;
with Ada.Float_Text_IO;                 use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;

procedure Write_Float_Array is
   type Float_Array is array (1..4) of Float;
   procedure Write_Columns
             (  File   : File_Type;
                X      : Float_Array;
                Y      : Float_Array;
                X_Pres : Natural := 3;
                Y_Pres : Natural := 5
             ) is
   begin
      for I in Float_Array'range loop
         Put (File => File, Item => X(I), Fore => 1, Aft => X_Pres - 1);
         Put (File, " ");
         Put (File => File, Item => Y(I), Fore => 1, Aft => Y_Pres - 1);
         New_Line (File);
      end loop;
   end Write_Columns;
   
   File : File_Type;
   X : Float_Array := (1.0, 2.0, 3.0, 1.0e11);
   Y : Float_Array;
begin
   Put ("Tell us the file name to write:");
   Create (File, Out_File, Get_Line);
   for I in Float_Array'range loop
      Y(I) := Sqrt (X (I));
   end loop;
   Write_columns (File, X, Y);
   Close (File);
end Write_Float_Array;
Task: Write float arrays to a text file








VB: Public Sub main()
    x = [{1, 2, 3, 1e11}]
    y = [{1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791}]
    Dim TextFile As Integer
    TextFile = FreeFile
    Open "filename" For Output As TextFile
    For i = 1 To UBound(x)
        Print #TextFile, Format(x(i), "0.000E-000"), Format(y(i), "0.00000E-000")
    Next i
    Close TextFile
End Sub




Ada: with Ada.Text_IO;                       use Ada.Text_IO;
with Ada.Float_Text_IO;                 use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;

procedure Write_Float_Array is
   type Float_Array is array (1..4) of Float;
   procedure Write_Columns
             (  File   : File_Type;
                X      : Float_Array;
                Y      : Float_Array;
                X_Pres : Natural := 3;
                Y_Pres : Natural := 5
             ) is
   begin
      for I in Float_Array'range loop
         Put (File => File, Item => X(I), Fore => 1, Aft => X_Pres - 1);
         Put (File, " ");
         Put (File => File, Item => Y(I), Fore => 1, Aft => Y_Pres - 1);
         New_Line (File);
      end loop;
   end Write_Columns;
   
   File : File_Type;
   X : Float_Array := (1.0, 2.0, 3.0, 1.0e11);
   Y : Float_Array;
begin
   Put ("Tell us the file name to write:");
   Create (File, Out_File, Get_Line);
   for I in Float_Array'range loop
      Y(I) := Sqrt (X (I));
   end loop;
   Write_columns (File, X, Y);
   Close (File);
end Write_Float_Array;
Task: Write float arrays to a text file

C: #include <stdio.h>
#include <math.h>

int main(int argc, char **argv) {

   float x[4] = {1,2,3,1e11}, y[4];
   int i = 0;
   FILE *filePtr;

   filePtr = fopen("floatArray","w");

   for (i = 0; i < 4; i++) {
      y[i] = sqrt(x[i]);
      fprintf(filePtr, "%.3g\t%.5g\n", x[i], y[i]);
   }

   return 0;
}
Task: Write float arrays to a text file



C#: using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var x = new double[] { 1, 2, 3, 1e11 };
        var y = new double[] { 1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791 };

        int xprecision = 3;
        int yprecision = 5;

        string formatString = "{0:G" + xprecision + "}\t{1:G" + yprecision + "}";

        using (var outf = new StreamWriter("FloatArrayColumns.txt"))
            for (int i = 0; i < x.Length; i++)
                outf.WriteLine(formatString, x[i], y[i]);
    }
}
Task: Write float arrays to a text file


C++: template<class InputIterator, class InputIterator2>
void writedat(const char* filename,
              InputIterator xbegin, InputIterator xend,
              InputIterator2 ybegin, InputIterator2 yend,
              int xprecision=3, int yprecision=5)
{
  std::ofstream f;
  f.exceptions(std::ofstream::failbit | std::ofstream::badbit);
  f.open(filename);
  for ( ; xbegin != xend and ybegin != yend; ++xbegin, ++ybegin)
    f << std::setprecision(xprecision) << *xbegin << '\t'
      << std::setprecision(yprecision) << *ybegin << '\n';
}
Task: Write float arrays to a text file





Java: import java.io.*;

public class FloatArray {
    public static void writeDat(String filename, double[] x, double[] y,
                                int xprecision, int yprecision)
        throws IOException {
        assert x.length == y.length;
        PrintWriter out = new PrintWriter(filename);
        for (int i = 0; i < x.length; i++)
            out.printf("%."+xprecision+"g\t%."+yprecision+"g\n", x[i], y[i]);
        out.close();
    }

    public static void main(String[] args) {
        double[] x = {1, 2, 3, 1e11};
        double[] y = new double[x.length];
        for (int i = 0; i < x.length; i++)
            y[i] = Math.sqrt(x[i]);
        
        try {
            writeDat("sqrt.dat", x, y, 3, 5);
        } catch (IOException e) {
            System.err.println("writeDat: exception: "+e);
        }

        try {
            BufferedReader br = new BufferedReader(new FileReader("sqrt.dat"));
            String line;
            while ((line = br.readLine()) != null)
                System.out.println(line);
        } catch (IOException e) { }
    }
}
Task: Write float arrays to a text file







Python: import itertools
def writedat(filename, x, y, xprecision=3, yprecision=5):
    with open(filename,'w') as f:
        for a, b in itertools.izip(x, y):
            print >> f, "%.*g\t%.*g" % (xprecision, a, yprecision, b)
Task: Write float arrays to a text file








VB: Public Sub main()
    x = [{1, 2, 3, 1e11}]
    y = [{1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791}]
    Dim TextFile As Integer
    TextFile = FreeFile
    Open "filename" For Output As TextFile
    For i = 1 To UBound(x)
        Print #TextFile, Format(x(i), "0.000E-000"), Format(y(i), "0.00000E-000")
    Next i
    Close TextFile
End Sub
Task: Write float arrays to a text file




Go: package main

import (
    "fmt"
    "os"
)

var (
    x = []float64{1, 2, 3, 1e11}
    y = []float64{1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791}

    xprecision = 3
    yprecision = 5
)

func main() {
    if len(x) != len(y) {
        fmt.Println("x, y different length")
        return
    }
    f, err := os.Create("filename")
    if err != nil {
        fmt.Println(err)
        return
    }
    for i := range x {
        fmt.Fprintf(f, "%.*e, %.*e\n", xprecision-1, x[i], yprecision-1, y[i])
    }
    f.Close()
}
Task: Write float arrays to a text file



C#: using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var x = new double[] { 1, 2, 3, 1e11 };
        var y = new double[] { 1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791 };

        int xprecision = 3;
        int yprecision = 5;

        string formatString = "{0:G" + xprecision + "}\t{1:G" + yprecision + "}";

        using (var outf = new StreamWriter("FloatArrayColumns.txt"))
            for (int i = 0; i < x.Length; i++)
                outf.WriteLine(formatString, x[i], y[i]);
    }
}








Fortran: program writefloats
  implicit none

  real, dimension(10) :: a, sqrta
  integer :: i
  integer, parameter :: unit = 40 

  a = (/ (i, i=1,10) /)
  sqrta = sqrt(a)

  open(unit, file="xydata.txt", status="new", action="write")
  call writexy(unit, a, sqrta)
  close(unit)

contains

  subroutine writexy(u, x, y)
    real, dimension(:), intent(in) :: x, y
    integer, intent(in) :: u

    integer :: i

    write(u, "(2F10.4)") (x(i), y(i), i=lbound(x,1), ubound(x,1))
  end subroutine writexy

end program writefloats
Task: Write float arrays to a text file


C++: template<class InputIterator, class InputIterator2>
void writedat(const char* filename,
              InputIterator xbegin, InputIterator xend,
              InputIterator2 ybegin, InputIterator2 yend,
              int xprecision=3, int yprecision=5)
{
  std::ofstream f;
  f.exceptions(std::ofstream::failbit | std::ofstream::badbit);
  f.open(filename);
  for ( ; xbegin != xend and ybegin != yend; ++xbegin, ++ybegin)
    f << std::setprecision(xprecision) << *xbegin << '\t'
      << std::setprecision(yprecision) << *ybegin << '\n';
}









Fortran: program writefloats
  implicit none

  real, dimension(10) :: a, sqrta
  integer :: i
  integer, parameter :: unit = 40 

  a = (/ (i, i=1,10) /)
  sqrta = sqrt(a)

  open(unit, file="xydata.txt", status="new", action="write")
  call writexy(unit, a, sqrta)
  close(unit)

contains

  subroutine writexy(u, x, y)
    real, dimension(:), intent(in) :: x, y
    integer, intent(in) :: u

    integer :: i

    write(u, "(2F10.4)") (x(i), y(i), i=lbound(x,1), ubound(x,1))
  end subroutine writexy

end program writefloats