ivl 679
ivl/details/core/rvalue.hpp
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>.
00002    A C++ template library extending syntax towards mathematical notation.
00003 
00004    Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr>
00005    Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr>
00006 
00007    ivl is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU Lesser General Public License 
00009    version 3 as published by the Free Software Foundation.
00010 
00011    Alternatively, you can redistribute it and/or modify it under the terms 
00012    of the GNU General Public License version 2 as published by the Free 
00013    Software Foundation.
00014 
00015    ivl is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00018    See the GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License 
00021    and a copy of the GNU Lesser General Public License along 
00022    with ivl. If not, see <http://www.gnu.org/licenses/>. */
00023 
00024 #ifndef IVL_CORE_DETAILS_RVALUE_HPP
00025 #define IVL_CORE_DETAILS_RVALUE_HPP
00026 
00027 // to be removed
00028 
00029 #if 0
00030 
00031 namespace ivl {
00032 
00033 template<class DERIVED>
00034 class rvalue_base
00035 : public types::rvalue_identifier
00036 {
00037 private:
00038         typedef DERIVED derived_type;
00039 
00040 public:
00041         const derived_type& derived() const
00042                 { return static_cast<const derived_type&>(*this); }
00043 
00044         derived_type& derived()
00045                 { return static_cast<derived_type&>(*this); }
00046 };
00047 
00048 namespace core_details {
00049 
00050 template <class A, class IS_LINEAR>
00051 struct rval_tool {};
00052 
00053 template <class A>
00054 struct rval_tool<A, types::t_false>
00055 {
00056         typedef typename A::create_similar type;
00057         static inline type operate(const A& a) { return type(a); }
00058 };
00059 
00060 template <class A>
00061 struct rval_tool<A, types::t_true>
00062 {
00063         typedef const A& type;
00064         static inline const A& operate(const A& a) { a; }
00065 };
00066 
00067 template <class A>
00068 struct resolve_rval
00069 : public rval_tool<A, typename A::is_linear>
00070 {
00071         typedef typename resolve_rval::type type;
00072 };
00073 
00074 /*
00075 template <class A>
00076 struct resolve_is_subreference
00077 : public rval_tool<A, typename types::t_and<typename A::is_writeable,
00078         types::is_base<types::subreference_identifier, A> >::type>
00079 {
00080         typedef typename resolve_rval::type type;
00081 };
00082 */
00083 
00084 } /* namespace core_details */
00085 
00111 template<class A>
00112 typename core_details::resolve_rval<A>::type rval(const A& a)
00113 {
00114         return core_details::resolve_rval<A>::operate(a);
00115 }
00116 
00124 template <class A>
00125 inline A& by_ref(const A& a) { return const_cast<A&>(a); }
00126 
00127 
00128 
00129 namespace core_details {
00130 
00131 template <class R, class A>
00132 class lval_wrapper : public A
00133 {
00134         const R& r;
00135 public:
00136         template <class X>
00137         lval_wrapper(const R& r, const X& x) : r(r), A(r) { }
00138         lval_wrapper(const lval_wrapper& x) : r(x.r), A(x) { }
00139 
00140         lval_wrapper& operator=(const lval_wrapper& x)
00141         { A::operator=(x); return *this; }
00142         using A::operator=;
00143 
00144         ~lval_wrapper()
00145         {
00146                 const_cast<typename types::remove_const<R>::type&>(r).assign(*this);
00147         }
00148 };
00149 
00150 template <class A, class IS_LINEAR>
00151 struct lval_tool {};
00152 
00153 template <class A>
00154 struct lval_tool<A, types::t_false>
00155 {
00156         typedef lval_wrapper<A, typename A::create_similar> type;
00157         static inline type operate(const A& a) { return type(a); }
00158 };
00159 
00160 template <class A>
00161 struct lval_tool<A, types::t_true>
00162 {
00163         typedef const A& type;
00164         static inline const A& operate(const A& a) { a; }
00165 };
00166 
00167 template <class A>
00168 struct resolve_lval
00169 : public lval_tool<A, typename A::is_linear>
00170 {
00171         typedef typename resolve_lval::type type;
00172 };
00173 
00174 } /* namespace core_details */
00175 
00180 template <class A>
00181 inline
00182 typename core_details::resolve_lval<A>::type lval(const A& a)
00183 {
00184         return core_details::resolve_lval<A>::operate(a);
00185 }
00186 
00187 }; /*namespace ivl*/
00188 
00189 #endif
00190 
00191 #endif // IVL_CORE_DETAILS_RVALUE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations