00001 // Software License for MTL 00002 // 00003 // Copyright (c) 2007 The Trustees of Indiana University. 00004 // 2008 Dresden University of Technology and the Trustees of Indiana University. 00005 // All rights reserved. 00006 // Authors: Peter Gottschling and Andrew Lumsdaine 00007 // 00008 // This file is part of the Matrix Template Library 00009 // 00010 // See also license.mtl.txt in the distribution. 00011 00012 #ifndef MTL_MAKE_COPY_OR_REFERENCE_INCLUDE 00013 #define MTL_MAKE_COPY_OR_REFERENCE_INCLUDE 00014 00015 namespace mtl { 00016 00017 00019 00024 template <typename Target, typename Source> 00025 struct make_in_copy_or_reference 00026 { 00027 typedef Target type; 00028 explicit make_in_copy_or_reference(const Source& src) : value(src) {} 00029 Target value; 00030 }; 00031 00032 template <typename Target> 00033 struct make_in_copy_or_reference<Target, Target> 00034 { 00035 typedef const Target& type; 00036 explicit make_in_copy_or_reference(const Target& src) : value(src) {} 00037 const Target& value; 00038 }; 00039 00040 00042 00048 template <typename Target, typename Source> 00049 struct make_out_copy_or_reference 00050 { 00051 explicit make_out_copy_or_reference(Source& src) : src(src) {} 00052 ~make_out_copy_or_reference() { src= value; } 00053 00054 Target value; 00055 private: 00056 Source& src; 00057 }; 00058 00059 template <typename Target> 00060 struct make_out_copy_or_reference<Target, Target> 00061 { 00062 explicit make_out_copy_or_reference(Target& src) : value(src) {} 00063 Target& value; 00064 }; 00065 00066 00068 00073 template <typename Target, typename Source> 00074 struct make_in_out_copy_or_reference 00075 { 00076 explicit make_in_out_copy_or_reference(Source& src) : src(src), value(src) {} 00077 ~make_in_out_copy_or_reference() { src= value; } 00078 00079 Target value; 00080 private: 00081 Source& src; 00082 }; 00083 00084 template <typename Target> 00085 struct make_in_out_copy_or_reference<Target, Target> 00086 { 00087 explicit make_in_out_copy_or_reference(Target& src) : value(src) {} 00088 Target& value; 00089 }; 00090 00091 } // namespace mtl 00092 00093 #endif // MTL_MAKE_COPY_OR_REFERENCE_INCLUDE