18 template<
class To,
class From>
19 class Cast :
public To
24 typedef typename To::Result Result;
30 this->copy_parameter_policy (
from);
33 std::string get_name ()
const
34 {
return std::string(
"Cast")
35 +
"<To=" + To::Name +
",From=" + From::Name +
">"; }
40 void calculate (Result& result, std::vector<Result>* gradient)
42 std::vector<typename From::Result> from_grad;
43 std::vector<typename From::Result>* from_gradptr = &from_grad;
47 typename From::Result from_result =
from->evaluate (from_gradptr);
49 result =
static_cast<Result
> (from_result);
54 gradient->resize( from_grad.size() );
55 for (
unsigned igrad=0; igrad<from_grad.size(); igrad++)
56 (*gradient)[igrad] =
static_cast<Result
> (from_grad[igrad]);
64 template<
class To,
class From>
66 {
return new Cast<To, From> (from); }
68 template<
class To,
class From>