Update of /cvsroot/boost/boost/boost/optional
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13309/boost/optional
Modified Files:
Tag: RC_1_34_0
optional.hpp
Log Message:
Fixed operator->() for optional references.
Index: optional.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/optional/optional.hpp,v
retrieving revision 1.9.2.2
retrieving revision 1.9.2.3
diff -u -d -r1.9.2.2 -r1.9.2.3
--- optional.hpp 12 Jun 2006 19:02:41 -0000 1.9.2.2
+++ optional.hpp 1 Mar 2007 21:39:25 -0000 1.9.2.3
@@ -185,6 +185,16 @@
{
construct(val);
}
+
+ // Creates an optional<T> initialized with 'val' IFF cond is true,
otherwise creates an uninitialzed optional<T>.
+ // Can throw if T::T(T const&) does
+ optional_base ( bool cond, argument_type val )
+ :
+ m_initialized(false)
+ {
+ if ( cond )
+ construct(val);
+ }
// Creates a deep copy of another optional<T>
// Can throw if T::T(T const&) does
@@ -418,6 +428,8 @@
// the following olverloads are used to filter out the case and guarantee
an error in case of T being a reference.
pointer_const_type cast_ptr( internal_type const* p, is_not_reference_tag
) const { return p ; }
pointer_type cast_ptr( internal_type * p, is_not_reference_tag
) { return p ; }
+ pointer_const_type cast_ptr( internal_type const* p, is_reference_tag
) const { return &p->get() ; }
+ pointer_type cast_ptr( internal_type * p, is_reference_tag
) { return &p->get() ; }
bool m_initialized ;
storage_type m_storage ;
@@ -455,6 +467,9 @@
// Can throw if T::T(T const&) does
optional ( argument_type val ) : base(val) {}
+ // Creates an optional<T> initialized with 'val' IFF cond is true,
otherwise creates an uninitialized optional.
+ // Can throw if T::T(T const&) does
+ optional ( bool cond, argument_type val ) : base(cond,val) {}
#ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR
// NOTE: MSVC needs templated versions first
@@ -549,6 +564,10 @@
reference_const_type get() const { BOOST_ASSERT(this->is_initialized()) ;
return this->get_impl(); }
reference_type get() { BOOST_ASSERT(this->is_initialized()) ;
return this->get_impl(); }
+ // Returns a copy of the value if this is initialized, 'v' otherwise
+ reference_const_type get_value_or ( reference_const_type v ) const {
return this->is_initialized() ? get() : v ; }
+ reference_type get_value_or ( reference_type v ) {
return this->is_initialized() ? get() : v ; }
+
// Returns a pointer to the value if this is initialized, otherwise,
// the behaviour is UNDEFINED
// No-throw
@@ -570,6 +589,22 @@
bool operator!() const { return !this->is_initialized() ; }
} ;
+// Returns optional<T>(v)
+template<class T>
+inline
+optional<T> make_optional ( T const& v )
+{
+ return optional<T>(v);
+}
+
+// Returns optional<T>(cond,v)
+template<class T>
+inline
+optional<T> make_optional ( bool cond, T const& v )
+{
+ return optional<T>(cond,v);
+}
+
// Returns a reference to the value if this is initialized, otherwise, the
behaviour is UNDEFINED.
// No-throw
template<class T>
@@ -606,6 +641,24 @@
return opt->get_ptr() ;
}
+// Returns a reference to the value if this is initialized, otherwise, the
behaviour is UNDEFINED.
+// No-throw
+template<class T>
+inline
+BOOST_DEDUCED_TYPENAME optional<T>::reference_const_type
+get_optional_value_or ( optional<T> const& opt, BOOST_DEDUCED_TYPENAME
optional<T>::reference_const_type v )
+{
+ return opt.get_value_or(v) ;
+}
+
+template<class T>
+inline
+BOOST_DEDUCED_TYPENAME optional<T>::reference_type
+get_optional_value_or ( optional<T>& opt, BOOST_DEDUCED_TYPENAME
optional<T>::reference_type v )
+{
+ return opt.get_value_or(v) ;
+}
+
// Returns a pointer to the value if this is initialized, otherwise, returns
NULL.
// No-throw
template<class T>
@@ -767,10 +820,6 @@
optional_detail::optional_swap(x,y);
}
-template<class T> inline optional<T> make_optional ( T const& v )
-{
- return optional<T>(v);
-}
} // namespace boost
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs