Codebase list cppad / upstream/2015.00.00.7 doc / cppad_vector.xml
upstream/2015.00.00.7

Tree @upstream/2015.00.00.7 (Download .tar.gz)

cppad_vector.xml @upstream/2015.00.00.7raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>The CppAD::vector Template Class</title>
<meta http-equiv='Content-Type' content='text/html' charset='utf-8'/>
<meta name="description" id="description" content="The CppAD::vector Template Class"/>
<meta name="keywords" id="keywords" content=" vector Cppad template class the cppad::vector syntax description include capacity assignment check size return reference move semantics element access [] push_back push_vector push output resize clear data vectorbool memory type and parallel mode thread_alloc example exercise Cppad::vector "/>
<style type='text/css'>
body { color : black }
body { background-color : white }
A:link { color : blue }
A:visited { color : purple }
A:active { color : purple }
</style>
<script type='text/javascript' language='JavaScript' src='_cppad_vector_xml.js'>
</script>
</head>
<body>
<table><tr>
<td>
<a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a>
</td>
<td><a href="ode_gear_control.cpp.xml" target="_top">Prev</a>
</td><td><a href="cppad_vector.cpp.xml" target="_top">Next</a>
</td><td>
<select onchange='choose_across0(this)'>
<option>Index-&gt;</option>
<option>contents</option>
<option>reference</option>
<option>index</option>
<option>search</option>
<option>external</option>
</select>
</td>
<td>
<select onchange='choose_up0(this)'>
<option>Up-&gt;</option>
<option>CppAD</option>
<option>library</option>
<option>CppAD_vector</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>CppAD-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>preprocessor</option>
<option>multi_thread</option>
<option>library</option>
<option>ipopt_solve</option>
<option>Example</option>
<option>speed</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>library-&gt;</option>
<option>ErrorHandler</option>
<option>NearEqual</option>
<option>speed_test</option>
<option>SpeedTest</option>
<option>time_test</option>
<option>NumericType</option>
<option>CheckNumericType</option>
<option>SimpleVector</option>
<option>CheckSimpleVector</option>
<option>nan</option>
<option>pow_int</option>
<option>Poly</option>
<option>LuDetAndSolve</option>
<option>RombergOne</option>
<option>RombergMul</option>
<option>Runge45</option>
<option>Rosen34</option>
<option>OdeErrControl</option>
<option>OdeGear</option>
<option>OdeGearControl</option>
<option>CppAD_vector</option>
<option>thread_alloc</option>
<option>index_sort</option>
<option>BenderQuad</option>
<option>opt_val_hes</option>
<option>LuRatio</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>CppAD_vector-&gt;</option>
<option>cppad_vector.cpp</option>
<option>vector_bool.cpp</option>
</select>
</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Syntax</option>
<option>Description</option>
<option>Include</option>
<option>capacity</option>
<option>Assignment</option>
<option>---..Check Size</option>
<option>---..Return Reference</option>
<option>---..Move Semantics</option>
<option>Element Access</option>
<option>push_back</option>
<option>push_vector</option>
<option>Output</option>
<option>resize</option>
<option>clear</option>
<option>data</option>
<option>vectorBool</option>
<option>---..Memory</option>
<option>---..data</option>
<option>---..Output</option>
<option>---..Element Type</option>
<option>Memory and Parallel Mode</option>
<option>Example</option>
<option>Exercise</option>
</select>
</td>
</tr></table><br/>







<center><b><big><big>The CppAD::vector Template Class</big></big></b></center>
<br/>
<b><big><a name="Syntax" id="Syntax">Syntax</a></big></b>

<code><font color="blue"><br/>
# include &lt;cppad/vector.hpp&gt;</font></code>

<br/>
<br/>
<b><big><a name="Description" id="Description">Description</a></big></b>
<br/>
The include file <code><font color="blue">cppad/vector.hpp</font></code> defines the
vector template class <code><font color="blue">CppAD::vector</font></code>.
This is a <a href="simplevector.xml" target="_top"><span style='white-space: nowrap'>SimpleVector</span></a>
 template class and in addition
it has the features listed below:

<br/>
<br/>
<b><big><a name="Include" id="Include">Include</a></big></b>
<br/>
The file <code><font color="blue">cppad/vector.hpp</font></code> is included by <code><font color="blue">cppad/cppad.hpp</font></code>
but it can also be included separately with out the rest of the 
CppAD include files.

