Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
from_to_dispatch_concept.cc
1 #include <iostream>
2 
3 template <typename E>
4 struct Base {};
5 
6 template <typename T>
7 struct Derived : Base <Derived<T> > {};
8 
9 template <typename E>
10 E exact(Base<E>)
11 {
12  return E();
13 }
14 
15 // namespace plop
16 // {
17 
18  template <typename E>
19  void test(Base<E>)
20  {
21  std::cout << "base" << std::endl;
22  }
23 
24 
25 // }
26 
27 template <typename E>
28 void calltest(Base<E> v)
29 {
30 // using namespace plop;
31  test(exact(v));
32 }
33 
34 int main()
35 {
36  Derived<int> v;
37  calltest(v);
38 }
39 
40 
41 // The following function shall not be considered by g++ if it is
42 // located in a namespace different from its first argument's
43 // namespace. This is conform to the c++ standard. This example shows
44 // the importance of having from_to_ overloads in milena in the same
45 // namespace as their first argument. Doing so allows the user to add
46 // new from_to_ functions in its own code and extend the conversion
47 // mecanism in Milena.
48 
49 // namespace plop
50 // {
51 
52  template <typename T>
53  void test(Derived<T>)
54  {
55  std::cout << "derived" << std::endl;
56  }
57 
58 
59 // }