Codebase list cppad / f3180a3
master: cppad_vector: include sizing constructor with int argument. command_line_arg.cmake: only set default and cache for mssing variables. Brad Bell 4 years ago
5 changed file(s) with 29 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
00 # -----------------------------------------------------------------------------
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
22 #
33 # CppAD is distributed under the terms of the
44 # Eclipse Public License Version 2.0.
3737 ENDIF( NOT ( ${type} STREQUAL "PATH" ) )
3838 ENDIF( NOT ( ${type} STREQUAL "STRING" ) )
3939 #
40 SET(${variable} "${default}" CACHE ${type} "${description}")
40 IF( NOT ${variable} )
41 SET(${variable} "${default}" CACHE ${type} "${description}")
42 ENDIF( NOT ${variable} )
4143 MESSAGE(STATUS "${variable} = ${${variable}}")
4244 #
4345 ENDMACRO( command_line_arg )
5555 // check Simple Vector specifications
5656 CppAD::CheckSimpleVector< Scalar, vector<Scalar> >();
5757
58 // check constructor with size_t and with an int
59 size_t two_s = 2;
60 int two_i = 2;
61 vector<Scalar> vec(2), other(two_s), another(two_i);
62
5863 // assignment returns reference for use in other assignments
59 vector<Scalar> vec(2), other(2), another(2);
6064 another[0] = Scalar(1);
6165 another[1] = Scalar(2);
6266 vec = other = another;
00 /* --------------------------------------------------------------------------
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-19 Bradley M. Bell
1 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-20 Bradley M. Bell
22
33 CppAD is distributed under the terms of the
44 Eclipse Public License Version 2.0.
8181 and not the rest of CppAD, you should include
8282 $code cppad/utility/vector_bool.hpp$$.
8383
84 $head Integer Size$$
85 The size $icode n$$ in the constructor syntax below can be an
86 $code int$$ (all simple vectors support $code size_t$$):
87 $codei%
88 CppAD::vector<%Scalar%> %vec%(%n%)
89 %$$
8490
8591 $head capacity$$
8692 If $icode cap$$ is a $code size_t$$ object,
118118 $head Sizing$$
119119 $codei%vector<%Type%> %vec%(%n%)
120120 %$$
121 where $icode n$$ is a $code size_t$$,
121 where $icode n$$ is a $code size_t$$ or $code int$$,
122122 creates the vector $icode vec$$ with $icode n$$ elements and capacity
123123 greater than or equal $icode n$$.
124124
146146 { }
147147 vector(size_t n) : capacity_(0), length_(0), data_(CPPAD_NULL)
148148 { resize(n); }
149 vector(int n) : capacity_(0), length_(0), data_(CPPAD_NULL)
150 { CPPAD_ASSERT_KNOWN(
151 n >= 0,
152 "CppAD::vector: attempt to create a vector with a negative size."
153 );
154 resize( size_t(n) );
155 }
149156 vector(const vector& other) : capacity_(0), length_(0), data_(CPPAD_NULL)
150157 { resize(other.length_);
151158 for(size_t i = 0; i < length_; i++)
2020 $$
2121
2222 $section Changes and Additions to CppAD During 2020$$
23
24 $head 03-11$$
25 The $code CppAD::vector$$ constructor was extended to allow its
26 $cref/size/CppAD_vector/Integer Size/$$ to be a $code int$$
27 (this used to generate a warning when using the $code clang$$ compiler).
2328
2429 $head 02-02$$
2530 The $code get_optional.sh$$ prefix was extended so that it could be a