|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77235 - in sandbox-branches/optional_optimization: boost/optional libs/optional/test
From: C.Hite_at_[hidden]
Date: 2012-03-05 12:13:07
Author: chris_hite
Date: 2012-03-05 12:13:05 EST (Mon, 05 Mar 2012)
New Revision: 77235
URL: http://svn.boost.org/trac/boost/changeset/77235
Log:
has_trivial_destructor and dtor optimization done.
Added:
sandbox-branches/optional_optimization/libs/optional/test/optional_test_trivial_assertions.cpp (contents, props changed)
Text files modified:
sandbox-branches/optional_optimization/boost/optional/optional.hpp | 29 +++++++++++++++++++++++++----
sandbox-branches/optional_optimization/libs/optional/test/Jamfile.v2 | 1 +
2 files changed, 26 insertions(+), 4 deletions(-)
Modified: sandbox-branches/optional_optimization/boost/optional/optional.hpp
==============================================================================
--- sandbox-branches/optional_optimization/boost/optional/optional.hpp (original)
+++ sandbox-branches/optional_optimization/boost/optional/optional.hpp 2012-03-05 12:13:05 EST (Mon, 05 Mar 2012)
@@ -26,6 +26,7 @@
#include <boost/type_traits/type_with_alignment.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/is_reference.hpp>
+#include <boost/type_traits/has_trivial_destructor.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/not.hpp>
@@ -168,6 +169,9 @@
typedef raw_type& argument_type ;
} ;
+template<typename T>
+struct optional_dtor_optimized : has_trivial_destructor<T> {};
+
struct optional_tag {} ;
template<class T>
@@ -199,6 +203,7 @@
public:
typedef BOOST_DEDUCED_TYPENAME mpl::if_<is_reference_predicate,types_when_ref,types_when_not_ref>::type types ;
+ typedef optional_dtor_optimized<T> dtor_optimized;
protected:
typedef bool (this_type::*unspecified_bool_type)() const;
@@ -265,7 +270,7 @@
// No-throw (assuming T::~T() doesn't)
- ~optional_base() { destroy() ; }
+ //~optional_base() { destroy() ; }
// Assigns from another optional<T> (deep-copies the rhs value)
void assign ( optional_base const& rhs )
@@ -440,6 +445,12 @@
m_initialized = false ;
}
}
+ void destructor_impl() // doesn't reset m_initialized
+ {
+ if(m_initialized)
+ destroy_impl(is_reference_predicate()) ;
+ }
+ template<typename Optional,bool dtor_optimized> friend class optional_dtor_mixin;
unspecified_bool_type safe_bool() const { return m_initialized ? &this_type::is_initialized : 0 ; }
@@ -495,10 +506,20 @@
storage_type m_storage ;
} ;
+template<typename Optional,bool dtor_optimized>
+struct optional_dtor_mixin{
+ ~optional_dtor_mixin(){ static_cast<Optional*>(this)->destructor_impl() ; }
+};
+
+template<typename Optional>
+struct optional_dtor_mixin<Optional, true > { };
+
} // namespace optional_detail
template<class T>
-class optional : public optional_detail::optional_base<T>
+class optional :
+ public optional_detail::optional_base<T>,
+ public optional_detail::optional_dtor_mixin<optional<T>, optional_detail::optional_base<T>::dtor_optimized::value >
{
typedef optional_detail::optional_base<T> base ;
@@ -565,8 +586,8 @@
// Can throw if T::T(T const&) does
optional ( optional const& rhs ) : base( static_cast<base const&>(rhs) ) {}
- // No-throw (assuming T::~T() doesn't)
- ~optional() {}
+ // No-throw (assuming T::~T() doesn't)
+ //~optional() {}
#if !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) && !defined(BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION)
// Assigns from an expression. See corresponding constructor.
Modified: sandbox-branches/optional_optimization/libs/optional/test/Jamfile.v2
==============================================================================
--- sandbox-branches/optional_optimization/libs/optional/test/Jamfile.v2 (original)
+++ sandbox-branches/optional_optimization/libs/optional/test/Jamfile.v2 2012-03-05 12:13:05 EST (Mon, 05 Mar 2012)
@@ -29,5 +29,6 @@
[ compile-fail optional_test_ref_fail4.cpp ]
[ compile-fail optional_test_inplace_fail.cpp ]
[ compile-fail optional_test_inplace_fail2.cpp ]
+ [ compile optional_test_trivial_assertions.cpp ]
;
}
Added: sandbox-branches/optional_optimization/libs/optional/test/optional_test_trivial_assertions.cpp
==============================================================================
--- (empty file)
+++ sandbox-branches/optional_optimization/libs/optional/test/optional_test_trivial_assertions.cpp 2012-03-05 12:13:05 EST (Mon, 05 Mar 2012)
@@ -0,0 +1,30 @@
+#include "boost/optional.hpp"
+#include "boost/static_assert.hpp"
+#include "boost/type_traits.hpp"
+
+using namespace boost;
+
+typedef optional<char> oc;
+typedef optional<int> oi;
+typedef optional<std::string> os;
+
+BOOST_STATIC_ASSERT( sizeof(oc) <= 2*sizeof(char) );
+BOOST_STATIC_ASSERT( sizeof(oi) <= 2*sizeof(int) );
+
+BOOST_STATIC_ASSERT( !has_trivial_default_constructor<oi>::value ); //never true for optional
+BOOST_STATIC_ASSERT( !has_trivial_default_constructor<os>::value );
+
+BOOST_STATIC_ASSERT( has_trivial_destructor<oi>::value ); //should be true where has_trivial_destructor<T>
+BOOST_STATIC_ASSERT( !has_trivial_destructor<os>::value );
+
+
+/*
+has_trivial_assign
+has_trivial_constructor
+has_trivial_copy
+has_trivial_copy_constructor
+has_trivial_default_constructor
+has_trivial_destructor
+ */
+
+
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