|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65632 - sandbox/variadic_templates/libs/composite_storage/sandbox/pack
From: cppljevans_at_[hidden]
Date: 2010-09-27 12:02:18
Author: cppljevans
Date: 2010-09-27 12:02:15 EDT (Mon, 27 Sep 2010)
New Revision: 65632
URL: http://svn.boost.org/trac/boost/changeset/65632
Log:
WHAT:
1) Added comments explaining why empties_tree_inherit size>1.
2) Added enum_base<index0> speecialization.
WHY:
1) Clarify why using inheritance to achive EBO only works
with 1 level of inheritance.
2) Show further saving of one_of_maybe vs. variant.
OUTPUT:
sizeof(empty_class<0>)=1
sizeof(index_inherit<0,empties_inherit>)=1
sizeof(empties_inherit)=1
sizeof(empties_tree_inherit)=2
sizeof(empties_member)=2
sizeof(empties_all_of)=1
sizeof(empties_tree_all_of)=1
sizeof(empties_variant)=8
sizeof(empties_one_of)=1
sizeof(enum_base<index0>::type)=1
p0=0x7fffefb05f6f
p1=0x7fffefb05f6f
*p0=empty_class<0>const&
*p1=empty_class<1>const&
r0=empty_class<0>const&
r1=empty_class<1>const&
&ea_v=0x7fffefb05f6e
&r0=0x7fffefb05f6e
&r1=0x7fffefb05f6e
r1.get()=1
Text files modified:
sandbox/variadic_templates/libs/composite_storage/sandbox/pack/empty_base.cpp | 53 ++++++++++++++++++++++++++++-----------
1 files changed, 38 insertions(+), 15 deletions(-)
Modified: sandbox/variadic_templates/libs/composite_storage/sandbox/pack/empty_base.cpp
==============================================================================
--- sandbox/variadic_templates/libs/composite_storage/sandbox/pack/empty_base.cpp (original)
+++ sandbox/variadic_templates/libs/composite_storage/sandbox/pack/empty_base.cpp 2010-09-27 12:02:15 EDT (Mon, 27 Sep 2010)
@@ -1,13 +1,8 @@
//Purpose:
-// See if more than 1 empty base types contribute
-// more to size of derived type than just 1
-// empty_base type.
-//Result:
-// No. Output is:
-// sizeof(empty_class<0>)=1
-// sizeof(empties_inherits)=1
-// sizeof(empties_member)=2
-// sizeof(empties_all_of)=1
+// Demostrate effect of using empty base class
+// in various constructs.
+//Reference:
+// [EBO] http://www.cantrip.org/emptyopt.html
//
#include <boost/composite_storage/pack/container_all_of_aligned.hpp>
#include <boost/composite_storage/pack/container_one_of_maybe.hpp>
@@ -18,6 +13,9 @@
< unsigned I
>
struct empty_class
+/**@brief
+ * This is an empty class, according to:
+ */
{
friend
std::ostream&
@@ -34,15 +32,15 @@
{
return I;
}
- #if 0
- unsigned my_i;
- empty_class(void):my_i(I){}
- #endif
};
struct empties_inherit
: empty_class<0>
, empty_class<1>
+/*@brief
+ * According to [EBO] this class is not an empty class
+ * because its sequence of base class objects is not empty.
+ */
{};
template<unsigned I, typename T>
@@ -53,6 +51,11 @@
struct empties_tree_inherit
: index_inherit<0,empties_inherit>
, index_inherit<1,empties_inherit>
+/**@brief
+ * Since empties_inherit is not an empty class,
+ * the empty-base-class-optimization doesn't apply here;
+ * hence sizeof(empties_tree_inherit)>1.
+ */
{};
struct empties_member
@@ -60,10 +63,28 @@
empty_class<0> m0;
empty_class<1> m1;
};
+
+ typedef
+ char
+index_type
+;
typedef
- boost::mpl::integral_c<unsigned,0>
+ boost::mpl::integral_c<index_type,index_type(0)>
index0
;
+namespace boost
+{
+namespace composite_storage
+{
+ template<>
+ struct enum_base<index0>
+ {
+ typedef
+ char //save space in one_of_maybe
+ type;
+ };
+}
+}
typedef
boost::composite_storage::pack::container
< boost::composite_storage::tags::all_of_aligned
@@ -101,13 +122,15 @@
int main(void)
{
std::cout<<"sizeof(empty_class<0>)="<<sizeof(empty_class<0>)<<"\n";
+ std::cout<<"sizeof(index_inherit<0,empties_inherit>)="
+ <<sizeof(index_inherit<0,empties_inherit>)<<"\n";
std::cout<<"sizeof(empties_inherit)="<<sizeof(empties_inherit)<<"\n";
std::cout<<"sizeof(empties_tree_inherit)="<<sizeof(empties_tree_inherit)<<"\n";
std::cout<<"sizeof(empties_member)="<<sizeof(empties_member)<<"\n";
std::cout<<"sizeof(empties_all_of)="<<sizeof(empties_all_of)<<"\n";
std::cout<<"sizeof(empties_tree_all_of)="<<sizeof(empties_tree_all_of)<<"\n";
- std::cout<<"sizeof(empties_one_of)="<<sizeof(empties_one_of)<<"\n";
std::cout<<"sizeof(empties_variant)="<<sizeof(empties_variant)<<"\n";
+ std::cout<<"sizeof(empties_one_of)="<<sizeof(empties_one_of)<<"\n";
std::cout
<<"sizeof(enum_base<index0>::type)="
<<sizeof(boost::composite_storage::enum_base<index0>::type)<<"\n";
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