imgtools/imglib/boostlibrary/boost/optional/optional.hpp
author kelvzhu
Thu, 08 Jul 2010 11:07:48 +0800
changeset 611 75fabbc53db5
parent 600 6d08f4a05d93
permissions -rw-r--r--
Release-Update
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
// Use, modification, and distribution is subject to the Boost Software
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
// http://www.boost.org/LICENSE_1_0.txt)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
// See http://www.boost.org/lib/optional for documentation.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
// You are welcome to contact the author at:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
//  fernando_cacciola@hotmail.com
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
#ifndef BOOST_OPTIONAL_OPTIONAL_FLC_19NOV2002_HPP
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
#define BOOST_OPTIONAL_OPTIONAL_FLC_19NOV2002_HPP
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
#include<new>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
#include<algorithm>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#include "boost/config.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#include "boost/assert.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include "boost/type.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include "boost/type_traits/alignment_of.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
#include "boost/type_traits/type_with_alignment.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#include "boost/type_traits/remove_reference.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#include "boost/type_traits/is_reference.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
#include "boost/mpl/if.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
#include "boost/mpl/bool.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
#include "boost/mpl/not.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
#include "boost/detail/reference_content.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
#include "boost/none.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
#include "boost/utility/compare_pointees.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
#include "boost/optional/optional_fwd.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
#if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
// VC6.0 has the following bug:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
//   When a templated assignment operator exist, an implicit conversion
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
//   constructing an optional<T> is used when assigment of the form:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
//     optional<T> opt ; opt = T(...);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
//   is compiled.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
//   However, optional's ctor is _explicit_ and the assignemt shouldn't compile.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
//   Therefore, for VC6.0 templated assignment is disabled.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
#define BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
#if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
// VC7.0 has the following bug:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
//   When both a non-template and a template copy-ctor exist
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
//   and the templated version is made 'explicit', the explicit is also
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
//   given to the non-templated version, making the class non-implicitely-copyable.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
#define BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) || BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION,<=700)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
// AFAICT only VC7.1 correctly resolves the overload set
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
// that includes the in-place factory taking functions,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
// so for the other VC versions, in-place factory support
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
// is disabled
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
#define BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
// BCB (5.5.1) cannot parse the nested template struct in an inplace factory.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
#define BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
#if !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) \
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
    && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581) )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
