LCOV - code coverage report
Current view: top level - data/test - template_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 14 14 100.0 %
Date: 2024-04-19 03:43:27 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Wieger Wesselink
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : /// \file template_test.cpp
      10             : /// \brief Template tests.
      11             : 
      12             : #define BOOST_TEST_MODULE template_test
      13             : #include <boost/test/included/unit_test.hpp>
      14             : #include <iostream>
      15             : 
      16             : template <typename Derived>
      17             : class data_traverser
      18             : {};
      19             : 
      20             : template <typename Derived, template <typename> class Traverser = data_traverser>
      21             : class lps_traverser: public Traverser<Derived>
      22             : {};
      23             : 
      24             : template <template <typename> class Traverser = data_traverser>
      25             : struct find_helper: public Traverser<find_helper<Traverser> >
      26             : {
      27           2 :   void print() const
      28             :   {
      29           2 :     std::cout << "hello, world!" << std::endl;
      30           2 :   }
      31             : };
      32             : 
      33             : template <template <typename> class Traverser>
      34           2 : find_helper<Traverser> make_find_helper()
      35             : {
      36           2 :   return find_helper<Traverser>();
      37             : }
      38             : 
      39             : template <template <typename> class Traverser>
      40           2 : void f1()
      41             : {
      42           2 :   std::cout << "hello, world!" << std::endl;
      43           2 : }
      44             : 
      45             : template <template <typename, typename> class Traverser>
      46             : void f2()
      47             : {
      48             :   std::cout << "hello, world!" << std::endl;
      49             : }
      50             : 
      51             : //-------------------------------------------------------------//
      52             : template <typename Derived>
      53             : class lps_traverser2: public data_traverser<Derived>
      54             : {};
      55             : 
      56           2 : BOOST_AUTO_TEST_CASE(test_main)
      57             : {
      58           1 :   make_find_helper<data_traverser>().print();
      59           1 :   f1<data_traverser>();
      60             : 
      61             :   //--- The intended usage pattern does not compile ---//
      62             :   // make_find_helper<lps_traverser>().print();
      63             :   //f1<lps_traverser>();
      64             : 
      65             :   //--- This also doesn't compile ---//
      66             :   //f2<lps_traverser>();
      67             : 
      68             :   //--- But this does compile ---//
      69           1 :   make_find_helper<lps_traverser2>().print();
      70           1 :   f1<lps_traverser2>();
      71           1 : }

Generated by: LCOV version 1.14