<br/>
<br/>
<b><big><a name="capacity" id="capacity">capacity</a></big></b>
<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
,
and 
<code><i><font color="black"><span style='white-space: nowrap'>cap</span></font></i></code>
 is a <code><font color="blue">size_t</font></code> object,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>cap</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity()<br/>
</span></font></code>
set 
<code><i><font color="black"><span style='white-space: nowrap'>cap</span></font></i></code>
 to the number of 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 objects that
could fit in the memory currently allocated for 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
.
Note that

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.size()&#xA0;&lt;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity()<br/>
</span></font></code>
<br/>
<b><big><a name="Assignment" id="Assignment">Assignment</a></big></b>

<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 and 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 are 

<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 objects,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
has all the properties listed for a
<a href="simplevector.xml#Assignment" target="_top"><span style='white-space: nowrap'>simple&#xA0;vector&#xA0;assignment</span></a>

plus the following:

<br/>
<br/>
<b><a name="Assignment.Check Size" id="Assignment.Check Size">Check Size</a></b>
<br/>
The <code><font color="blue">CppAD::vector</font></code> template class will check that
the size of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is either zero or the size of 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>

before doing the assignment.
If this is not the case, <code><font color="blue">CppAD::vector</font></code> will use
<a href="errorhandler.xml" target="_top"><span style='white-space: nowrap'>ErrorHandler</span></a>

to generate an appropriate error report.
Allowing for assignment to a vector with size zero makes the following
code work:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>;<br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>;<br/>
</span></font></code>
<br/>
<b><a name="Assignment.Return Reference" id="Assignment.Return Reference">Return Reference</a></b>
<br/>
A reference to the vector 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 is returned.
An example use of this reference is in multiple assignments of the form

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>z</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
<br/>
<b><a name="Assignment.Move Semantics" id="Assignment.Move Semantics">Move Semantics</a></b>
<br/>
If the C++ compiler supports move semantic rvalues using the <code><font color="blue">&amp;&amp;</font></code>
syntax, then it will be used during the vector assignment statement.
This means that return values and other temporaries are not be copied,
but rather pointers are transferred.

<br/>
<br/>
<b><big><a name="Element Access" id="Element Access">Element Access</a></big></b>


<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object
and <code><font color="blue">i</font></code> has type <code><font color="blue">size_t</font></code>,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]<br/>
</span></font></code>
has all the properties listed for a
<a href="simplevector.xml#Element Access" target="_top"><span style='white-space: nowrap'>simple&#xA0;vector&#xA0;element&#xA0;access</span></a>

plus the following:
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>The object 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 has type 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>

(is not possibly a different type that can be converted to 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
).
<code><span style='white-space: nowrap'><br/>
<br/>
</span></code>If 
<code><i><font color="black"><span style='white-space: nowrap'>i</span></font></i></code>
 is not less than the size of the 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
,
<code><font color="blue">CppAD::vector</font></code> will use
<a href="errorhandler.xml" target="_top"><span style='white-space: nowrap'>ErrorHandler</span></a>

to generate an appropriate error report.

<br/>
<br/>
<b><big><a name="push_back" id="push_back">push_back</a></big></b>


<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object
with size equal to 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
 and

<code><i><font color="black"><span style='white-space: nowrap'>s</span></font></i></code>
 has type 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.push_back(</span></font><i><font color="black"><span style='white-space: nowrap'>s</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
extends the vector 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 so that its new size is 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
 plus one
and 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 is equal to 
<code><i><font color="black"><span style='white-space: nowrap'>s</span></font></i></code>

(equal in the sense of the 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 assignment operator).

<br/>
<br/>
<b><big><a name="push_vector" id="push_vector">push_vector</a></big></b>


<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object
with size equal to 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
 and

<code><i><font color="black"><span style='white-space: nowrap'>v</span></font></i></code>
 is a <a href="simplevector.xml" target="_top"><span style='white-space: nowrap'>simple&#xA0;vector</span></a>

with elements of type 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 and size 
<code><i><font color="black"><span style='white-space: nowrap'>m</span></font></i></code>
,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.push_vector(</span></font><i><font color="black"><span style='white-space: nowrap'>v</span></font></i><font color="blue"><span style='white-space: nowrap'>)<br/>
</span></font></code>
extends the vector 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 so that its new size is 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>+</span></font><i><font color="black"><span style='white-space: nowrap'>m</span></font></i></code>

and 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;+&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 is equal to 
<code><i><font color="black"><span style='white-space: nowrap'>v</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>

for 
<code><i><font color="black"><span style='white-space: nowrap'>i&#xA0;=&#xA0;1&#xA0;,&#xA0;...&#xA0;,&#xA0;m-1</span></font></i></code>

(equal in the sense of the 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 assignment operator).

<br/>
<br/>
<b><big><a name="Output" id="Output">Output</a></big></b>
<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object
and 
<code><i><font color="black"><span style='white-space: nowrap'>os</span></font></i></code>
 is an <code><font color="blue">std::ostream</font></code>,
and the operation

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>os</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;&lt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
will output the vector 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 to the standard
output stream 
<code><i><font color="black"><span style='white-space: nowrap'>os</span></font></i></code>
.
The elements of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 are enclosed at the beginning by a
<code><font color="blue">{</font></code> character,
they are separated by <code><font color="blue">,</font></code> characters,
and they are enclosed at the end by <code><font color="blue">}</font></code> character.
It is assumed by this operation that if 
<code><i><font color="black"><span style='white-space: nowrap'>e</span></font></i></code>

is an object with type 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
,

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>os</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;&lt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>e</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
will output the value 
<code><i><font color="black"><span style='white-space: nowrap'>e</span></font></i></code>
 to the standard
output stream 
<code><i><font color="black"><span style='white-space: nowrap'>os</span></font></i></code>
.

<br/>
<br/>
<b><big><a name="resize" id="resize">resize</a></big></b>
<br/>
The call 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.resize(</span></font><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
 set the size of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 equal to 

<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i></code>
. 
If 
<code><i><font color="black"><span style='white-space: nowrap'>n</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity()</span></font></code>
, 
no memory is freed or allocated and the capacity of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 does not change.

<br/>
<br/>
<b><big><a name="clear" id="clear">clear</a></big></b>
<br/>
All memory allocated for the vector is freed
and both its size and capacity are set to zero.
The can be useful when using very large vectors
and when checking for memory leaks (and there are global vectors)
see the <a href="cppad_vector.xml#Memory and Parallel Mode" target="_top"><span style='white-space: nowrap'>memory</span></a>
 discussion.

<br/>
<br/>
<b><big><a name="data" id="data">data</a></big></b>


<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is a 
<code><font color="blue"><span style='white-space: nowrap'>CppAD::vector&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 object

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.data()<br/>
</span></font></code>
returns a pointer to a 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 object such that for

<code><font color="blue"><span style='white-space: nowrap'>0&#xA0;&lt;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.size()</span></font></code>
,

<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 and 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.data()[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 
are the same 
<code><i><font color="black"><span style='white-space: nowrap'>Scalar</span></font></i></code>
 object.
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is <code><font color="blue">const</font></code>, the pointer is <code><font color="blue">const</font></code>.
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>.capacity()</span></font></code>
 is zero, the value of the pointer is not defined.
The pointer may no longer be valid after the following operations on 

<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
:
its destructor,
<code><font color="blue">clear</font></code>,
<code><font color="blue">resize</font></code>, 
<code><font color="blue">push_back</font></code>,
<code><font color="blue">push_vector</font></code>,
assignment to another vector when original size of 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 is zero. 

<br/>
<br/>
<b><big><a name="vectorBool" id="vectorBool">vectorBool</a></big></b>

<br/>
The file <code><font color="blue">&lt;cppad/vector.hpp&gt;</font></code> also defines the class
<code><font color="blue">CppAD::vectorBool</font></code>.
This has the same specifications as <code><font color="blue">CppAD::vector&lt;bool&gt;</font></code> 
with the following exceptions:

<br/>
<br/>
<b><a name="vectorBool.Memory" id="vectorBool.Memory">Memory</a></b>
<br/>
The class <code><font color="blue">vectorBool</font></code> conserves on memory
(on the other hand, <code><font color="blue">CppAD::vector&lt;bool&gt;</font></code> is expected to be faster
than <code><font color="blue">vectorBool</font></code>).

<br/>
<br/>
<b><a name="vectorBool.data" id="vectorBool.data">data</a></b>
<br/>
The <a href="cppad_vector.xml#data" target="_top"><span style='white-space: nowrap'>data</span></a>
 function is not supported by
<code><font color="blue">vectorBool</font></code>.

<br/>
<br/>
<b><a name="vectorBool.Output" id="vectorBool.Output">Output</a></b>
<br/>
The <code><font color="blue">CppAD::vectorBool</font></code> output operator
prints each boolean value as 
a <code><font color="blue">0</font></code> for false,
a <code><font color="blue">1</font></code> for true, 
and does not print any other output; i.e.,
the vector is written a long sequence of zeros and ones with no
surrounding <code><font color="blue">{</font></code>, <code><font color="blue">}</font></code> and with no separating commas or spaces. 

<br/>
<br/>
<b><a name="vectorBool.Element Type" id="vectorBool.Element Type">Element Type</a></b>
<br/>
If 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 has type <code><font color="blue">vectorBool</font></code>
and 
<code><i><font color="black"><span style='white-space: nowrap'>i</span></font></i></code>
 has type <code><font color="blue">size_t</font></code>,
the element access value 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]</span></font></code>
 has an unspecified type,
referred to here as 
<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
, that supports the following
operations:

<ol type="1"><li>

<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
 can be converted to <code><font color="blue">bool</font></code>; e.g.
the following syntax is supported:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;static_cast&lt;bool&gt;(&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]&#xA0;)<br/>
</span></font></code>
</li><li>

<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
 supports the assignment operator <code><font color="blue">=</font></code> where the 
right hand side is a <code><font color="blue">bool</font></code> or an 
<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
 object; e.g.,
if 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 has type <code><font color="blue">bool</font></code>, the following syntax is supported:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
</li><li>
The result of an assignment to an 
<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>

also has type 
<code><i><font color="black"><span style='white-space: nowrap'>elementType</span></font></i></code>
. 
Thus, if 
<code><i><font color="black"><span style='white-space: nowrap'>z</span></font></i></code>
 has type <code><font color="blue">bool</font></code>, the following syntax is supported:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>z</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>i</span></font></i><font color="blue"><span style='white-space: nowrap'>]&#xA0;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
</li></ol>
<br/>
<b><big><a name="Memory and Parallel Mode" id="Memory and Parallel Mode">Memory and Parallel Mode</a></big></b>


<br/>
These vectors use the multi-threaded fast memory allocator 
<a href="thread_alloc.xml" target="_top"><span style='white-space: nowrap'>thread_alloc</span></a>
:

<ol type="1"><li>
The routine <a href="ta_parallel_setup.xml" target="_top"><span style='white-space: nowrap'>parallel_setup</span></a>
 must
be called before these vectors can be used 
<a href="ta_in_parallel.xml" target="_top"><span style='white-space: nowrap'>in&#xA0;parallel</span></a>
.
</li><li>

Using these vectors affects the amount of memory 
<a href="ta_inuse.xml" target="_top"><span style='white-space: nowrap'>in_use</span></a>
 and <a href="ta_available.xml" target="_top"><span style='white-space: nowrap'>available</span></a>
.
</li><li>

Calling <a href="cppad_vector.xml#clear" target="_top"><span style='white-space: nowrap'>clear</span></a>
,
makes the corresponding memory available (though <code><font color="blue">thread_alloc</font></code>)
to the current thread.
</li><li>

Available memory
can then be completely freed using <a href="ta_free_available.xml" target="_top"><span style='white-space: nowrap'>free_available</span></a>
.
</li></ol>


<br/>
<br/>
<b><big><a name="Example" id="Example">Example</a></big></b>

<br/>
The files
<a href="cppad_vector.cpp.xml" target="_top"><span style='white-space: nowrap'>cppad_vector.cpp</span></a>
 and
<a href="vector_bool.cpp.xml" target="_top"><span style='white-space: nowrap'>vector_bool.cpp</span></a>
 each
contain an example and test of this template class.
They return true if they succeed and false otherwise.

<br/>
<br/>
<b><big><a name="Exercise" id="Exercise">Exercise</a></big></b>

<br/>
Create and run a program that contains the following code:
<code><font color='blue'><pre style='display:inline'> 
	CppAD::vector&lt;double&gt; x(3);
	size_t i;
	for(i = 0; i &lt; 3; i++)
		x[i] = 4. - i;
	std::cout &lt;&lt; &quot;x = &quot; &lt;&lt; x &lt;&lt; std::endl;
</pre></font></code>



<hr/>Input File: cppad/vector.hpp

</body>
</html>