⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 value_type.html

📁 VC书籍介绍C++的应用的TheOODesignProcess.zip 电子书好用的
💻 HTML
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Zafir Anjum">
   <TITLE>MFC Programmer's SourceBook : STL Programmer's Guide</TITLE>
    <META name="description" 
     content="A freely available implementation 
     of the C++ Standard Template Library, including 
     hypertext documentation.">
	<META name="keywords" 
	content="generic programming, STL, standard template library">
</HEAD>

<SCRIPT LANGUAGE="JavaScript"><!--
var adcategory = "cpp";
// -->
</SCRIPT>
<body background="../../fancyhome/back.gif" bgcolor="#FFFFFF" >
<SCRIPT LANGUAGE="JavaScript"><!--
var nfrm = location.href.indexOf("_nfrm_");
var validframes = (top.frames.length > 0 && top.frames['ad'] && top.frames['logo'] );
var random = Math.random();

if( !validframes && nfrm == -1 )
{
	var dclkPage = "www.codeguru.com/";
	if( self.adcategory )
		dclkPage += adcategory;
	else
		dclkPage += "mfc";
	document.write('<nolayer><center>');
	document.write('<iframe src="http://ad.doubleclick.net/adi/' + dclkPage + ';ord='
	 + random + '" width=470 height=62 marginwidth=0 marginheight=0 hspace=0 vspace=0 '
	 + 'frameborder=0 scrolling=no bordercolor="#000000">');
	document.write('<a href="http://ad.doubleclick.net/jump/' + dclkPage + ';ord='
	 + random + '">');
	document.write('<img src="http://ad.doubleclick.net/ad/' + dclkPage + ';ord='
	 + random + '" height=60 width=468>' + '</a>');
	document.write('</iframe>');
	document.write('</center></nolayer>');
	document.write('<layer  src="http://ad.doubleclick.net/adl/' + dclkPage + 
	 ';ord=' + random + '"></layer>');
	document.write('<ilayer visibility=hide width=468 height=83></ilayer>');
}


//		top.location = "/show.cgi?" + adcategory + "=" + location.pathname;


// -->
</SCRIPT>
<noscript>
<p align="center">
<a href="http://ad.doubleclick.net/jump/www.codeguru.com/cpp;ord=NupaltFCY34AAHctPyc">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/cpp;ord=NupaltFCY34AAHctPyc"></a>
</p>
</noscript>





<BR Clear>
<H1>value_type</H1>

<Table CellPadding=0 CellSpacing=0 width=100%>
<TR>
<TD Align=left><Img src = "iterators.gif" Alt=""   WIDTH = "194"  HEIGHT = "38" ></TD>
<TD Align=right><Img src = "function.gif" Alt=""   WIDTH = "194"  HEIGHT = "38" ></TD>
</TR>
<TR>
<TD Align=left VAlign=top><b>Category</b>: iterators</TD>
<TD Align=right VAlign=top><b>Component type</b>: function</TD>
</TR>
</Table>

<h3>Prototype</h3>
<tt>Value_type</tt> is overloaded; it is in fact five different functions.
<pre>
template &lt;class T, class Distance&gt; 
inline T* value_type(const <A href="input_iterator.html">input_iterator</A>&lt;T, Distance&gt;&amp;);

template &lt;class T, class Distance&gt; 
inline T* value_type(const <A href="forward_iterator.html">forward_iterator</A>&lt;T, Distance&gt;&amp;);

template &lt;class T, class Distance&gt; 
inline T* value_type(const <A href="bidirectional_iterator.html">bidirectional_iterator</A>&lt;T, Distance&gt;&amp;);

template &lt;class T, class Distance&gt; 
inline T* value_type(const <A href="random_access_iterator.html">random_access_iterator</A>&lt;T, Distance&gt;&amp;);

