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