# move.h

Go to the documentation of this file.

    00001 // Move, forward and identity for C++0x + swap -*- C++ -*-
    00002
    00003 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 3, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // Under Section 7 of GPL version 3, you are granted additional
    00017 // permissions described in the GCC Runtime Library Exception, version
    00018 // 3.1, as published by the Free Software Foundation.
    00019
    00020 // You should have received a copy of the GNU General Public License and
    00021 // a copy of the GCC Runtime Library Exception along with this program;
    00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    00023 // <http://www.gnu.org/licenses/>.
    00024
    00025 /** @file move.h
    00026  *  This is an internal header file, included by other library headers.
    00027  *  You should not attempt to use it directly.
    00028  */
    00029
    00030 #ifndef _MOVE_H
    00031 #define _MOVE_H 1
    00032
    00033 #include <bits/c++config.h>
    00034 #include <cstddef>
    00035 #include <bits/concept_check.h>
    00036
    00037 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00038 #include <type_traits>
    00039
    00040 _GLIBCXX_BEGIN_NAMESPACE(std)
    00041
    00042   // 20.2.2, forward/move
    00043   template<typename _Tp>
    00044     struct identity
    00045     {
    00046       typedef _Tp type;
    00047     };
    00048
    00049   template<typename _Tp>
    00050     inline _Tp&&
    00051     forward(typename std::identity<_Tp>::type&& __t)
    00052     { return __t; }
    00053
    00054   template<typename _Tp>
    00055     inline typename std::remove_reference<_Tp>::type&&
    00056     move(_Tp&& __t)
    00057     { return __t; }
    00058
    00059 _GLIBCXX_END_NAMESPACE
    00060
    00061 #define _GLIBCXX_MOVE(_Tp) std::move(_Tp)
    00062 #else
    00063 #define _GLIBCXX_MOVE(_Tp) (_Tp)
    00064 #endif
    00065
    00066 _GLIBCXX_BEGIN_NAMESPACE(std)
    00067
    00068   /**
    00069    *  @brief Swaps two values.
    00070    *  @param  a  A thing of arbitrary type.
    00071    *  @param  b  Another thing of arbitrary type.
    00072    *  @return   Nothing.
    00073   */
    00074   template<typename _Tp>
    00075     inline void
    00076     swap(_Tp& __a, _Tp& __b)
    00077     {
    00078       // concept requirements
    00079       __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
    00080
    00081       _Tp __tmp = _GLIBCXX_MOVE(__a);
    00082       __a = _GLIBCXX_MOVE(__b);
    00083       __b = _GLIBCXX_MOVE(__tmp);
    00084     }
    00085
    00086   // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00087   // DR 809. std::swap should be overloaded for array types.
    00088   template<typename _Tp, size_t _Nm>
    00089     inline void
    00090     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
    00091     {
    00092       for (size_t __n = 0; __n < _Nm; ++__n)
    00093     swap(__a[__n], __b[__n]);
    00094     }
    00095
    00096 _GLIBCXX_END_NAMESPACE
    00097
    00098 #endif /* _MOVE_H */