Last change
on this file since 35 was
29,
checked in by landauf, 17 years ago
|
updated boost from 1_33_1 to 1_34_1
|
File size:
1.3 KB
|
Rev | Line | |
---|
[29] | 1 | // Copyright 2002, Fernando Luis Cacciola Carballal. |
---|
| 2 | // |
---|
| 3 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
| 4 | // accompanying file LICENSE_1_0.txt or copy at |
---|
| 5 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
| 6 | // |
---|
| 7 | // 21 Ago 2002 (Created) Fernando Cacciola |
---|
| 8 | // |
---|
| 9 | #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP |
---|
| 10 | #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP |
---|
| 11 | |
---|
| 12 | #include "boost/detail/select_type.hpp" |
---|
| 13 | #include "boost/type_traits/cv_traits.hpp" |
---|
| 14 | |
---|
| 15 | namespace boost { |
---|
| 16 | |
---|
| 17 | namespace vinit_detail { |
---|
| 18 | |
---|
| 19 | template<class T> |
---|
| 20 | class const_T_base |
---|
| 21 | { |
---|
| 22 | protected : |
---|
| 23 | |
---|
| 24 | const_T_base() : x() {} |
---|
| 25 | |
---|
| 26 | T x ; |
---|
| 27 | } ; |
---|
| 28 | |
---|
| 29 | template<class T> |
---|
| 30 | struct non_const_T_base |
---|
| 31 | { |
---|
| 32 | protected : |
---|
| 33 | |
---|
| 34 | non_const_T_base() : x() {} |
---|
| 35 | |
---|
| 36 | mutable T x ; |
---|
| 37 | } ; |
---|
| 38 | |
---|
| 39 | template<class T> |
---|
| 40 | struct select_base |
---|
| 41 | { |
---|
| 42 | typedef typename |
---|
| 43 | boost::detail::if_true< ::boost::is_const<T>::value > |
---|
| 44 | ::template then< const_T_base<T>, non_const_T_base<T> >::type type ; |
---|
| 45 | } ; |
---|
| 46 | |
---|
| 47 | } // namespace vinit_detail |
---|
| 48 | |
---|
| 49 | template<class T> |
---|
| 50 | class value_initialized : private vinit_detail::select_base<T>::type |
---|
| 51 | { |
---|
| 52 | public : |
---|
| 53 | |
---|
| 54 | value_initialized() {} |
---|
| 55 | |
---|
| 56 | operator T&() const { return this->x ; } |
---|
| 57 | |
---|
| 58 | T& data() const { return this->x ; } |
---|
| 59 | |
---|
| 60 | } ; |
---|
| 61 | |
---|
| 62 | template<class T> |
---|
| 63 | T const& get ( value_initialized<T> const& x ) |
---|
| 64 | { |
---|
| 65 | return x.data() ; |
---|
| 66 | } |
---|
| 67 | template<class T> |
---|
| 68 | T& get ( value_initialized<T>& x ) |
---|
| 69 | { |
---|
| 70 | return x.data() ; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | } // namespace boost |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | #endif |
---|
| 77 | |
---|
Note: See
TracBrowser
for help on using the repository browser.