!! Support for ordered pairs of integers.
!! (A simple example for f90doc.)
!!
!! For example, you can create the pair p = (10,20) with the following code:
!!>    type (pair) :: p
!!     p%a = 10
!!<    p%b = 20
!!
!! @author Erik Demaine
!! @version simple
module ordered_pair
   private

   !! Every pair has two parts,
   !!     - the _left_ element and
   !!     - the _right_ element.
   type pair
      integer :: a      !! The left element in the pair.
      integer :: b      !! The right element in the pair.
   end type pair

   !! This interface allows one to try to reverse an integer as well as
   !! a pair.  Reversing the integer does nothing.
   interface reverse
      module procedure reverse_pair
      module procedure reverse_int
   end interface reverse

   public :: pair, reverse

contains

   !! Reversal routine for a pair of integers.  Swaps them in-place.
   subroutine reverse_pair (p)
      type (pair), intent (inout) :: p  !! The pair to reverse
      integer :: temp

      temp = p%a
      p%a = p%b
      p%b = temp
   end subroutine reverse_pair

   !! Reversal routine for an integer.  Does *nothing*.
   subroutine reverse_int (i)
      integer, intent (in) :: i
   end subroutine

end module ordered_pair
