The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
const_clone.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef UTILS_CONST_CLONE_HPP_INCLUDED
16 #define UTILS_CONST_CLONE_HPP_INCLUDED
17 
18 #include <boost/type_traits.hpp>
19 #include <boost/utility/enable_if.hpp>
20 
21 namespace utils {
22 
23 /**
24  * Helper struct to clone the constness of one type to another.
25  *
26  * It's function is similar to the @ref tconst_duplicator, but a bit more
27  * flexible.
28  *
29  * @warning It seems @c *this in a const member function is not a const object,
30  * use @c this, which is a pointer to a const object.
31  *
32  * @tparam D The destination type, it should have no
33  * cv-qualifier and not be a pointer or
34  * reference.
35  * @tparam S The source type, this type may be a pointer
36  * or reference and obviously is allowed to have
37  * a cv-qualifier, although @c volatile has no
38  * effect.
39  * @tparam E The enable parameter for
40  * @ref boost::enable_if.
41  */
42 template<
43  class D
44  , class S
45  , typename E = void
46  >
48 {
49  /** The destination type, possibly const qualified. */
50  typedef D type;
51 
52  /** A reference to the destination type, possibly const qualified. */
53  typedef D& reference;
54 
55  /** A pointer to the destination type, possibly const qualified. */
56  typedef D* pointer;
57 };
58 
59 /**
60  * The specialised version of @ref tconst_clone.
61  *
62  * This version is used when the @p S is const-qualified.
63  */
64 template<
65  class D
66  , class S
67  >
68 struct tconst_clone<
69  D
70  , S
71  , typename boost::enable_if<
72  boost::is_const<
73  typename boost::remove_pointer<
74  typename boost::remove_reference<S>::type
75  >::type
76  >
77  >::type
78  >
79 {
80  typedef const D type;
81  typedef const D& reference;
82  typedef const D* pointer;
83 };
84 
85 } // namespace utils
86 
87 #endif
D & reference
A reference to the destination type, possibly const qualified.
Definition: const_clone.hpp:53
D * pointer
A pointer to the destination type, possibly const qualified.
Definition: const_clone.hpp:56
Helper struct to clone the constness of one type to another.
Definition: const_clone.hpp:47
D type
The destination type, possibly const qualified.
Definition: const_clone.hpp:50
#define S(x)
Definition: luac.cpp:374