1 #include <CGAL/Coercion_traits.h>
2 #include <CGAL/Quotient.h>
3 #include <CGAL/Sqrt_extension.h>
4 #include <CGAL/IO/io.h>
5
6 // this is the implementation for ExplicitInteroperable types
7 template <typename A, typename B>
8 typename CGAL::Coercion_traits<A,B>::Type
binary_function_(const A & a,const B & b,CGAL::Tag_false)9 binary_function_(const A& a , const B& b, CGAL::Tag_false){
10 std::cout << "Call for ExplicitInteroperable types: " << std::endl;
11 typedef CGAL::Coercion_traits<A,B> CT;
12 typename CT::Cast cast;
13 return cast(a)*cast(b);
14 }
15
16 // this is the implementation for ImplicitInteroperable types
17 template <typename A, typename B>
18 typename CGAL::Coercion_traits<A,B>::Type
binary_function_(const A & a,const B & b,CGAL::Tag_true)19 binary_function_(const A& a , const B& b, CGAL::Tag_true){
20 std::cout << "Call for ImpicitInteroperable types: " << std::endl;
21 return a*b;
22 }
23
24 // this function selects the correct implementation
25 template <typename A, typename B>
26 typename CGAL::Coercion_traits<A,B>::Type
binary_func(const A & a,const B & b)27 binary_func(const A& a , const B& b){
28 typedef CGAL::Coercion_traits<A,B> CT;
29 typedef typename CT::Are_implicit_interoperable Are_implicit_interoperable;
30 return binary_function_(a,b,Are_implicit_interoperable());
31 }
32
main()33 int main(){
34 CGAL::IO::set_pretty_mode(std::cout);
35
36 // Function call for ImplicitInteroperable types
37 std::cout<< binary_func(double(3), int(5)) << std::endl;
38
39 // Function call for ExplicitInteroperable types
40 CGAL::Quotient<int> rational(1,3); // == 1/3
41 CGAL::Sqrt_extension<int,int> extension(1,2,3); // == 1+2*sqrt(3)
42 CGAL::Sqrt_extension<CGAL::Quotient<int>,int> result = binary_func(rational, extension);
43 std::cout<< result << std::endl;
44
45 return 0;
46 }
47