xref: /haiku/headers/private/shared/TypeOperation.h (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2014, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Based on TypeOp in "C++-Templates, The Complete Guide", which is
6  * Copyright 2003 by Pearson Education, Inc.
7  */
8 #ifndef _TYPE_OPERATION_H
9 #define _TYPE_OPERATION_H
10 
11 namespace BPrivate {
12 
13 
14 // Generic type conversion operations.
15 template<typename T>
16 class TypeOperation {
17 public:
18 	typedef T					ArgT;
19 	typedef T					BareT;
20 	typedef T const				ConstT;
21 
22 	typedef T&					RefT;
23 	typedef T&					BareRefT;
24 	typedef T const&			ConstRefT;
25 };
26 
27 
28 // Specialization for constant types.
29 template<typename T>
30 class TypeOperation<T const> {
31 public:
32 	typedef T const				ArgT;
33 	typedef T					BareT;
34 	typedef T const				ConstT;
35 
36 	typedef T const&			RefT;
37 	typedef T&					BareRefT;
38 	typedef T const&			ConstRefT;
39 };
40 
41 
42 // Specialization for reference types.
43 template<typename T>
44 class TypeOperation<T&> {
45 public:
46 	typedef T&									ArgT;
47 	typedef typename TypeOperation<T>::BareT	BareT;
48 	typedef T const								ConstT;
49 
50 	typedef T&									RefT;
51 	typedef typename TypeOperation<T>::BareRefT	BareRefT;
52 	typedef T const&							ConstRefT;
53 };
54 
55 
56 // Specialization for void.
57 template<>
58 class TypeOperation<void> {
59 public:
60 	typedef void				ArgT;
61 	typedef void				BareT;
62 	typedef void const			ConstT;
63 
64 	typedef void				RefT;
65 	typedef void				BareRefT;
66 	typedef void				ConstRefT;
67 };
68 
69 
70 }	// namespace BPrivate
71 
72 
73 using BPrivate::TypeOperation;
74 
75 
76 #endif	// _TYPE_OPERATION_H
77