Fix Example SConstruct files to search for senfutil.py in system directory
[senf.git] / boost / intrusive / detail / ebo_holder.hpp
1 /////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 // (C) Copyright Joaquín M López Muñoz  2006-2007\r
4 //\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
8 //\r
9 // See http://www.boost.org/libs/intrusive for documentation.\r
10 //\r
11 /////////////////////////////////////////////////////////////////////////////\r
12 #include <boost/type_traits/is_empty.hpp>\r
13 \r
14 namespace boost {\r
15 namespace intrusive {\r
16 namespace detail {\r
17 \r
18 template<typename T, bool IsEmpty = false>\r
19 class ebo_holder_impl\r
20 {\r
21    public:\r
22    ebo_holder_impl(){}\r
23    ebo_holder_impl(const T& t):t(t){}\r
24 \r
25    T&       get(){return t;}\r
26    const T& get()const{return t;}\r
27 \r
28    private:\r
29    T t;\r
30 };\r
31 \r
32 template<typename T>\r
33 class ebo_holder_impl<T, true>\r
34    :  private T\r
35 {\r
36    public:\r
37    ebo_holder_impl(){}\r
38    ebo_holder_impl(const T& t):T(t){}\r
39 \r
40    T&       get(){return *this;}\r
41    const T& get()const{return *this;}\r
42 };\r
43 \r
44 template<typename T>\r
45 class ebo_holder\r
46    :  public ebo_holder_impl<T,boost::is_empty<T>::value>\r
47 {\r
48    private:\r
49    typedef ebo_holder_impl<T,boost::is_empty<T>::value> super;\r
50 \r
51    public:\r
52    ebo_holder(){}\r
53    ebo_holder(const T& t):super(t){}\r
54 \r
55    ebo_holder& operator=(const ebo_holder& x)\r
56    {\r
57       this->get()=x.get();\r
58       return *this;\r
59    }\r
60 };\r
61 \r
62 \r
63 }  //namespace detail {\r
64 }  //namespace intrusive {\r
65 }  //namespace boost {\r
66 \r
67 /*\r
68 \r
69 // testing\r
70 \r
71 #include <boost/assert.hpp>\r
72 #include <string>\r
73 \r
74 struct empty_member{};\r
75 \r
76 struct foo:public ebo_holder<empty_member>\r
77 {\r
78   int x;\r
79 };\r
80 \r
81 int main()\r
82 {\r
83   ebo_holder<int> ei=5;\r
84   BOOST_ASSERT(ei.get()==5);\r
85   ei=6;\r
86   BOOST_ASSERT(ei.get()==6);\r
87 \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
92 \r
93   BOOST_ASSERT(sizeof(foo)==sizeof(int)); // if EBO applies\r
94 }\r
95 */\r