Skip to content

Latest commit

 

History

History
92 lines (79 loc) · 1.73 KB

File metadata and controls

92 lines (79 loc) · 1.73 KB
title swap Function (auto_gcroot) | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-windows
ms.tgt_pltfrm
ms.topic reference
f1_keywords
msclr::swap
msclr.swap
dev_langs
C++
helpviewer_keywords
swap function
ms.assetid 2fe8146b-a7f7-445a-9ae9-53b5556be701
caps.latest.revision 10
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

swap Function (auto_gcroot)

Swaps objects between one auto_gcroot and another.

Syntax

template<typename _element_type>  
void swap(  
   auto_gcroot<_element_type> & _left,  
   auto_gcroot<_element_type> & _right  
);  

Parameters

_left
An auto_gcroot.

_right
Another auto_gcroot.

Example

// msl_swap_auto_gcroot.cpp  
// compile with: /clr  
#include <msclr\auto_gcroot.h>  
  
using namespace System;  
using namespace msclr;  
  
int main() {  
   auto_gcroot<String^> s1 = "string one";  
   auto_gcroot<String^> s2 = "string two";  
  
   Console::WriteLine( "s1 = '{0}', s2 = '{1}'",  
      s1->ToString(), s2->ToString() );  
   swap( s1, s2 );  
   Console::WriteLine( "s1 = '{0}', s2 = '{1}'",  
      s1->ToString(), s2->ToString() );  
}  
s1 = 'string one', s2 = 'string two'  
s1 = 'string two', s2 = 'string one'  

Requirements

Header file <msclr\auto_gcroot.h>

Namespace msclr

See Also

auto_gcroot
auto_gcroot::swap