CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ad_to_string.hpp
Go to the documentation of this file.
1 // $Id$
2 # ifndef CPPAD_CORE_AD_TO_STRING_HPP
3 # define CPPAD_CORE_AD_TO_STRING_HPP
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 
15 /*
16 $begin ad_to_string$$
17 $spell
18  const
19  std
20 $$
21 
22 $section Convert An AD or Base Type to String$$
23 
24 $head Syntax$$
25 $icode%s% = to_string(%value%)%$$.
26 
27 $head See Also$$
28 $cref to_string$$, $cref base_to_string$$
29 
30 $head value$$
31 The argument $icode value$$ has prototype
32 $codei%
33  const AD<%Base%>& %value%
34  const %Base%& %value%
35 %$$
36 where $icode Base$$ is a type that supports the
37 $cref base_to_string$$ type requirement.
38 
39 $head s$$
40 The return value has prototype
41 $codei%
42  std::string %s%
43 %$$
44 and contains a representation of the specified $icode value$$.
45 If $icode value$$ is an AD type,
46 the result has the same precision as for the $icode Base$$ type.
47 
48 $head Example$$
49 The file $cref to_string.cpp$$
50 includes an example and test of $code to_string$$ with AD types.
51 It returns true if it succeeds and false otherwise.
52 
53 $end
54 */
56 # include <cppad/core/ad.hpp>
57 
58 namespace CppAD {
59 
60  // Template definition is in cppad/utility/to_string.hpp.
61  // Partial specialzation for AD<Base> types
62  template<class Base>
63  struct to_string_struct< CppAD::AD<Base> >
64  { std::string operator()(const CppAD::AD<Base>& value)
66  return ts( Value( Var2Par( value ) ) ); }
67  };
68 
69 }
70 
71 # endif
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION AD< Base > Var2Par(const AD< Base > &x)
Definition: var2par.hpp:75
Definition: ad.hpp:34
std::string operator()(const CppAD::AD< Base > &value)
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION Base Value(const AD< Base > &x)
Definition: value.hpp:82