Imported Upstream version 1.51.0
[platform/upstream/boost.git] / boost / container / detail / stored_ref.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2008-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #ifndef BOOST_CONTAINER_DETAIL_STORED_REF_HPP
12 #define BOOST_CONTAINER_DETAIL_STORED_REF_HPP
13
14 #include "config_begin.hpp"
15 #include <boost/container/detail/workaround.hpp>
16
17 #ifndef BOOST_NO_RVALUE_REFERENCES
18
19 namespace boost{
20 namespace container{
21 namespace container_detail{
22
23 template<class T>
24 struct stored_ref
25 {
26
27    static T && forward(T &t)
28    #ifdef BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
29    { return t; }
30    #else
31    { return boost::move(t); }
32    #endif
33 };
34
35 template<class T>
36 struct stored_ref<const T>
37 {
38    static const T && forward(const T &t)
39    #ifdef BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
40    { return t; }
41    #else
42    { return static_cast<const T&&>(t); }
43    #endif
44 };
45
46 template<class T>
47 struct stored_ref<T&&>
48 {
49    static T && forward(T &t)
50    #ifdef BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
51    { return t; }
52    #else
53    { return boost::move(t); }
54    #endif
55 };
56
57 template<class T>
58 struct stored_ref<const T&&>
59 {
60    static const T && forward(const T &t)
61    #ifdef BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
62    { return t; }
63    #else
64    { return static_cast<const T &&>(t); }
65    #endif
66 };
67
68 template<class T>
69 struct stored_ref<const T&>
70 {
71    static const T & forward(const T &t)
72    {  return t; }
73 };
74
75 template<class T>
76 struct stored_ref<T&>
77 {
78    static T & forward(T &t)
79    {  return t; }
80 };
81
82 }  //namespace container_detail{
83 }  //namespace container{
84 }  //namespace boost{
85
86 #else
87 #error "This header can be included only for compiler with rvalue references"
88 #endif   //BOOST_NO_RVALUE_REFERENCES
89
90 #include <boost/container/detail/config_end.hpp>
91
92 #endif   //BOOST_CONTAINER_DETAIL_STORED_REF_HPP