// BCB (up to 5.64) has the following bug:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
//   If there is a member function/operator template of the form
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
//     template<class Expr> mfunc( Expr expr ) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
//   some calls are resolved to this even if there are other better matches.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
//   The effect of this bug is that calls to converting ctors and assignments
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
//   are incrorrectly sink to this general catch-all member function template as shown above.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
#define BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
// Daniel Wallin discovered that bind/apply.hpp badly interacts with the apply<>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
// member template of a factory as used in the optional<> implementation.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
// He proposed this simple fix which is to move the call to apply<> outside
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
// namespace boost.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
namespace boost_optional_detail
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
  template <class T, class Factory>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
  void construct(Factory const& factory, void* address)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
  {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
    factory.BOOST_NESTED_TEMPLATE apply<T>(address);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
namespace boost {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
class in_place_factory_base ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
class typed_in_place_factory_base ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
namespace optional_detail {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
// This local class is used instead of that in "aligned_storage.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
// because I've found the 'official' class to ICE BCB5.5
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
// when some types are used with optional<>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
// (due to sizeof() passed down as a non-type template parameter)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
template <class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
class aligned_storage
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
    // Borland ICEs if unnamed unions are used for this!
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
    union dummy_u
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
        char data[ sizeof(T) ];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
        BOOST_DEDUCED_TYPENAME type_with_alignment<
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
          ::boost::alignment_of<T>::value >::type aligner_;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
    } dummy_ ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
  public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
    void const* address() const { return &dummy_.data[0]; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
    void      * address()       { return &dummy_.data[0]; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
} ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
struct types_when_isnt_ref
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
  typedef T const& reference_const_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
  typedef T &      reference_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
  typedef T const* pointer_const_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
  typedef T *      pointer_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
  typedef T const& argument_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
} ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
struct types_when_is_ref
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
  typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type raw_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
  typedef raw_type& reference_const_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
  typedef raw_type& reference_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
  typedef raw_type* pointer_const_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
  typedef raw_type* pointer_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
  typedef raw_type& argument_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
} ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
struct optional_tag {} ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
class optional_base : public optional_tag
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
  private :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
    typedef
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
    BOOST_DEDUCED_TYPENAME
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
#endif 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
    ::boost::detail::make_reference_content<T>::type internal_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
    typedef aligned_storage<internal_type> storage_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
    typedef types_when_isnt_ref<T> types_when_not_ref ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
    typedef types_when_is_ref<T>   types_when_ref   ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
    typedef optional_base<T> this_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
  protected :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
    typedef T value_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
    typedef mpl::true_  is_reference_tag ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
    typedef mpl::false_ is_not_reference_tag ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
    typedef BOOST_DEDUCED_TYPENAME is_reference<T>::type is_reference_predicate ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
    typedef BOOST_DEDUCED_TYPENAME mpl::if_<is_reference_predicate,types_when_ref,types_when_not_ref>::type types ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
    typedef bool (this_type::*unspecified_bool_type)() const;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
    typedef BOOST_DEDUCED_TYPENAME types::reference_type       reference_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
    typedef BOOST_DEDUCED_TYPENAME types::reference_const_type reference_const_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
    typedef BOOST_DEDUCED_TYPENAME types::pointer_type         pointer_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
    typedef BOOST_DEDUCED_TYPENAME types::pointer_const_type   pointer_const_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
    typedef BOOST_DEDUCED_TYPENAME types::argument_type        argument_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
    // Creates an optional<T> uninitialized.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
    // No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
    optional_base()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
      :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
      m_initialized(false) {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
    // Creates an optional<T> uninitialized.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
    // No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
    optional_base ( none_t )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
      :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
      m_initialized(false) {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
    // Creates an optional<T> initialized with 'val'.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
    // Can throw if T::T(T const&) does
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
    optional_base ( argument_type val )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
      :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
      m_initialized(false)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
      construct(val);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
    
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
    // Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialzed optional<T>.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
    // Can throw if T::T(T const&) does
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
    optional_base ( bool cond, argument_type val )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
      :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
      m_initialized(false)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
      if ( cond )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
        construct(val);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
    // Creates a deep copy of another optional<T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
    // Can throw if T::T(T const&) does
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
    optional_base ( optional_base const& rhs )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
      :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
      m_initialized(false)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
      if ( rhs.is_initialized() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
        construct(rhs.get_impl());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
    // This is used for both converting and in-place constructions.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
    // Derived classes use the 'tag' to select the appropriate
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
    // implementation (the correct 'construct()' overload)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
    explicit optional_base ( Expr const& expr, Expr const* tag )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
      :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
      m_initialized(false)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
      construct(expr,tag);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
    // No-throw (assuming T::~T() doesn't)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
    ~optional_base() { destroy() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
    // Assigns from another optional<T> (deep-copies the rhs value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
    void assign ( optional_base const& rhs )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
      if (is_initialized())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
        if ( rhs.is_initialized() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
             assign_value(rhs.get_impl(), is_reference_predicate() );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
        else destroy();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
      else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
        if ( rhs.is_initialized() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
          construct(rhs.get_impl());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
    // Assigns from another _convertible_ optional<U> (deep-copies the rhs value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
    template<class U>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
    void assign ( optional<U> const& rhs )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
      if (is_initialized())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
        if ( rhs.is_initialized() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
             assign_value(static_cast<value_type>(rhs.get()), is_reference_predicate() );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   263
        else destroy();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
      else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
        if ( rhs.is_initialized() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
          construct(static_cast<value_type>(rhs.get()));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
    // Assigns from a T (deep-copies the rhs value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
    void assign ( argument_type val )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
      if (is_initialized())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
           assign_value(val, is_reference_predicate() );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
      else construct(val);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
    // Assigns from "none", destroying the current value, if any, leaving this UNINITIALIZED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
    // No-throw (assuming T::~T() doesn't)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
    void assign ( none_t ) { destroy(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
    void assign_expr ( Expr const& expr, Expr const* tag )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
        if (is_initialized())
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
             assign_expr_to_initialized(expr,tag);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
        else construct(expr,tag);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
  public :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
    // Destroys the current value, if any, leaving this UNINITIALIZED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   297
    // No-throw (assuming T::~T() doesn't)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   298
    void reset() { destroy(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   299
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   300
    // Replaces the current value -if any- with 'val'
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   301
    void reset ( argument_type val ) { assign(val); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   302
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   303
    // Returns a pointer to the value if this is initialized, otherwise,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   304
    // returns NULL.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   305
    // No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   306
    pointer_const_type get_ptr() const { return m_initialized ? get_ptr_impl() : 0 ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   307
    pointer_type       get_ptr()       { return m_initialized ? get_ptr_impl() : 0 ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   308
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   309
    bool is_initialized() const { return m_initialized ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   310
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   311
  protected :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   312
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   313
    void construct ( argument_type val )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   314
     {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   315
       new (m_storage.address()) internal_type(val) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   316
       m_initialized = true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   317
     }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   318
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   319
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   320
    // Constructs in-place using the given factory
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   321
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   322
    void construct ( Expr const& factory, in_place_factory_base const* )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   323
     {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   324
       BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   325
       boost_optional_detail::construct<value_type>(factory, m_storage.address());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   326
       m_initialized = true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   327
     }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   328
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   329
    // Constructs in-place using the given typed factory
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   330
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   331
    void construct ( Expr const& factory, typed_in_place_factory_base const* )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   332
     {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   333
       BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   334
       factory.apply(m_storage.address()) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   335
       m_initialized = true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   336
     }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   337
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   338
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   339
    void assign_expr_to_initialized ( Expr const& factory, in_place_factory_base const* tag )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   340
     {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   341
       destroy();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   342
       construct(factory,tag);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   343
     }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   344
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   345
    // Constructs in-place using the given typed factory
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   346
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   347
    void assign_expr_to_initialized ( Expr const& factory, typed_in_place_factory_base const* tag )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   348
     {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   349
       destroy();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   350
       construct(factory,tag);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   351
     }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   352
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   353
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   354
    // Constructs using any expression implicitely convertible to the single argument
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   355
    // of a one-argument T constructor.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   356
    // Converting constructions of optional<T> from optional<U> uses this function with
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   357
    // 'Expr' being of type 'U' and relying on a converting constructor of T from U.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   358
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   359
    void construct ( Expr const& expr, void const* )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   360
     {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   361
       new (m_storage.address()) internal_type(expr) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   362
       m_initialized = true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   363
     }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   364
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   365
    // Assigns using a form any expression implicitely convertible to the single argument
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   366
    // of a T's assignment operator.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   367
    // Converting assignments of optional<T> from optional<U> uses this function with
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   368
    // 'Expr' being of type 'U' and relying on a converting assignment of T from U.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   369
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   370
    void assign_expr_to_initialized ( Expr const& expr, void const* )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   371
     {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   372
       assign_value(expr, is_reference_predicate());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   373
     }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   374
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   375
#ifdef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   376
    // BCB5.64 (and probably lower versions) workaround.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   377
    //   The in-place factories are supported by means of catch-all constructors
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   378
    //   and assignment operators (the functions are parameterized in terms of
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   379
    //   an arbitrary 'Expr' type)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   380
    //   This compiler incorrectly resolves the overload set and sinks optional<T> and optional<U>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   381
    //   to the 'Expr'-taking functions even though explicit overloads are present for them.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   382
    //   Thus, the following overload is needed to properly handle the case when the 'lhs'
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   383
    //   is another optional.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   384
    //
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   385
    // For VC<=70 compilers this workaround dosen't work becasue the comnpiler issues and error
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   386
    // instead of choosing the wrong overload
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   387
    //
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   388
    // Notice that 'Expr' will be optional<T> or optional<U> (but not optional_base<..>)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   389
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   390
    void construct ( Expr const& expr, optional_tag const* )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   391
     {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   392
       if ( expr.is_initialized() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   393
       {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   394
         // An exception can be thrown here.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   395
         // It it happens, THIS will be left uninitialized.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   396
         new (m_storage.address()) internal_type(expr.get()) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   397
         m_initialized = true ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   398
       }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   399
     }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   400
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   401
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   402
    void assign_value ( argument_type val, is_not_reference_tag ) { get_impl() = val; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   403
    void assign_value ( argument_type val, is_reference_tag     ) { construct(val); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   404
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   405
    void destroy()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   406
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   407
      if ( m_initialized )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   408
        destroy_impl(is_reference_predicate()) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   409
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   410
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   411
    unspecified_bool_type safe_bool() const { return m_initialized ? &this_type::is_initialized : 0 ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   412
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   413
    reference_const_type get_impl() const { return dereference(get_object(), is_reference_predicate() ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   414
    reference_type       get_impl()       { return dereference(get_object(), is_reference_predicate() ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   415
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   416
    pointer_const_type get_ptr_impl() const { return cast_ptr(get_object(), is_reference_predicate() ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   417
    pointer_type       get_ptr_impl()       { return cast_ptr(get_object(), is_reference_predicate() ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   418
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   419
  private :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   420
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   421
    // internal_type can be either T or reference_content<T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   422
    internal_type const* get_object() const { return static_cast<internal_type const*>(m_storage.address()); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   423
    internal_type *      get_object()       { return static_cast<internal_type *>     (m_storage.address()); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   424
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   425
    // reference_content<T> lacks an implicit conversion to T&, so the following is needed to obtain a proper reference.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   426
    reference_const_type dereference( internal_type const* p, is_not_reference_tag ) const { return *p ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   427
    reference_type       dereference( internal_type*       p, is_not_reference_tag )       { return *p ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   428
    reference_const_type dereference( internal_type const* p, is_reference_tag     ) const { return p->get() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   429
    reference_type       dereference( internal_type*       p, is_reference_tag     )       { return p->get() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   430
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   431
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   432
    void destroy_impl ( is_not_reference_tag ) { get_ptr_impl()->internal_type::~internal_type() ; m_initialized = false ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   433
#else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   434
    void destroy_impl ( is_not_reference_tag ) { get_ptr_impl()->T::~T() ; m_initialized = false ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   435
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   436
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   437
    void destroy_impl ( is_reference_tag     ) { m_initialized = false ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   438
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   439
    // If T is of reference type, trying to get a pointer to the held value must result in a compile-time error.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   440
    // Decent compilers should disallow conversions from reference_content<T>* to T*, but just in case,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   441
    // the following olverloads are used to filter out the case and guarantee an error in case of T being a reference.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   442
    pointer_const_type cast_ptr( internal_type const* p, is_not_reference_tag ) const { return p ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   443
    pointer_type       cast_ptr( internal_type *      p, is_not_reference_tag )       { return p ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   444
    pointer_const_type cast_ptr( internal_type const* p, is_reference_tag     ) const { return &p->get() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   445
    pointer_type       cast_ptr( internal_type *      p, is_reference_tag     )       { return &p->get() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   446
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   447
    bool m_initialized ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   448
    storage_type m_storage ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   449
} ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   450
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   451
} // namespace optional_detail
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   452
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   453
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   454
class optional : public optional_detail::optional_base<T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   455
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   456
    typedef optional_detail::optional_base<T> base ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   457
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   458
    typedef BOOST_DEDUCED_TYPENAME base::unspecified_bool_type  unspecified_bool_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   459
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   460
  public :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   461
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   462
    typedef optional<T> this_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   463
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   464
    typedef BOOST_DEDUCED_TYPENAME base::value_type           value_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   465
    typedef BOOST_DEDUCED_TYPENAME base::reference_type       reference_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   466
    typedef BOOST_DEDUCED_TYPENAME base::reference_const_type reference_const_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   467
    typedef BOOST_DEDUCED_TYPENAME base::pointer_type         pointer_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   468
    typedef BOOST_DEDUCED_TYPENAME base::pointer_const_type   pointer_const_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   469
    typedef BOOST_DEDUCED_TYPENAME base::argument_type        argument_type ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   470
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   471
    // Creates an optional<T> uninitialized.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   472
    // No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   473
    optional() : base() {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   474
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   475
    // Creates an optional<T> uninitialized.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   476
    // No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   477
    optional( none_t none_ ) : base(none_) {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   478
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   479
    // Creates an optional<T> initialized with 'val'.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   480
    // Can throw if T::T(T const&) does
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   481
    optional ( argument_type val ) : base(val) {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   482
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   483
    // Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   484
    // Can throw if T::T(T const&) does
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   485
    optional ( bool cond, argument_type val ) : base(cond,val) {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   486
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   487
#ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   488
    // NOTE: MSVC needs templated versions first
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   489
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   490
    // Creates a deep copy of another convertible optional<U>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   491
    // Requires a valid conversion from U to T.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   492
    // Can throw if T::T(U const&) does
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   493
    template<class U>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   494
    explicit optional ( optional<U> const& rhs )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   495
      :
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   496
      base()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   497
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   498
      if ( rhs.is_initialized() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   499
        this->construct(rhs.get());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   500
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   501
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   502
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   503
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   504
    // Creates an optional<T> with an expression which can be either
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   505
    //  (a) An instance of InPlaceFactory (i.e. in_place(a,b,...,n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   506
    //  (b) An instance of TypedInPlaceFactory ( i.e. in_place<T>(a,b,...,n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   507
    //  (c) Any expression implicitely convertible to the single type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   508
    //      of a one-argument T's constructor.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   509
    //  (d*) Weak compilers (BCB) might also resolved Expr as optional<T> and optional<U>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   510
    //       even though explicit overloads are present for these.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   511
    // Depending on the above some T ctor is called.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   512
    // Can throw is the resolved T ctor throws.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   513
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   514
    explicit optional ( Expr const& expr ) : base(expr,&expr) {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   515
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   516
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   517
    // Creates a deep copy of another optional<T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   518
    // Can throw if T::T(T const&) does
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   519
    optional ( optional const& rhs ) : base(rhs) {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   520
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   521
   // No-throw (assuming T::~T() doesn't)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   522
    ~optional() {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   523
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   524
#if !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) && !defined(BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   525
    // Assigns from an expression. See corresponding constructor.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   526
    // Basic Guarantee: If the resolved T ctor throws, this is left UNINITIALIZED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   527
    template<class Expr>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   528
    optional& operator= ( Expr expr )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   529
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   530
        this->assign_expr(expr,&expr);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   531
        return *this ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   532
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   533
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   534
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   535
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   536
#ifndef BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   537
    // Assigns from another convertible optional<U> (converts && deep-copies the rhs value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   538
    // Requires a valid conversion from U to T.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   539
    // Basic Guarantee: If T::T( U const& ) throws, this is left UNINITIALIZED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   540
    template<class U>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   541
    optional& operator= ( optional<U> const& rhs )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   542
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   543
        this->assign(rhs);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   544
        return *this ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   545
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   546
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   547
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   548
    // Assigns from another optional<T> (deep-copies the rhs value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   549
    // Basic Guarantee: If T::T( T const& ) throws, this is left UNINITIALIZED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   550
    //  (NOTE: On BCB, this operator is not actually called and left is left UNMODIFIED in case of a throw)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   551
    optional& operator= ( optional const& rhs )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   552
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   553
        this->assign( rhs ) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   554
        return *this ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   555
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   556
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   557
    // Assigns from a T (deep-copies the rhs value)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   558
    // Basic Guarantee: If T::( T const& ) throws, this is left UNINITIALIZED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   559
    optional& operator= ( argument_type val )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   560
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   561
        this->assign( val ) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   562
        return *this ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   563
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   564
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   565
    // Assigns from a "none"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   566
    // Which destroys the current value, if any, leaving this UNINITIALIZED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   567
    // No-throw (assuming T::~T() doesn't)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   568
    optional& operator= ( none_t none_ )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   569
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   570
        this->assign( none_ ) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   571
        return *this ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   572
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   573
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   574
    // Returns a reference to the value if this is initialized, otherwise,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   575
    // the behaviour is UNDEFINED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   576
    // No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   577
    reference_const_type get() const { BOOST_ASSERT(this->is_initialized()) ; return this->get_impl(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   578
    reference_type       get()       { BOOST_ASSERT(this->is_initialized()) ; return this->get_impl(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   579
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   580
    // Returns a copy of the value if this is initialized, 'v' otherwise
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   581
    reference_const_type get_value_or ( reference_const_type v ) const { return this->is_initialized() ? get() : v ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   582
    reference_type       get_value_or ( reference_type       v )       { return this->is_initialized() ? get() : v ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   583
    
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   584
    // Returns a pointer to the value if this is initialized, otherwise,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   585
    // the behaviour is UNDEFINED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   586
    // No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   587
    pointer_const_type operator->() const { BOOST_ASSERT(this->is_initialized()) ; return this->get_ptr_impl() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   588
    pointer_type       operator->()       { BOOST_ASSERT(this->is_initialized()) ; return this->get_ptr_impl() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   589
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   590
    // Returns a reference to the value if this is initialized, otherwise,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   591
    // the behaviour is UNDEFINED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   592
    // No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   593
    reference_const_type operator *() const { return this->get() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   594
    reference_type       operator *()       { return this->get() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   595
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   596
    // implicit conversion to "bool"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   597
    // No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   598
    operator unspecified_bool_type() const { return this->safe_bool() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   599
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   600
       // This is provided for those compilers which don't like the conversion to bool
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   601
       // on some contexts.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   602
       bool operator!() const { return !this->is_initialized() ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   603
} ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   604
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   605
// Returns optional<T>(v)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   606
template<class T> 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   607
inline 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   608
optional<T> make_optional ( T const& v  )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   609
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   610
  return optional<T>(v);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   611
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   612
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   613
// Returns optional<T>(cond,v)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   614
template<class T> 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   615
inline 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   616
optional<T> make_optional ( bool cond, T const& v )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   617
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   618
  return optional<T>(cond,v);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   619
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   620
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   621
// Returns a reference to the value if this is initialized, otherwise, the behaviour is UNDEFINED.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   622
// No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   623
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   624
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   625
BOOST_DEDUCED_TYPENAME optional<T>::reference_const_type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   626
get ( optional<T> const& opt )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   627
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   628
  return opt.get() ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   629
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   630
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   631
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   632
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   633
BOOST_DEDUCED_TYPENAME optional<T>::reference_type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   634
get ( optional<T>& opt )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   635
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   636
  return opt.get() ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   637
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   638
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   639
// Returns a pointer to the value if this is initialized, otherwise, returns NULL.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   640
// No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   641
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   642
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   643
BOOST_DEDUCED_TYPENAME optional<T>::pointer_const_type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   644
get ( optional<T> const* opt )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   645
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   646
  return opt->get_ptr() ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   647
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   648
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   649
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   650
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   651
BOOST_DEDUCED_TYPENAME optional<T>::pointer_type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   652
get ( optional<T>* opt )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   653
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   654
  return opt->get_ptr() ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   655
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   656
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   657
// Returns a reference to the value if this is initialized, otherwise, the behaviour is UNDEFINED.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   658
// No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   659
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   660
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   661
BOOST_DEDUCED_TYPENAME optional<T>::reference_const_type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   662
get_optional_value_or ( optional<T> const& opt, BOOST_DEDUCED_TYPENAME optional<T>::reference_const_type v )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   663
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   664
  return opt.get_value_or(v) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   665
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   666
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   667
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   668
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   669
BOOST_DEDUCED_TYPENAME optional<T>::reference_type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   670
get_optional_value_or ( optional<T>& opt, BOOST_DEDUCED_TYPENAME optional<T>::reference_type v )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   671
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   672
  return opt.get_value_or(v) ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   673
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   674
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   675
// Returns a pointer to the value if this is initialized, otherwise, returns NULL.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   676
// No-throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   677
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   678
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   679
BOOST_DEDUCED_TYPENAME optional<T>::pointer_const_type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   680
get_pointer ( optional<T> const& opt )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   681
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   682
  return opt.get_ptr() ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   683
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   684
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   685
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   686
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   687
BOOST_DEDUCED_TYPENAME optional<T>::pointer_type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   688
get_pointer ( optional<T>& opt )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   689
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   690
  return opt.get_ptr() ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   691
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   692
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   693
// optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values).
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   694
// WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointess() in generic code instead.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   695
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   696
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   697
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   698
// optional<T> vs optional<T> cases
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   699
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   700
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   701
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   702
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   703
bool operator == ( optional<T> const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   704
{ return equal_pointees(x,y); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   705
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   706
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   707
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   708
bool operator < ( optional<T> const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   709
{ return less_pointees(x,y); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   710
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   711
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   712
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   713
bool operator != ( optional<T> const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   714
{ return !( x == y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   715
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   716
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   717
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   718
bool operator > ( optional<T> const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   719
{ return y < x ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   720
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   721
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   722
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   723
bool operator <= ( optional<T> const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   724
{ return !( y < x ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   725
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   726
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   727
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   728
bool operator >= ( optional<T> const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   729
{ return !( x < y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   730
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   731
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   732
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   733
// optional<T> vs T cases
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   734
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   735
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   736
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   737
bool operator == ( optional<T> const& x, T const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   738
{ return equal_pointees(x, optional<T>(y)); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   739
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   740
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   741
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   742
bool operator < ( optional<T> const& x, T const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   743
{ return less_pointees(x, optional<T>(y)); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   744
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   745
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   746
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   747
bool operator != ( optional<T> const& x, T const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   748
{ return !( x == y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   749
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   750
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   751
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   752
bool operator > ( optional<T> const& x, T const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   753
{ return y < x ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   754
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   755
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   756
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   757
bool operator <= ( optional<T> const& x, T const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   758
{ return !( y < x ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   759
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   760
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   761
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   762
bool operator >= ( optional<T> const& x, T const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   763
{ return !( x < y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   764
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   765
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   766
// T vs optional<T> cases
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   767
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   768
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   769
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   770
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   771
bool operator == ( T const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   772
{ return equal_pointees( optional<T>(x), y ); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   773
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   774
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   775
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   776
bool operator < ( T const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   777
{ return less_pointees( optional<T>(x), y ); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   778
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   779
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   780
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   781
bool operator != ( T const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   782
{ return !( x == y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   783
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   784
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   785
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   786
bool operator > ( T const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   787
{ return y < x ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   788
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   789
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   790
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   791
bool operator <= ( T const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   792
{ return !( y < x ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   793
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   794
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   795
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   796
bool operator >= ( T const& x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   797
{ return !( x < y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   798
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   799
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   800
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   801
// optional<T> vs none cases
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   802
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   803
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   804
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   805
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   806
bool operator == ( optional<T> const& x, none_t )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   807
{ return equal_pointees(x, optional<T>() ); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   808
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   809
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   810
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   811
bool operator < ( optional<T> const& x, none_t )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   812
{ return less_pointees(x,optional<T>() ); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   813
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   814
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   815
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   816
bool operator != ( optional<T> const& x, none_t y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   817
{ return !( x == y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   818
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   819
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   820
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   821
bool operator > ( optional<T> const& x, none_t y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   822
{ return y < x ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   823
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   824
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   825
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   826
bool operator <= ( optional<T> const& x, none_t y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   827
{ return !( y < x ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   828
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   829
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   830
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   831
bool operator >= ( optional<T> const& x, none_t y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   832
{ return !( x < y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   833
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   834
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   835
// none vs optional<T> cases
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   836
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   837
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   838
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   839
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   840
bool operator == ( none_t x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   841
{ return equal_pointees(optional<T>() ,y); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   842
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   843
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   844
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   845
bool operator < ( none_t x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   846
{ return less_pointees(optional<T>() ,y); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   847
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   848
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   849
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   850
bool operator != ( none_t x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   851
{ return !( x == y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   852
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   853
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   854
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   855
bool operator > ( none_t x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   856
{ return y < x ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   857
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   858
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   859
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   860
bool operator <= ( none_t x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   861
{ return !( y < x ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   862
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   863
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   864
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   865
bool operator >= ( none_t x, optional<T> const& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   866
{ return !( x < y ) ; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   867
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   868
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   869
// The following swap implementation follows the GCC workaround as found in
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   870
//  "boost/detail/compressed_pair.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   871
//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   872
namespace optional_detail {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   873
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   874
// GCC < 3.2 gets the using declaration at namespace scope (FLC, DWA)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   875
#if BOOST_WORKAROUND(__GNUC__, < 3)                             \
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   876
    || BOOST_WORKAROUND(__GNUC__, == 3) && __GNUC_MINOR__ <= 2
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   877
   using std::swap;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   878
#define BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   879
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   880
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   881
// optional's swap:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   882
// If both are initialized, calls swap(T&, T&). If this swap throws, both will remain initialized but their values are now unspecified.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   883
// If only one is initialized, calls U.reset(*I), THEN I.reset().
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   884
// If U.reset(*I) throws, both are left UNCHANGED (U is kept uinitialized and I is never reset)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   885
// If both are uninitialized, do nothing (no-throw)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   886
template<class T>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   887
inline
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   888
void optional_swap ( optional<T>& x, optional<T>& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   889
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   890
  if ( !x && !!y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   891
  {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   892
    x.reset(*y);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   893
    y.reset();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   894
  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   895
  else if ( !!x && !y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   896
  {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   897
    y.reset(*x);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   898
    x.reset();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   899
  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   900
  else if ( !!x && !!y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   901
  {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   902
// GCC > 3.2 and all other compilers have the using declaration at function scope (FLC)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   903
#ifndef BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   904
    // allow for Koenig lookup
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   905
    using std::swap ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   906
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   907
    swap(*x,*y);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   908
  }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   909
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   910
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   911
} // namespace optional_detail
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   912
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   913
template<class T> inline void swap ( optional<T>& x, optional<T>& y )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   914
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   915
  optional_detail::optional_swap(x,y);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   916
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   917
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   918
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   919
} // namespace boost
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   920
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   921
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   922