File: template_test.cpp

package info (click to toggle)
mcrl2 201409.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd
  • size: 46,348 kB
  • ctags: 29,960
  • sloc: cpp: 213,160; ansic: 16,219; python: 13,238; yacc: 309; lex: 214; xml: 197; makefile: 83; sh: 82; pascal: 17
file content (72 lines) | stat: -rwxr-xr-x 1,762 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Author(s): Wieger Wesselink
// Copyright: see the accompanying file COPYING or copy at
// https://svn.win.tue.nl/trac/MCRL2/browser/trunk/COPYING
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
/// \file template_test.cpp
/// \brief Template tests.

#include <iostream>
#include <boost/test/minimal.hpp>

template <typename Derived>
class data_traverser
{};

template <typename Derived, template <typename> class Traverser = data_traverser>
class lps_traverser: public Traverser<Derived>
{};

template <template <typename> class Traverser = data_traverser>
struct find_helper: public Traverser<find_helper<Traverser> >
{
  void print() const
  {
    std::cout << "hello, world!" << std::endl;
  }
};

template <template <typename> class Traverser>
find_helper<Traverser> make_find_helper()
{
  return find_helper<Traverser>();
}

template <template <typename> class Traverser>
void f1()
{
  std::cout << "hello, world!" << std::endl;
}

template <template <typename, typename> class Traverser>
void f2()
{
  std::cout << "hello, world!" << std::endl;
}

//-------------------------------------------------------------//
template <typename Derived>
class lps_traverser2: public data_traverser<Derived>
{};

int test_main(int /*argc*/, char** /*argv[]*/)
{
  make_find_helper<data_traverser>().print();
  f1<data_traverser>();

  //--- The intended usage pattern does not compile ---//
  // make_find_helper<lps_traverser>().print();
  //f1<lps_traverser>();

  //--- This also doesn't compile ---//
  //f2<lps_traverser>();

  //--- But this does compile ---//
  make_find_helper<lps_traverser2>().print();
  f1<lps_traverser2>();

  return 0;
}