00001 // (C) 2002, Fernando Luis Cacciola Carballal. 00002 // 00003 // Distributed under the Boost Software License, Version 1.0. (See 00004 // accompanying file LICENSE_1_0.txt or copy at 00005 // http://www.boost.org/LICENSE_1_0.txt) 00006 // 00007 // 21 Ago 2002 (Created) Fernando Cacciola 00008 // 00009 #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP 00010 #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP 00011 00012 #include "sysc/packages/boost/detail/select_type.hpp" 00013 #include "sysc/packages/boost/type_traits/cv_traits.hpp" 00014 00015 namespace boost { 00016 00017 namespace vinit_detail { 00018 00019 template<class T> 00020 class const_T_base 00021 { 00022 protected : 00023 00024 const_T_base() : x() {} 00025 00026 T x ; 00027 } ; 00028 00029 template<class T> 00030 struct non_const_T_base 00031 { 00032 protected : 00033 00034 non_const_T_base() : x() {} 00035 00036 mutable T x ; 00037 } ; 00038 00039 template<class T> 00040 struct select_base 00041 { 00042 typedef typename 00043 detail::if_true< ::boost::is_const<T>::value > 00044 ::template then< const_T_base<T>, non_const_T_base<T> >::type type ; 00045 } ; 00046 00047 } // namespace vinit_detail 00048 00049 template<class T> 00050 class value_initialized : private vinit_detail::select_base<T>::type 00051 { 00052 public : 00053 00054 value_initialized() {} 00055 00056 operator T&() const { return this->x ; } 00057 00058 T& data() const { return this->x ; } 00059 00060 } ; 00061 00062 template<class T> 00063 T const& get ( value_initialized<T> const& x ) 00064 { 00065 return x.data() ; 00066 } 00067 template<class T> 00068 T& get ( value_initialized<T>& x ) 00069 { 00070 return x.data() ; 00071 } 00072 00073 } // namespace boost 00074 00075 00076 #endif 00077
1.5.5