1// Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
2
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifdef BOOST_QVM_TEST_SINGLE_HEADER
7# include BOOST_QVM_TEST_SINGLE_HEADER
8#else
9# include <boost/qvm/deduce_vec.hpp>
10#endif
11
12template <class T,class U>
13struct same_type;
14
15template <class T>
16struct
17same_type<T,T>
18 {
19 };
20
21template <class A,class B,int D,class Result>
22struct
23check
24 {
25 same_type<typename boost::qvm::deduce_vec2<A,B,D>::type,Result> a;
26 same_type<typename boost::qvm::deduce_vec2<B,A,D>::type,Result> b;
27 };
28
29template <class T,int D> struct v1;
30template <class T,int D> struct v2;
31
32namespace
33boost
34 {
35 namespace
36 qvm
37 {
38 template <class T,int D>
39 struct
40 vec_traits< v1<T,D> >
41 {
42 typedef T scalar_type;
43 static int const dim=D;
44 };
45
46 template <class T,int D>
47 struct
48 vec_traits< v2<T,D> >
49 {
50 typedef T scalar_type;
51 static int const dim=D;
52 };
53
54 template <int D,class S,int V2D,class V2S>
55 struct
56 deduce_vec<v2<V2S,V2D>,D,S>
57 {
58 typedef v2<S,D> type;
59 };
60
61 template <int D,class S,class AS,int AD,class BS,int BD>
62 struct
63 deduce_vec2<v2<AS,AD>,v2<BS,BD>,D,S>
64 {
65 typedef v2<S,D> type;
66 };
67 }
68 }
69
70int
71main()
72 {
73 same_type< boost::qvm::deduce_vec< v1<int,3> >::type, v1<int,3> >();
74 same_type< boost::qvm::deduce_vec< v1<int,3>, 4 >::type, boost::qvm::vec<int,4> >();
75 check< v1<int,3>, v1<int,3>, 3, v1<int,3> >();
76 check< v1<int,3>, v1<float,3>, 4, boost::qvm::vec<float,4> >();
77
78 same_type< boost::qvm::deduce_vec< v2<int,3> >::type, v2<int,3> >();
79 same_type< boost::qvm::deduce_vec< v2<int,3>, 4 >::type, v2<int,4> >();
80 check< v2<int,3>, v2<int,3>, 3, v2<int,3> >();
81 check< v2<int,3>, v2<float,3>, 4, v2<float,4> >();
82 }
83

source code of boost/libs/qvm/test/deduce_vec_test.cpp