Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84182 - trunk/boost
From: antoshkka_at_[hidden]
Date: 2013-05-07 15:19:43


Author: apolukhin
Date: 2013-05-07 15:19:42 EDT (Tue, 07 May 2013)
New Revision: 84182
URL: http://svn.boost.org/trac/boost/changeset/84182

Log:
Make Boost.Any more conformant to draft:
* add missing BOOST_NOEXCEPT (partially refs #6999)
* add clear() method
* microoptimization
Text files modified:
   trunk/boost/any.hpp | 35 ++++++++++++++++++++++++++++++-----
   1 files changed, 30 insertions(+), 5 deletions(-)

Modified: trunk/boost/any.hpp
==============================================================================
--- trunk/boost/any.hpp (original)
+++ trunk/boost/any.hpp 2013-05-07 15:19:42 EDT (Tue, 07 May 2013)
@@ -12,7 +12,7 @@
 // with features contributed and bugs found by
 // Antony Polukhin, Ed Brey, Mark Rodgers,
 // Peter Dimov, and James Curran
-// when: July 2001, Aplril 2013
+// when: July 2001, April 2013 - May 2013
 
 #include <algorithm>
 #include <typeinfo>
@@ -37,6 +37,11 @@
 #include <cstring>
 # endif
 
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable: 4172) // Mistakenly warns: returning address of local variable or temporary
+#endif
+
 namespace boost
 {
     class any
@@ -134,7 +139,12 @@
             return !content;
         }
 
- const std::type_info & type() const
+ void clear() BOOST_NOEXCEPT
+ {
+ any().swap(*this);
+ }
+
+ const std::type_info & type() const BOOST_NOEXCEPT
         {
             return content ? content->type() : typeid(void);
         }
@@ -155,7 +165,7 @@
 
         public: // queries
 
- virtual const std::type_info & type() const = 0;
+ virtual const std::type_info & type() const BOOST_NOEXCEPT = 0;
 
             virtual placeholder * clone() const = 0;
 
@@ -179,7 +189,7 @@
 #endif
         public: // queries
 
- virtual const std::type_info & type() const
+ virtual const std::type_info & type() const BOOST_NOEXCEPT
             {
                 return typeid(ValueType);
             }
@@ -269,7 +279,18 @@
         nonref * result = any_cast<nonref>(&operand);
         if(!result)
             boost::throw_exception(bad_any_cast());
- return static_cast<ValueType>(*result);
+
+ // Attempt to avoid construction of a temporary object in cases when
+ // `ValueType` is not a reference. Example:
+ // `static_cast<std::string>(*result);`
+ // which is equal to `std::string(*result);`
+ typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_<
+ boost::is_reference<ValueType>,
+ ValueType,
+ ValueType&
+ >::type ref_type;
+
+ return static_cast<ref_type>(*result);
     }
 
     template<typename ValueType>
@@ -310,4 +331,8 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
+
 #endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk