source: NonGTP/Boost/boost/utility/value_init.hpp @ 857

Revision 857, 1.4 KB checked in by igarcia, 19 years ago (diff)
Line 
1// (C) 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
15namespace boost {
16
17namespace vinit_detail {
18
19template<class T>
20class const_T_base
21{
22  protected :
23
24   const_T_base() : x() {}
25
26   T x ;
27} ;
28
29template<class T>
30struct non_const_T_base
31{
32  protected :
33
34   non_const_T_base() : x() {}
35
36   mutable T x ;
37} ;
38
39template<class T>
40struct select_base
41{
42  typedef typename
43    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
49template<class T>
50class 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
62template<class T>
63T const& get ( value_initialized<T> const& x )
64{
65  return x.data() ;
66}
67template<class T>
68T& 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.