1 /////////////////////////////////////////////////////////////////////////////
\r
3 // (C) Copyright Joaquín M López Muñoz 2006-2007
\r
5 // Distributed under the Boost Software License, Version 1.0.
\r
6 // (See accompanying file LICENSE_1_0.txt or copy at
\r
7 // http://www.boost.org/LICENSE_1_0.txt)
\r
9 // See http://www.boost.org/libs/intrusive for documentation.
\r
11 /////////////////////////////////////////////////////////////////////////////
\r
12 #include <boost/type_traits/is_empty.hpp>
\r
15 namespace intrusive {
\r
18 template<typename T, bool IsEmpty = false>
\r
19 class ebo_holder_impl
\r
23 ebo_holder_impl(const T& t):t(t){}
\r
26 const T& get()const{return t;}
\r
32 template<typename T>
\r
33 class ebo_holder_impl<T, true>
\r
38 ebo_holder_impl(const T& t):T(t){}
\r
40 T& get(){return *this;}
\r
41 const T& get()const{return *this;}
\r
44 template<typename T>
\r
46 : public ebo_holder_impl<T,boost::is_empty<T>::value>
\r
49 typedef ebo_holder_impl<T,boost::is_empty<T>::value> super;
\r
53 ebo_holder(const T& t):super(t){}
\r
55 ebo_holder& operator=(const ebo_holder& x)
\r
57 this->get()=x.get();
\r
63 } //namespace detail {
\r
64 } //namespace intrusive {
\r
65 } //namespace boost {
\r
71 #include <boost/assert.hpp>
\r
74 struct empty_member{};
\r
76 struct foo:public ebo_holder<empty_member>
\r
83 ebo_holder<int> ei=5;
\r
84 BOOST_ASSERT(ei.get()==5);
\r
86 BOOST_ASSERT(ei.get()==6);
\r
88 ebo_holder<std::string> es("hello");
\r
89 BOOST_ASSERT(es.get()=="hello");
\r
90 es=std::string("bye");
\r
91 BOOST_ASSERT(es.get()=="bye");
\r
93 BOOST_ASSERT(sizeof(foo)==sizeof(int)); // if EBO applies
\r