template &lt;class T&gt; inline T* value_type(const T*);
</pre>
<h3>Description</h3>
<tt>Value_type</tt> is an <A href="iterator_tags.html">iterator tag</A> function: it is used to
determine the value type associated with an iterator.  An iterator's
value type is the type of object returned when the iterator is
dereferenced; <A href="OutputIterator.html">Output Iterators</A> do not have value types 
(<A href="OutputIterator.html">Output Iterators</A> may only be used for storing values, not for
accessing values), but <A href="InputIterator.html">Input Iterators</A>, <A href="ForwardIterator.html" tppabs="http://www.sgi.com/Technology/STL/ForwardIterator.shtml">Forward Iterators</A>,
<A href="BidirectionalIterator.html">Bidirectional Iterators</A>, and <A href="RandomAccessIterator.html" tppabs="http://www.sgi.com/Technology/STL/RandomAccessIterator.shtml">Random Access Iterators</A> do. <A href="#1">[1]</A>
In some cases, such as an algorithm that must
declare a local variable that holds a value returned from
dereferencing an iterator, it is necessary to find out an iterator's
value  type.  Accordingly, <tt>value_type(Iter)</tt> returns <tt>(T*) 0</tt>, where <tt>T</tt> is
<tt>Iter</tt>'s value type.
<P>
Although <tt>value_type</tt> looks like a single function whose
return type depends on its argument type, in reality it is a set
of functions; the name <tt>value_type</tt> is overloaded.  
The function <tt>value_type</tt> must be overloaded for every iterator type <A href="#1">[1]</A>.
<P>
In practice, ensuring that <tt>value_type</tt> is defined requires
essentially no work at all.  It is already defined for pointers, and
for the base classes <tt><A href="input_iterator.html">input_iterator</A></tt>,
<tt><A href="forward_iterator.html">forward_iterator</A></tt>, <tt><A href="bidirectional_iterator.html" tppabs="http://www.sgi.com/Technology/STL/bidirectional_iterator.shtml">bidirectional_iterator</A></tt>, and
<tt><A href="random_access_iterator.html">random_access_iterator</A></tt>.  If you are implementing a new type of
forward iterator, for example, you can simply derive it from the base
class <tt><A href="forward_iterator.html">forward_iterator</A></tt>; this means that <tt>value_type</tt>
(along with <tt><A href="iterator_category.html">iterator_category</A></tt> and <tt><A href="distance_type.html" tppabs="http://www.sgi.com/Technology/STL/distance_type.shtml">distance_type</A></tt>) will 
automatically be defined for your iterator.   These base classes are
empty: they contain no member functions or member variables, but
only type information.  Using them should therefore incur no overhead.
<P>
Note that, while the function <tt>value_type</tt> was present in the
original STL, it is no longer present in the most recent draft C++
standard: it has been replaced by the <tt><A href="iterator_traits.html">iterator_traits</A></tt> class
At present both mechanisms are supported <A href="#2">[2]</A>, but eventually
<tt>value_type</tt> will be removed.
<h3>Definition</h3>
Defined in <A href="iterator.h">iterator.h</A>.
<h3>Requirements on types</h3>
The argument of <tt>value_type</tt> must be an <A href="InputIterator.html">Input Iterator</A>, 
<A href="ForwardIterator.html">Forward Iterator</A>, <A href="BidirectionalIterator.html" tppabs="http://www.sgi.com/Technology/STL/BidirectionalIterator.shtml">Bidirectional Iterator</A>, or
<A href="RandomAccessIterator.html">Random Access Iterator</A>. <A href="#1">[1]</A>
<h3>Preconditions</h3>
None.  <tt>Value_type</tt>'s argument is even permitted to be
a singular iterator.
<h3>Complexity</h3>
At most amortized constant time.  In many cases, a compiler should be
able to optimize away <tt>value_type</tt> entirely.
<h3>Example</h3>
This example uses the <tt><A href="value_type.html">value_type</A></tt> iterator tag function in order to
declare a temporary variable of an iterator's value type.
<pre>
template &lt;class <A href="ForwardIterator.html">ForwardIterator</A>1, class <A href="ForwardIterator.html" tppabs="http://www.sgi.com/Technology/STL/ForwardIterator.shtml">ForwardIterator</A>2, class ValueType&gt;
inline void __iter_swap(ForwardIterator1 a, ForwardIterator2 b, ValueType*) {
    T tmp = *a;
    *a = *b;
    *b = tmp;
}

