To: J3 J3/23-188 From: Brad Richardson Subject: Possible Solutions to Long Templates Date: 2023-June-13 #Reference: Introduction: ------------- As many plenary members have observed, the CONTAINS section of template definitions appears in the specification section of their surrounding scope. For larger templates and especially in the case of nested templates, this can significantly impair the legibility of the source code. Note that the "obvious" analog of SUBMODULE does not work for technical reasons. Subgroup intends to explore mechanisms to improve this situation. As example, consider a template like the following: TEMPLATE A(T, plus) REQUIRES binary_op(T, plus) TEMPLATE B(times) REQUIRES binary_op(T, times) CONTAINS PURE FUNCTION product(array) TYPE(T), intent(in) :: array(:) TYPE(T) :: product INTEGER :: i product = array(1) DO i = 2, size(array) product = times(product, array(i)) END DO END FUNCTION END TEMPLATE CONTAINS PURE FUNCTION sum(array) TYPE(T), intent(in) :: array(:) TYPE(T) :: sum INTEGER :: i sum = array(1) DO i = 2, size(array) sum = plus(sum, array(i)) END DO END FUNCTION END TEMPLATE The important contents of the outer template, A, appear after the contents of the inner template B, which causes it to be difficult to read and understand the purpose of the outer template.