~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/utility/value_init.hpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// (C) 2002, Fernando Luis Cacciola Carballal.
 
2
//
 
3
// This material is provided "as is", with absolutely no warranty expressed
 
4
// or implied. Any use is at your own risk.
 
5
//
 
6
// Permission to use or copy this software for any purpose is hereby granted
 
7
// without fee, provided the above notices are retained on all copies.
 
8
// Permission to modify the code and to distribute modified code is granted,
 
9
// provided the above notices are retained, and a notice that the code was
 
10
// modified is included with the above copyright notice.
 
11
//
 
12
// 21 Ago 2002 (Created) Fernando Cacciola
 
13
//
 
14
#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
 
15
#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
 
16
 
 
17
#include "boost/detail/select_type.hpp"
 
18
#include "boost/type_traits/cv_traits.hpp"
 
19
 
 
20
namespace boost {
 
21
 
 
22
namespace vinit_detail {
 
23
 
 
24
template<class T>
 
25
class const_T_base
 
26
{
 
27
  protected :
 
28
 
 
29
   const_T_base() : x() {}
 
30
 
 
31
   T x ;
 
32
} ;
 
33
 
 
34
template<class T>
 
35
struct non_const_T_base
 
36
{
 
37
  protected :
 
38
 
 
39
   non_const_T_base() : x() {}
 
40
 
 
41
   mutable T x ;
 
42
} ;
 
43
 
 
44
template<class T>
 
45
struct select_base
 
46
{
 
47
  typedef typename
 
48
    detail::if_true< ::boost::is_const<T>::value >
 
49
      ::template then< const_T_base<T>, non_const_T_base<T> >::type type ;
 
50
} ;
 
51
 
 
52
} // namespace vinit_detail
 
53
 
 
54
template<class T>
 
55
class value_initialized : private vinit_detail::select_base<T>::type
 
56
{
 
57
  public :
 
58
 
 
59
    value_initialized() {}
 
60
 
 
61
    operator T&() const { return this->x ; }
 
62
 
 
63
    T& data() const { return this->x ; }
 
64
 
 
65
} ;
 
66
 
 
67
template<class T>
 
68
T const& get ( value_initialized<T> const& x )
 
69
{
 
70
  return x.data() ;
 
71
}
 
72
template<class T>
 
73
T& get ( value_initialized<T>& x )
 
74
{
 
75
  return x.data() ;
 
76
}
 
77
 
 
78
} // namespace boost
 
79
 
 
80
 
 
81
#endif
 
82