template &lt;class <A href="ForwardIterator.html">ForwardIterator</A>1, class <A href="ForwardIterator.html" tppabs="http://www.sgi.com/Technology/STL/ForwardIterator.shtml">ForwardIterator</A>2&gt;
inline void iter_swap(ForwardIterator1 a, ForwardIterator2 b) {
    __iter_swap(a, b, <A href="value_type.html">value_type</A>(a));
}
</pre>
<h3>Notes</h3>
<P><A name="1">[1]</A>
Note that <tt>distance_type</tt> is not defined for <A href="OutputIterator.html">Output Iterators</A>
or for <A href="trivial.html">Trivial Iterators</A>.  In the case of <A href="OutputIterator.html" tppabs="http://www.sgi.com/Technology/STL/OutputIterator.shtml">Output Iterators</A>,
this is because an <A href="OutputIterator.html">Output Iterator</A> does not have a value type:
it is not possible to dereference an <A href="OutputIterator.html">Output Iterator</A> and obtain
a value.  In the case of <A href="trivial.html">Trivial Iterators</A>, this is because 
the concept was introduced only for conceptual clarity,
in order to separate the axioms related to an object that refers
to another object from those related to iteration over a range.
In fact, the STL does not define any types that are <A href="trivial.html">Trivial Iterators</A>.
Although built-in C pointers may be <A href="trivial.html">Trivial Iterators</A>, the C
type system does not allow a distinction between pointers that are
<A href="trivial.html">Trivial Iterators</A> and pointers that are <A href="RandomAccessIterator.html" tppabs="http://www.sgi.com/Technology/STL/RandomAccessIterator.shtml">Random Access Iterators</A>
into C arrays.  Consequently, there is no <A href="trivial.html">Trivial Iterator</A> category
tag or iterator base.
<P><A name="2">[2]</A>
The <tt><A href="iterator_traits.html">iterator_traits</A></tt> class
relies on a C++ feature known as <i>partial specialization</i>.  Many of
today's compilers don't implement the complete standard; in
particular, many compilers do not support partial specialization.  If
your compiler does not support partial specialization, then you will
not be able to use <tt><A href="iterator_traits.html">iterator_traits</A></tt>, and you will have to 
continue using the functions <tt><A href="iterator_category.html">iterator_category</A></tt>, <tt><A href="distance_type.html" tppabs="http://www.sgi.com/Technology/STL/distance_type.shtml">distance_type</A></tt>,
and <tt>value_type</tt>.  This is one reason that those functions have
not yet been removed.
<h3>See also</h3>
The <A href="iterator_tags.html">Iterator Tags</A> overview, <tt><A href="iterator_traits.html" tppabs="http://www.sgi.com/Technology/STL/iterator_traits.shtml">iterator_traits</A></tt>,
<tt><A href="iterator_category.html">iterator_category</A></tt>, <tt><A href="distance_type.html" tppabs="http://www.sgi.com/Technology/STL/distance_type.shtml">distance_type</A></tt>,
<tt><A href="output_iterator_tag.html">output_iterator_tag</A></tt>, <tt><A href="input_iterator_tag.html" tppabs="http://www.sgi.com/Technology/STL/input_iterator_tag.shtml">input_iterator_tag</A></tt>,
<tt><A href="forward_iterator_tag.html">forward_iterator_tag</A></tt>, <tt><A href="bidirectional_iterator_tag.html" tppabs="http://www.sgi.com/Technology/STL/bidirectional_iterator_tag.shtml">bidirectional_iterator_tag</A></tt>,
<tt><A href="random_access_iterator_tag.html">random_access_iterator_tag</A></tt>

<HR SIZE="6"> <FONT SIZE="-2"> Copyright &copy; 1996 Silicon Graphics, Inc.
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="index.html" >
STL</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; Copyright 1997-1998 CodeGuru</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact : <A HREF="mailto:webmaster@codeguru.com">webmaster@codeguru.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript" ><!--
var adurl = "/cgi-bin/doubleclick.cgi?";

if( self.adcategory )
	adurl += adcategory;
else
	adurl += "mfc";

if( self.parent.norefreshad )
	parent.norefreshad = false;
else if( validframes )
	parent.frames['ad'].location = adurl;



if( !validframes && nfrm == -1)
{
	var dclkPage = "www.codeguru.com/";
	if( self.adcategory )
		dclkPage += adcategory;
	else 
		dclkPage += "mfc";
//	var random = Math.random();
	document.write('<nolayer><center>');
	document.write('<iframe src="http://ad.doubleclick.net/adi/' + dclkPage + ';ord='
	 + random + '" width=470 height=62 marginwidth=0 marginheight=0 hspace=0 vspace=0 '
	 + 'frameborder=0 scrolling=no bordercolor="#000000">');
	document.write('<a href="http://ad.doubleclick.net/jump/' + dclkPage + ';ord='
	 + random + '">');
	document.write('<img src="http://ad.doubleclick.net/ad/' + dclkPage + ';ord='
	 + random + '" height=60 width=468>' + '</a>');
	document.write('</iframe>');
	document.write('</center></nolayer>');
	document.write('<layer  src="http://ad.doubleclick.net/adl/' + dclkPage + 
	 ';ord=' + random + '"></layer>');
	document.write('<ilayer visibility=hide width=468 height=83></ilayer>');
}

// -->
</SCRIPT> 
<!-- SCRIPT LANGUAGE="JavaScript" SRC="/global/fscript.js">
//
</SCRIPT --> 

<noscript>
<p align="center">
<a href="http://ad.doubleclick.net/jump/www.codeguru.com/cpp;ord=NupaltFCY34AAHctPyc">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/cpp;ord=NupaltFCY34AAHctPyc"></a>
</p>
</noscript>





</BODY>
</HTML>


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -